Motion
word-rotate
One word in a sentence that changes to the next of a list in place, rising and fading, once through the list (or round and round with loop, pausing while hovered or focused); screen readers hear the whole list once, and under reduced motion the last word simply stands.
When to use it
A headline that names several things one after another: "Charts for teams / schools / newsrooms". Keep the words about the same length. For a whole heading appearing use text-reveal; for a number counting up use number-ticker.
See it working
The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Effects and 3D data page.
Word rotate and pattern
Maps for teams, schools, or newsrooms
Animated beam
A map becomes a film.
Orbit
- Maps
- Charts
- Films
- Motion
Confetti
Not yet published.
Point cloud
- Clay
- Stone
- Glass
| # | width | height | kind |
|---|---|---|---|
| 1 | 0.2 | 1.2 | Clay |
| 2 | 0.2 | 2.1 | Clay |
| 3 | 0.2 | 2.5 | Clay |
| 4 | 0.3 | 0.6 | Clay |
| 5 | 0.3 | 2.2 | Clay |
| 6 | 0.3 | 2.5 | Clay |
| 7 | 0.4 | 0.5 | Clay |
| 8 | 0.5 | 0.6 | Clay |
| 9 | 0.5 | 2.1 | Clay |
| 10 | 0.6 | 1.4 | Clay |
| 11 | 0.7 | 0.7 | Clay |
| 12 | 0.8 | 1.4 | Clay |
| 13 | 0.9 | 0.6 | Clay |
| 14 | 1 | 0.5 | Clay |
| 15 | 1.1 | 2.2 | Clay |
| 16 | 1.2 | 0.6 | Clay |
| 17 | 1.2 | 1.1 | Stone |
| 18 | 1.2 | 1.2 | Stone |
| 19 | 1.2 | 1.2 | Stone |
| 20 | 1.2 | 2.5 | Clay |
| 21 | 1.3 | 1.1 | Clay |
| 22 | 1.3 | 1.3 | Stone |
| 23 | 1.3 | 1.7 | Stone |
| 24 | 1.3 | 2 | Stone |
| 25 | 1.5 | 2.5 | Clay |
| 26 | 1.5 | 2.6 | Stone |
| 27 | 1.5 | 2.8 | Stone |
| 28 | 1.6 | 1.3 | Clay |
| 29 | 1.6 | 2.1 | Clay |
| 30 | 1.6 | 3.1 | Stone |
| 31 | 1.7 | 2 | Clay |
| 32 | 1.7 | 3.1 | Stone |
| 33 | 1.8 | 2 | Clay |
| 34 | 1.8 | 2.9 | Stone |
| 35 | 1.8 | 3.1 | Stone |
| 36 | 1.9 | 1.2 | Clay |
| 37 | 1.9 | 2.7 | Stone |
| 38 | 2 | 2.5 | Clay |
| 39 | 2.1 | 0.6 | Clay |
| 40 | 2.1 | 2.2 | Clay |
| 41 | 2.1 | 2.7 | Stone |
| 42 | 2.2 | 0.7 | Clay |
| 43 | 2.2 | 1.3 | Clay |
| 44 | 2.2 | 1.5 | Clay |
| 45 | 2.2 | 2 | Stone |
| 46 | 2.2 | 2.6 | Glass |
| 47 | 2.2 | 2.6 | Stone |
| 48 | 2.2 | 3.4 | Glass |
| 49 | 2.2 | 3.7 | Glass |
| 50 | 2.3 | 1.8 | Stone |
| 51 | 2.3 | 3.7 | Glass |
| 52 | 2.4 | 1.7 | Glass |
| 53 | 2.4 | 1.8 | Glass |
| 54 | 2.4 | 3.3 | Glass |
| 55 | 2.5 | 1.3 | Stone |
| 56 | 2.6 | 1.2 | Stone |
| 57 | 2.6 | 1.8 | Glass |
| 58 | 2.6 | 2.4 | Glass |
| 59 | 2.7 | 1.2 | Stone |
| 60 | 2.7 | 2.3 | Glass |
| 61 | 2.8 | 1.2 | Stone |
| 62 | 2.9 | 1.3 | Stone |
| 63 | 2.9 | 1.7 | Stone |
| 64 | 2.9 | 2.5 | Glass |
| 65 | 3 | 1.7 | Glass |
| 66 | 3 | 1.9 | Stone |
| 67 | 3 | 3.2 | Glass |
| 68 | 3.1 | 1.8 | Glass |
| 69 | 3.1 | 1.8 | Stone |
| 70 | 3.1 | 2.1 | Stone |
| 71 | 3.1 | 2.6 | Stone |
| 72 | 3.1 | 2.8 | Stone |
| 73 | 3.2 | 2.7 | Stone |
| 74 | 3.2 | 3.1 | Stone |
| 75 | 3.3 | 1.9 | Glass |
| 76 | 3.4 | 2.5 | Glass |
| 77 | 3.4 | 3.7 | Glass |
| 78 | 3.5 | 3.5 | Glass |
| 79 | 3.7 | 2.7 | Glass |
| 80 | 3.7 | 3.4 | Glass |
| 81 | 3.8 | 2.6 | Glass |
| 82 | 3.8 | 3.4 | Glass |
| 83 | 4 | 1.9 | Glass |
| 84 | 4 | 2.5 | Glass |
| 85 | 4 | 3.7 | Glass |
| 86 | 4.1 | 3.3 | Glass |
| 87 | 4.2 | 1.8 | Glass |
| 88 | 4.2 | 2.3 | Glass |
| 89 | 4.2 | 2.4 | Glass |
| 90 | 4.2 | 3.2 | Glass |
| # | width | height | depth | kind |
|---|---|---|---|---|
| 1 | 1.2 | 2.5 | 2.5 | Clay |
| 2 | 3.2 | 2.7 | 3.2 | Stone |
| 3 | 2.9 | 2.5 | 3.8 | Glass |
| 4 | 0.3 | 0.6 | 4.3 | Clay |
| 5 | 2.7 | 1.2 | 4.5 | Stone |
| 6 | 4 | 2.5 | 4.4 | Glass |
| 7 | 0.5 | 2.1 | 4.1 | Clay |
| 8 | 1.6 | 3.1 | 3.5 | Stone |
| 9 | 4.1 | 3.3 | 2.9 | Glass |
| 10 | 1.6 | 1.3 | 2.1 | Clay |
| 11 | 1.2 | 1.2 | 1.4 | Stone |
| 12 | 3.1 | 1.8 | 0.9 | Glass |
| 13 | 2.2 | 1.3 | 0.6 | Clay |
| 14 | 2.1 | 2.7 | 0.5 | Stone |
| 15 | 2.2 | 3.7 | 0.7 | Glass |
| 16 | 1.6 | 2.1 | 1.2 | Clay |
| 17 | 3.1 | 1.8 | 1.8 | Stone |
| 18 | 2.6 | 1.8 | 2.5 | Glass |
| 19 | 0.5 | 0.6 | 3.2 | Clay |
| 20 | 3 | 1.9 | 3.9 | Stone |
| 21 | 3.7 | 3.4 | 4.3 | Glass |
| 22 | 0.3 | 2.5 | 4.5 | Clay |
| 23 | 1.9 | 2.7 | 4.4 | Stone |
| 24 | 4.2 | 2.4 | 4.1 | Glass |
| 25 | 1.2 | 0.6 | 3.5 | Clay |
| 26 | 1.2 | 1.2 | 2.8 | Stone |
| 27 | 3.4 | 2.5 | 2.1 | Glass |
| 28 | 2.1 | 2.2 | 1.4 | Clay |
| 29 | 1.7 | 3.1 | 0.9 | Stone |
| 30 | 2.4 | 3.3 | 0.6 | Glass |
| 31 | 1.9 | 1.2 | 0.5 | Clay |
| 32 | 2.8 | 1.2 | 0.7 | Stone |
| 33 | 2.4 | 1.8 | 1.2 | Glass |
| 34 | 0.8 | 1.4 | 1.8 | Clay |
| 35 | 3.1 | 2.8 | 2.5 | Stone |
| 36 | 3.4 | 3.7 | 3.2 | Glass |
| 37 | 0.2 | 2.1 | 3.9 | Clay |
| 38 | 2.3 | 1.8 | 4.3 | Stone |
| 39 | 4.2 | 1.8 | 4.5 | Glass |
| 40 | 0.9 | 0.6 | 4.4 | Clay |
| 41 | 1.3 | 2 | 4.1 | Stone |
| 42 | 3.8 | 3.4 | 3.5 | Glass |
| 43 | 2 | 2.5 | 2.8 | Clay |
| 44 | 1.5 | 2.6 | 2.1 | Stone |
| 45 | 2.6 | 2.4 | 1.4 | Glass |
| 46 | 2.1 | 0.6 | 0.9 | Clay |
| 47 | 2.5 | 1.3 | 0.6 | Stone |
| 48 | 2.2 | 2.6 | 0.5 | Glass |
| 49 | 1.1 | 2.2 | 0.7 | Clay |
| 50 | 3.2 | 3.1 | 1.2 | Stone |
| 51 | 3 | 3.2 | 1.8 | Glass |
| 52 | 0.2 | 1.2 | 2.5 | Clay |
| 53 | 2.6 | 1.2 | 3.3 | Stone |
| 54 | 4 | 1.9 | 3.9 | Glass |
| 55 | 0.6 | 1.4 | 4.3 | Clay |
| 56 | 1.5 | 2.8 | 4.5 | Stone |
| 57 | 4 | 3.7 | 4.4 | Glass |
| 58 | 1.7 | 2 | 4.1 | Clay |
| 59 | 1.3 | 1.7 | 3.5 | Stone |
| 60 | 3 | 1.7 | 2.8 | Glass |
| 61 | 2.2 | 0.7 | 2.1 | Clay |
| 62 | 2.2 | 2 | 1.4 | Stone |
| 63 | 2.2 | 3.4 | 0.9 | Glass |
| 64 | 1.5 | 2.5 | 0.6 | Clay |
| 65 | 3.1 | 2.6 | 0.5 | Stone |
| 66 | 2.7 | 2.3 | 0.7 | Glass |
| 67 | 0.4 | 0.5 | 1.2 | Clay |
| 68 | 2.9 | 1.3 | 1.8 | Stone |
| 69 | 3.8 | 2.6 | 2.6 | Glass |
| 70 | 0.3 | 2.2 | 3.3 | Clay |
| 71 | 1.8 | 3.1 | 3.9 | Stone |
| 72 | 4.2 | 3.2 | 4.3 | Glass |
| 73 | 1.3 | 1.1 | 4.5 | Clay |
| 74 | 1.2 | 1.1 | 4.4 | Stone |
| 75 | 3.3 | 1.9 | 4.1 | Glass |
| 76 | 2.2 | 1.5 | 3.5 | Clay |
| 77 | 1.8 | 2.9 | 2.8 | Stone |
| 78 | 2.3 | 3.7 | 2.1 | Glass |
| 79 | 1.8 | 2 | 1.4 | Clay |
| 80 | 2.9 | 1.7 | 0.9 | Stone |
| 81 | 2.4 | 1.7 | 0.6 | Glass |
| 82 | 0.7 | 0.7 | 0.5 | Clay |
| 83 | 3.1 | 2.1 | 0.7 | Stone |
| 84 | 3.5 | 3.5 | 1.2 | Glass |
| 85 | 0.2 | 2.5 | 1.8 | Clay |
| 86 | 2.2 | 2.6 | 2.6 | Stone |
| 87 | 4.2 | 2.3 | 3.3 | Glass |
| 88 | 1 | 0.5 | 3.9 | Clay |
| 89 | 1.3 | 1.3 | 4.3 | Stone |
| 90 | 3.7 | 2.7 | 4.5 | Glass |
Model annotations
- Lid — Hinged at the back.
- Side — A handle was here.
- Front — The maker's mark.
Add it
npx shadcn@latest add @rivier-ui/word-rotate
The registry is named once in components.json: see Installation.
Example
Import it from @/components/motion/word-rotate.
<h1>Maps for <WordRotate words={["teams", "schools", "newsrooms"]} /></h1>
What it needs
A client component: it uses state, effects or browser behaviour. Packages: motion.
It imports
Source
The whole file. Once copied it is yours: the registry item holds the same text.
"use client";
/**
* @name word-rotate
* @category motion
* @description One word in a sentence that changes to the next of a list in place, rising and fading, once through the list (or round and round with `loop`, pausing while hovered or focused); screen readers hear the whole list once, and under reduced motion the last word simply stands.
* @when A headline that names several things one after another: "Charts for teams / schools / newsrooms". Keep the words about the same length. For a whole heading appearing use text-reveal; for a number counting up use number-ticker.
* @example
* <h1>Maps for <WordRotate words={["teams", "schools", "newsrooms"]} /></h1>
*/
import { AnimatePresence, motion } from "motion/react";
import { useEffect, useState, type ComponentProps } from "react";
import { cn } from "@/lib/cn";
import { useMotionSafe } from "@/lib/motion";
export type WordRotateProps = Omit<ComponentProps<"span">, "children"> & {
words: readonly string[];
/** Milliseconds each word stays. Default 2200. */
interval?: number;
/** Go round again and again. Default false: once through, then the last word stays (no motion lasts past a few seconds). */
loop?: boolean;
/** Stops it where it is. */
paused?: boolean;
/** Joins the words for screen readers. Default: Intl's list format in `locale`. */
locale?: string;
};
export function WordRotate({ words, interval = 2200, loop = false, paused = false, locale = "en-US", className, ...props }: WordRotateProps) {
const safe = useMotionSafe();
const [index, setIndex] = useState(0);
const [hold, setHold] = useState(false);
const last = words.length - 1;
const running = safe && !paused && !hold && words.length > 1 && (loop || index < last);
useEffect(() => {
if (!running) return;
const timer = window.setTimeout(() => setIndex((i) => (i >= last ? 0 : i + 1)), interval);
return () => window.clearTimeout(timer);
}, [running, index, interval, last]);
const shown = safe ? (words[index] ?? "") : (words[last] ?? "");
const spoken = new Intl.ListFormat(locale, { type: "disjunction" }).format(words);
return (
<span data-slot="word-rotate" className={cn("relative inline-grid align-bottom", className)} onPointerEnter={() => setHold(true)} onPointerLeave={() => setHold(false)} onFocus={() => setHold(true)} onBlur={() => setHold(false)} {...props}>
<span className="sr-only">{spoken}</span>
{/* The widest word holds the space, so the sentence does not jump. */}
<span aria-hidden="true" className="invisible col-start-1 row-start-1">
{words.reduce((a, b) => (b.length > a.length ? b : a), "")}
</span>
<span aria-hidden="true" className="col-start-1 row-start-1 overflow-hidden">
<AnimatePresence mode="popLayout" initial={false}>
<motion.span
key={shown}
className="inline-block"
initial={safe ? { opacity: 0, y: "60%" } : false}
animate={{ opacity: 1, y: "0%" }}
exit={safe ? { opacity: 0, y: "-60%" } : { opacity: 0 }}
transition={{ duration: 0.35, ease: [0.2, 0, 0, 1] }}
>
{shown}
</motion.span>
</AnimatePresence>
</span>
</span>
);
}