1.4.0 • Published 1 year ago

react-anagram-animation v1.4.0

Weekly downloads
-
License
WTFPL
Repository
github
Last release
1 year ago

React Anagram Animation

A React component to use CSS animations to swap letters in 2 words which are an anagram of each other.

The text is animated in position after calculating initial and final positions of each letter.

Install

yarn add react-anagram-animation

or

npm install react-anagram-animation

Demo

DEMO

CodeSandbox

Usage

import React from 'react';
import Anagram from 'react-anagram-animation';

export default function MyComponent() {
    return (
        <Anagram words={['React Anagram Animation', 'Magenta Raincoat Airman']} />
    );
}

To control the animation speed and timing, you can pass an object of animationOptions.

<Anagram animationOptions={{
    randomStartMin: 0,
    randomStartMax: 0,
    randomReverseMin: 6000,
    randomReverseMax: 6000,
    loopAnimation: 20000,
    waitToStart: 5000,
    transitionDuration: 2000,
    timingFunction: 'ease-in-out',
}} />

If you are using an embedded font and need to wait for it to load before animating, then you should specify the fontToObserve property with the font family name.

<Anagram fontToObserve="Open Sans" />
<Anagram fontToObserve="Roboto" />

API

Props

PropTypeDefaultDescription
wordsarray['React Anagram Animation', 'Magenta Raincoat Airman']An array containing exactly 2 words which are an anagram of each other.
animationOptionsobjectAnimationOptionsTiming options for when to start, how fast to animate forwards, backwards, and when to loop (optional).
fontToObservestringThe name of an embedded font to wait until loaded. If not specified, animation will loaded immediately (optional).

AnimationOptions

All time values are in # of milliseconds. The randomness allows a nice jumble effect. You can use any values you want to create some fascinating animations.

PropertyTypeDefaultDescription
randomStartMinnumber0The minimum amount of time to randomly wait before starting to animate each letter.
randomStartMaxnumber3000The maximum amount of time to randomly wait before starting to animate each letter. Should be >= randomStartMin.
randomReverseMinnumber6000The minimum amount of time to randomly wait before starting to animate each letter in reverse.
randomReverseMaxnumber9000The maximum amount of time to randomly wait before starting to animate each letter in reverse. Should be >= randomReverseMin.
loopAnimationnumber12000The amount of time to wait before starting the next full loop of the animation. Should be >= randomReverseMax + transitionDuration.
waitToStartnumber0The amount of time to wait before beginning the animation on start up the first time.
transitionDurationnumber1000How long should it take for a letter to move to its next position. Should be <= randomReverseMin - randomStartMax.
timingFunctionstringease-in-outWhat timing function should be used for the animation.

Run Locally

To run demo locally:

  • yarn
  • yarn start

and a browser will open to the demo.

If you receive Invalid hook call errors because you are linking this module, you may need to point this library's React to your app's installed React so there is only one copy.

npm link ../my-app/node_modules/react
npm link ../my-app/node_modules/react-dom

Future Ideas

  • Animate between more than 2 words.
  • Animate non-anagram words. Done.

License

WTFPL

1.4.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.2.0

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.0.3

3 years ago

0.1.1

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.0

3 years ago