Updated
Rolling Word
Customize
Duration0.45s
Exit duration0.35s
Stagger0.030s
Text size48px
Installation
npx shadcn@latest add https://uibrik.com/r/rolling-word.jsonInstall the packages
npm install motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/rolling-word/rolling-word.tsx"use client"; import { cn } from "@/lib/utils"; import { AnimatePresence, motion } from "motion/react"; import { useEffect, useMemo, useRef, useState } from "react"; import useMeasure from "react-use-measure"; // `play` counts presses of a card's Change button. 0 means the card has not // been pressed yet, so every effect renders its resting state without // animating on page load. export type EffectProps = { play: number }; // Size comes from --text-effect-size (default 1.25rem, i.e. text-xl), so a // preview can enlarge every effect without changing the installed default. const SIZE = "text-[length:var(--text-effect-size,1.25rem)] leading-[1.4]"; const TEXT = `${SIZE} text-zinc-700 font-medium dark:text-zinc-200`; const EASE_OUT = [0.23, 1, 0.32, 1] as const; // The entry for the nth press, wrapping around the list. const pick = <T,>(list: T[], play: number) => list[((play % list.length) + list.length) % list.length]; // 07 — Each press rolls in the next word on a drum. Letters sit on a
Adds the files to
components/uibrik/rolling-word and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/rolling-word.Usage
import { RollingWord } from "@/components/uibrik/rolling-word/rolling-word";<RollingWord play={0} prefix="Build something" words={["calm", "honest", "lasting", "yours"]} duration={0.45} exitDuration={0.35} stagger={0.03}/>Where to use Rolling Word
Rotating headlines
One word rolling to the next like a drum lets a headline speak to several audiences.
Pairs with Anagram Shuffle
"Built for" taglines
A rolling slot works for lines like "Built for designers, developers and teams".
Section titles
A single changing word keeps a title short while covering several use cases.
Props
RollingWord- prefix
- Type string
- "Build something"
- Fixed text before the rolling word.
- words
- Type string[]
- ["calm","honest","lasting","yours"]
- Cycled through, one per play.
- duration
- Type number
- 0.45
- Time for a letter to roll in.
- exitDuration
- Type number
- 0.35
- Time for a letter to roll out.
- stagger
- Type number
- 0.03
- Delay between letters.
- playrequired
- Type number
- –
- Each change plays the effect again; 0 shows its resting state.
- className
- Type string
- –
- Classes for the line, merged over the defaults.