@gfazioli/mantine-text-animate
Version:
The TextAnimate component allows you to animate text with various effects.
79 lines (75 loc) • 1.7 kB
JavaScript
'use client';
;
var core = require('@mantine/core');
var React = require('react');
var useMorphing = require('./use-morphing.cjs');
var Morphing_module = require('./Morphing.module.css.cjs');
const defaultProps = {
animate: true,
speed: 1
};
const varsResolver = core.createVarsResolver((_, { speed }) => ({
root: {
"--text-animate-morphing-speed": `${1 / (speed || 1)}s`
}
}));
const Morphing = core.polymorphicFactory((_props) => {
const props = core.useProps("Morphing", defaultProps, _props);
const {
value,
animate,
speed,
onCompleted,
classNames,
style,
styles,
unstyled,
vars,
className,
...others
} = props;
const getStyles = core.useStyles({
name: "Morphing",
props,
classes: Morphing_module,
className,
style,
classNames,
styles,
unstyled,
vars,
varsResolver
});
const { characters, width } = useMorphing.useMorphing({
value,
animate,
speed,
onCompleted
});
return /* @__PURE__ */ React.createElement(
core.Box,
{
...getStyles("root"),
component: "div",
"aria-live": "polite",
"aria-label": value,
style: { width: `${width}ch`, height: "1.2em" },
...others
},
characters.map((char) => /* @__PURE__ */ React.createElement(
core.Box,
{
key: char.key,
component: "span",
...getStyles("character"),
style: { left: `${char.toX}ch` },
"data-morph-state": char.state
},
char.char
))
);
});
Morphing.classes = Morphing_module;
Morphing.displayName = "Morphing";
exports.Morphing = Morphing;
//# sourceMappingURL=Morphing.cjs.map