npm install -S react-text-transition
npm run dev
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 (
<h1>
<TextTransition
text={ TEXTS[index % TEXTS.length] }
springConfig={ presets.wobbly }
/>
</h1>
);
};
Prop | Type | Default | Definition |
---|---|---|---|
text | String | REQUIRED | The text you want to show. |
direction | String (enum) | 0 | Used to determine the direction of the transition "up" or "down" (Must be an all-lowercase string). |
inline | Boolean | false | Makes the wrapper inline (will auto resize based on contents). |
delay | Number | 0 | Delay the transition of the text (in milliseconds). |
springConfig | Object | { mass: 1, tension: 170, friction: 26 } | react-spring's spring configuration. |
noOverflow | Boolean | false | Setting this to true will make the transitioning text appear clipped (Will simply set overflow : hidden on the wrapper). |
className | String | "" | Any css classes that you might want to send to the wrapper. |
style | Object | {} | Any styles that you might want to send to the wrapper. |
Changing this prop triggers the transition.
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.
The amount of miliseconds to wait before transitioning.
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
text={ this.state.text }
springConfig={ presets.wobbly }
/>
There're 4 presets
default
The default.gentle
wobbly
stiff
slow
molasses
Any css classes that you might want to provide to the wrapper.
Any css styles that you might want to provide to the wrapper.
Feel free to ask any questions about using this plugin. This plugin requires react +16.8