Fade In Left to Right
Installation
npx shadcn@latest add https://uibrik.com/r/fade-left-to-right.jsonInstall the packages
npm install motionCopy the source into your project
components/uibrik/fade-left-to-right/fade-left-to-right.tsx"use client"; import { animate, motion, useMotionTemplate, useMotionValue } from "motion/react"; import { useEffect } from "react"; import { TEXT, type EffectProps } from "../_text-effects/shared"; // 17 — The line is revealed by a soft edge that travels left to right, // fading the letters in rather than cutting them. export function FadeLeftToRight({ play, text = "Revealed with a soft edge", duration = 0.9, softness = 30, }: EffectProps & { text?: string; /** Seconds for the edge to cross the line. */ duration?: number; /** Width of the soft edge, % of the line. */ softness?: number; }) { const edge = useMotionValue(100); const mask = useMotionTemplate`linear-gradient(90deg, black ${edge}%, transparent calc(${edge}% + ${softness}%))`; useEffect(() => { if (!play) return; const controls = animate(edge, [-softness, 100], { duration, ease: "easeInOut" }); return () => controls.stop(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [play, edge]); return ( <motion.p className={TEXT} style={{ maskImage: mask, WebkitMaskImage: mask }}> {text} </motion.p> ); }
Adds the files to
components/uibrik/fade-left-to-right and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/fade-left-to-right.Props
FadeLeftToRight- text
- Type string
- "Revealed with a soft edge"
- The copy to animate.
- duration
- Type number
- 0.9
- Time for the edge to cross the line.
- softness
- Type number
- 30
- Width of the soft edge.
- playrequired
- Type number
- –
- Each change plays the effect again; 0 shows its resting state.