@gfazioli/mantine-text-animate
Version:
The TextAnimate component allows you to animate text with various effects.
92 lines (89 loc) • 1.89 kB
JavaScript
'use client';
import React from 'react';
import { createVarsResolver, polymorphicFactory, useProps, useStyles, Box } from '@mantine/core';
import { useTextTicker } from './use-text-ticker.mjs';
import classes from './TextTicker.module.css.mjs';
const defaultProps = {
characterSet: "alphanumeric",
customCharacters: "",
delay: 0,
speed: 1,
easing: "ease-out",
randomChangeSpeed: 1,
revealDirection: "left-to-right",
initialText: "random",
animate: true
};
const varsResolver = createVarsResolver((_, { delay, speed }) => ({
root: {
"--text-ticker-animation-duration": `${1 / (speed || 1)}s`,
"--text-ticker-animation-delay": `${delay || 0}s`
}
}));
const TextTicker = polymorphicFactory((_props, ref) => {
const props = useProps("TextTicker", defaultProps, _props);
const {
value,
initialText,
animate,
characterSet,
customCharacters,
delay,
speed,
easing,
randomChangeSpeed,
revealDirection,
onCompleted,
classNames,
style,
styles,
unstyled,
vars,
className,
...others
} = props;
const { text } = useTextTicker({
value,
initialText,
animate,
characterSet,
customCharacters,
delay,
speed,
easing,
randomChangeSpeed,
revealDirection,
onCompleted
});
const getStyles = useStyles({
name: "TextTicker",
props,
classes,
className,
style,
classNames,
styles,
unstyled,
vars,
varsResolver
});
return /* @__PURE__ */ React.createElement(
Box,
{
ref,
...getStyles("root", {
style: {
display: "inline-block",
fontFamily: "monospace",
whiteSpace: "pre"
}
}),
component: "p",
...others
},
text
);
});
TextTicker.displayName = "TextTicker";
export { TextTicker };
//# sourceMappingURL=TextTicker.mjs.map