3.1.0 • Published 1 year ago

react-text-transition v3.1.0

Weekly downloads
2,178
License
MIT
Repository
github
Last release
1 year ago

React-Text-transition

Animate your text changes

text-transition

Edit r03264p26n

Installation

npm install -S react-text-transition

Using the demo

npm run dev

How to use

Example

import React from 'react';
import TextTransition, { presets } from 'react-text-transition';

const TEXTS = ['Forest', 'Building', 'Tree', 'Color'];

const App = () => {
  const [index, setIndex] = React.useState(0);

  React.useEffect(() => {
    const intervalId = setInterval(
      () => setIndex((index) => index + 1),
      3000, // every 3 seconds
    );
    return () => clearTimeout(intervalId);
  }, []);

  return (
    <h1>
      <TextTransition springConfig={presets.wobbly}>{TEXTS[index % TEXTS.length]}</TextTransition>
    </h1>
  );
};

Props

PropTypeDefaultDefinition
directionString (enum)0Used to determine the direction of the transition "up" or "down" (Must be an all-lowercase string).
inlineBooleanfalseMakes the wrapper inline (will auto resize based on contents).
delayNumber0Delay the transition of the text (in milliseconds).
springConfigObject{ mass: 1, tension: 170, friction: 26 }react-spring's spring configuration.
classNameString""Any css classes that you might want to send to the wrapper.
styleReact.CSSProperties{}Any styles that you might want to send to the wrapper.
childrenReact.ReactNodeREQUIREDThe react node to be animated
translateValuestring"100%"Transform value for determine height animation

Detailed Props

inline Boolean

Will simply make the wrapper an inline element and animate its width based on currently showing text, this is useful if you want to show some other static text on the same line.

delay Number

The amount of miliseconds to wait before transitioning.

spring Object

react-spring's Spring configuration (Refer to the configs section) react-spring's spring presets are exposed as presets.

import TextTransition, { presets } from 'react-text-transition';

// in your render method
<TextTransition springConfig={presets.wobbly}>{this.state.text}</TextTransition>;

You have the following presets

  • default The default.
  • gentle
  • wobbly
  • stiff
  • slow
  • molasses

className String

Any css classes that you might want to provide to the wrapper.

style React.CSSProperties

Any css styles that you might want to provide to the wrapper.

NOTE

Feel free to ask any questions about using this component. This plugin requires react +16.8

3.1.0-beta.1

1 year ago

3.1.0

1 year ago

2.0.0-beta.1

2 years ago

2.0.0

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.0

6 years ago