UNPKG

@gfazioli/mantine-text-animate

Version:

The TextAnimate component allows you to animate text with various effects.

77 lines (74 loc) 1.65 kB
'use client'; import { createVarsResolver, polymorphicFactory, useProps, useStyles, Box } from '@mantine/core'; import React from 'react'; import { useMorphing } from './use-morphing.mjs'; import classes from './Morphing.module.css.mjs'; const defaultProps = { animate: true, speed: 1 }; const varsResolver = createVarsResolver((_, { speed }) => ({ root: { "--text-animate-morphing-speed": `${1 / (speed || 1)}s` } })); const Morphing = polymorphicFactory((_props) => { const props = useProps("Morphing", defaultProps, _props); const { value, animate, speed, onCompleted, classNames, style, styles, unstyled, vars, className, ...others } = props; const getStyles = useStyles({ name: "Morphing", props, classes, className, style, classNames, styles, unstyled, vars, varsResolver }); const { characters, width } = useMorphing({ value, animate, speed, onCompleted }); return /* @__PURE__ */ React.createElement( 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( Box, { key: char.key, component: "span", ...getStyles("character"), style: { left: `${char.toX}ch` }, "data-morph-state": char.state }, char.char )) ); }); Morphing.classes = classes; Morphing.displayName = "Morphing"; export { Morphing }; //# sourceMappingURL=Morphing.mjs.map