Reveal Text
Reveal Text é um componente de texto para React e Tailwind CSS, da biblioteca SmoothUI, com licença MIT. Copia e cola no teu projeto.
SmoothUI
MIT
text
O que é
Reveal Text é um componente de texto para React e Tailwind CSS, da biblioteca SmoothUI, com licença MIT. Copia e cola no teu projeto.
Como usar
Abre o componente no catálogo, carrega em copiar, e cola no teu projeto. O prompt copiado leva o código e as regras para o teu agente o reproduzir sem alterar nada.
Cinco cópias grátis por mês. Sem cartão.
Precisa de
npm i motion
Licença
Este componente vem de SmoothUI e é redistribuído sob a licença MIT, que permite uso comercial. O aviso de copyright viaja com o código.
Reveal Text
import { motion, useInView, useReducedMotion } from "motion/react";
import React from "react";
export interface RevealTextProps {
children: string;
className?: string;
delay?: number;
direction?: "up" | "down" | "left" | "right";
triggerOnView?: boolean;
}
const REVEAL_ANIMATION_DURATION_S = 0.25;
const MILLISECONDS_TO_SECONDS = 1000;
const directionVariants = {
down: { opacity: 0, y: -24 },
left: { opacity: 0, x: 24 },
right: { opacity: 0, x: -24 },
up: { opacity: 0, y: 24 },
};
const RevealText: React.FC<RevealTextProps> = ({
children,
direction = "up",
delay = 0,
triggerOnView = false,
className = "",
}) => {
const ref = React.useRef<HTMLSpanElement>(null);
const inView = useInView(ref, { once: true });
const shouldReduceMotion = useReducedMotion();
const animate = (!triggerOnView || inView) && !shouldReduceMotion;
return (
<motion.span
animate={
shouldReduceMotion || !animate
? { opacity: 1 }
: { opacity: 1, x: 0, y: 0 }
}
className={className}
initial={
shouldReduceMotion ? { opacity: 1 } : directionVariants[direction]
}
ref={ref}
style={{ display: "inline-block" }}
transition={
shouldReduceMotion
? { duration: 0 }
: {
delay: delay / MILLISECONDS_TO_SECONDS,
duration: REVEAL_ANIMATION_DURATION_S,
}
}
>
{children}
</motion.span>
);
};
export default RevealText;