Text Swap
betaText that animates from the old string to the new one when its value changes — fade through, shared axis X/Y/Z and per-word crossfade — with a TextRotate for cycling phrases.
- Effects & motion
- 2 files
- 1 npm package
- Accessibility notes
pnpm dlx @dowel-ui/cli add text-swapnpm packages installed: class-variance-authority.
import { TextSwap } from "@/components/ui/text-swap";Default
Gallery
Directions
In Sentence
Live Region
In View
<TextSwap>
| Prop | Type | Default |
|---|---|---|
children (required)The value. Whenever it changes, the old text animates out and the new text in. | string | number | — |
appearAnimate the first value in too. | boolean | "in-view" | false |
asRendered element. Block elements lay out as | TextSwapElement | "span" |
delayMilliseconds added before every entrance. | number | 0 |
directionWhich way the change moves. | "forward" | "backward" | "forward" |
ref | Ref<HTMLElement> | — |
staggerMilliseconds between words, for the split transitions. Defaults to the source's. | number | — |
transitionHow the old text leaves and the new text arrives. | TextSwapTransition | "fade-through" |
Plus every attribute of <span> except children, ref.
8/8
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — does not apply
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — does not apply
- No fixed widths — passes