packages/popmotion-pose/docs/api/react/react-pose-text.md
React Pose has been deprecated in favour of Framer Motion. Read the upgrade guide
React Pose Text automatically splits strings of text into individual words and/or characters. These can then be animated with the full power of Pose:
color and text-shadowenter/exit animations with PoseGroupReact Pose Text is free for non-profit use under a GPL-v3 license.
A permissive, commercial license is exclusive to backers of the Popmotion Patreon!
npm install react-pose react-pose-text
React Pose Text exports a single component, SplitText.
import SplitText from 'react-pose-text';
export default () => (
<SplitText>Hello world!</SplitText>
);
Strings wrapped with this component will be split into posed components for every word and character.
Poses can be defined for both words and characters by providing Pose configs to the wordPoses and charPoses props, respectively:
const charPoses = {
enter: { opacity: 1 },
exit: { opacity: 0 }
};
export default () => (
<SplitText charPoses={charPoses}>
Hello world!
</SplitText>
);
SplitText acts like a regular posed component, which means we can animate between poses using the pose property:
export default ({ isVisible }) => (
<SplitText
charPoses={charPoses}
pose={isVisible ? 'enter' : 'exit'}
>
Hello world!
</SplitText>
);
It also responds to pose changes further up the tree.
<CodeSandbox id="100lwoo7wl" />Like normal posed components, all props provided to SplitText are sent through to dynamic pose properties:
const charPoses = {
enter: { y: 0 },
exit: { y: ({ initialOffset }) => initialOffset }
};
export default () => (
<SplitText initialOffset={5} charPoses={charPoses}>
Hello world!
</SplitText>
);
But SplitText also provides a series of special props.
Words receive:
wordIndexnumWordsCharacters receive:
wordIndexnumWordscharIndexnumCharscharInWordIndexnumCharsInWordYou can use these props in various ways, for instance to create a variety of staggering effects by dynamically generating delay:
const charPoses = {
enter: {
y: 0,
delay: ({ charIndex }) => charIndex * 50
}
};
You can use Pose's pointer events as usual. For instance, you can make every word draggable by setting draggable: true:
Those poses still cascade down, too. So by setting dragging and dragEnd poses to our characters, we can make our characters animate while dragging words: