Vertical Cut Reveal
fancy/vertical-cut-revealFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/vertical-cut-reveal.jsonSource
1"use client"23import { AnimationOptions, motion } from "motion/react"4import {5 forwardRef,6 useCallback,7 useEffect,8 useImperativeHandle,9 useMemo,10 useRef,11 useState,12} from "react"1314import { cn } from "@/lib/utils"1516interface TextProps {17 children: React.ReactNode18 reverse?: boolean19 transition?: AnimationOptions20 splitBy?: "words" | "characters" | "lines" | string21 staggerDuration?: number22 staggerFrom?: "first" | "last" | "center" | "random" | number23 containerClassName?: string24 wordLevelClassName?: string25 elementLevelClassName?: string26 onClick?: () => void27 onStart?: () => void28 onComplete?: () => void29 autoStart?: boolean // Whether to start the animation automatically30}3132// Ref interface to allow external control of the animation33export interface VerticalCutRevealRef {34 startAnimation: () => void35 reset: () => void36}3738interface WordObject {39 characters: string[]40 needsSpace: boolean41}4243const VerticalCutReveal = forwardRef<VerticalCutRevealRef, TextProps>(44 (45 {46 children,47 reverse = false,48 transition = {49 type: "spring",50 stiffness: 190,51 damping: 22,52 },53 splitBy = "words",54 staggerDuration = 0.2,55 staggerFrom = "first",56 containerClassName,57 wordLevelClassName,58 elementLevelClassName,59 onClick,60 onStart,61 onComplete,62 autoStart = true,63 ...props64 },65 ref66 ) => {67 const containerRef = useRef<HTMLSpanElement>(null)68 const text =69 typeof children === "string" ? children : children?.toString() || ""70 const [isAnimating, setIsAnimating] = useState(false)7172 // handy function to split text into characters with support for unicode and emojis73 const splitIntoCharacters = (text: string): string[] => {74 if (typeof Intl !== "undefined" && "Segmenter" in Intl) {75 const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" })76 return Array.from(segmenter.segment(text), ({ segment }) => segment)77 }78 // Fallback for browsers that don't support Intl.Segmenter79 return Array.from(text)80 }8182 // Split text based on splitBy parameter83 const elements = useMemo(() => {84 const words = text.split(" ")85 if (splitBy === "characters") {86 return words.map((word, i) => ({87 characters: splitIntoCharacters(word),88 needsSpace: i !== words.length - 1,89 }))90 }91 return splitBy === "words"92 ? text.split(" ")93// … truncated
What it pulls in
npm packages
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient With Svganimated-gradient-with-svg | fancy | Components | Free | no deps | |
| Basic Number Tickerbasic-number-ticker | fancy | Components | Free | 1 dep | |
| Box Carouselbox-carousel | fancy | Components | Free | 1 dep | |
| Breathing Textbreathing-text | fancy | Components | Free | 1 dep | |
| Circling Elementscircling-elements | fancy | Components | Free | 1 dep | |
| Css Boxcss-box | fancy | Components | Free | 1 dep | |
| Cursor Attractor And Gravitycursor-attractor-and-gravity | fancy | Components | Free | 5 deps | |
| Drag Elementsdrag-elements | fancy | Components | Free | 1 dep |
