Slide Up Text
spell-ui/slide-up-textFreeComponent
Text animation that slides up from bottom with stagger effect.
Live preview
live · rendered by the registry
Rendered by spell-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://spell.sh/r/slide-up-text.jsonSource
1"use client";23import { AnimationOptions, motion } from "motion/react";4import {5 forwardRef,6 useCallback,7 useEffect,8 useImperativeHandle,9 useMemo,10 useState,11} from "react";1213import { cn } from "@/lib/utils";1415interface SlideUpTextProps {16 children: React.ReactNode;17 split?: "words" | "characters" | "lines";18 delay?: number;19 stagger?: number;20 from?: "first" | "last" | "center";21 transition?: AnimationOptions;22 className?: string;23 wordClass?: string;24 charClass?: string;25 autoStart?: boolean;26 onStart?: () => void;27 onComplete?: () => void;28 inView?: boolean;29 once?: boolean;30}3132export interface SlideUpTextRef {33 startAnimation: () => void;34 reset: () => void;35}3637interface WordObject {38 characters: string[];39 needsSpace: boolean;40}4142const SlideUpText = forwardRef<SlideUpTextRef, SlideUpTextProps>(43 (44 {45 children,46 split = "words",47 delay = 0,48 stagger = 0.1,49 from = "first",50 transition = {51 type: "tween",52 ease: [0.625, 0.05, 0, 1],53 duration: 0.5,54 },55 className,56 wordClass,57 charClass,58 autoStart = true,59 onStart,60 onComplete,61 inView = false,62 once = true,63 ...props64 },65 ref,66 ) => {67 const text = typeof children === "string"68 ? children69 : children?.toString() || "";70 const [isAnimating, setIsAnimating] = useState(false);7172 const splitIntoCharacters = (text: string): string[] => {73 if (typeof Intl !== "undefined" && "Segmenter" in Intl) {74 const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });75 return Array.from(segmenter.segment(text), ({ segment }) => segment);76 }77 return Array.from(text);78 };7980 const elements = useMemo(() => {81 const words = text.split(" ");82 if (split === "characters") {83 return words.map((word, i) => ({84 characters: splitIntoCharacters(word),85 needsSpace: i !== words.length - 1,86 }));87 }88 return split === "words" ? text.split(" ") : text.split("\n");89 }, [text, split]);9091 const getStaggerDelay = useCallback(92 (index: number) => {93 const total = split === "characters"94 ? elements.reduce(95 (acc, word) =>96 acc +97 (typeof word === "string"98 ? 199 : word.characters.length + (word.needsSpace ? 1 : 0)),100 0,101 )102 : elements.length;103104// … truncated
What it pulls in
npm packages
Files it writes
More from spell-ui
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Checkboxanimated-checkbox | spell-ui | Components | Free | 1 dep | |
| Animated Gradientanimated-gradient | spell-ui | Components | Free | no deps | |
| Badgebadge | spell-ui | Components | Free | 2 deps | |
| Bars Spinnerbars-spinner | spell-ui | Components | Free | no deps | |
| Blur Revealblur-reveal | spell-ui | Components | Free | 1 dep | |
| Chartchart | spell-ui | Components | Free | no deps | |
| Color Selectorcolor-selector | spell-ui | Components | Free | no deps | |
| Copy Buttoncopy-button | spell-ui | Components | Free | 1 dep |
