UNPKG

react-textmotion

Version:

Lightweight yet powerful library that provides variable animation effects for React applications.

56 lines (55 loc) 2.52 kB
import '../../styles/animations.scss'; import '../../styles/motion.scss'; import { FC } from 'react'; import { TextMotionProps } from '../../types'; /** * @description * `TextMotion` is a component that animates text by splitting it into characters, words or lines, * and applying motion presets or custom motion configurations. * It leverages CSS animations and dynamically generated inline styles for smooth effects. * * @param {ElementType} [as='span'] - The HTML tag to render. Defaults to `span`. * @param {string} text - The text content to animate. * @param {SplitType} [split='character'] - Defines how the text is split for animation (`character`, `word`, or `line`). Defaults to `'character'`. * @param {'on-load' | 'scroll' } [trigger='scroll'] - Defines when the animation should start. 'on-load' starts the animation immediately. 'scroll' starts the animation only when the component enters the viewport. Defaults to `'scroll'`. * @param {boolean} [repeat=true] - Determines if the animation should repeat every time it enters the viewport. Only applicable when `trigger` is `'scroll'`. Defaults to `true`. * @param {number} [initialDelay=0] - The initial delay before the animation starts, in seconds. Defaults to `0`. * @param {'first-to-last' | 'last-to-first'} [animationOrder='first-to-last'] - Defines the order in which the animation sequence is applied. Defaults to `'first-to-last'`. * @param {MotionConfig} [motion] - Custom motion configuration object. Cannot be used with `preset`. * @param {AnimationPreset[]} [preset] - Predefined motion presets. Cannot be used with `motion`. * * @returns {JSX.Element} A React element that renders animated `<span>`s for each split unit of text. * * @example * // Using custom motion configuration * function App() { * return ( * <TextMotion * text="Hello World!" * split="character" * trigger="scroll" * repeat={false} * initialDelay={1} * motion={{ * fade: { variant: 'in', duration: 0.25, delay: 0.025, easing: 'linear' }, * slide: { variant: 'up', duration: 0.25, delay: 0.025, easing: 'linear' }, * }} * /> * ); * } * * @example * // Using predefined animation presets * function App() { * return ( * <TextMotion * text="Hello World!" * split="word" * trigger="on-load" * initialDelay={0.5} * preset={['fade-in', 'slide-up']} * /> * ); * } */ export declare const TextMotion: FC<TextMotionProps>;