Animated Label
Rolling text changes and width transitions with the complete Zenos Text styling API.
Animated Label rolls between short labels and eases the space they occupy. Its interaction is inspired by Koala UI’s Animated Label, implemented here with native browser animations and Zenos Text. No additional animation package is needed.
Install
Section titled “Install”pnpm dlx @zentara-co/zenos-cli add animated-labelThe CLI copies animated-label.tsx into your chosen directory. Import it from your application-owned path:
import { AnimatedLabel } from "./components/animated-label";In a button
Section titled “In a button”Additional details are visible while the disclosure is expanded.
Change swapKey when the label’s meaning changes. An ordinary rerender leaves the motion alone. Keep icons outside the animated label when they should remain stationary or rotate independently. Use as="span" inside buttons so the markup stays phrasing content, and className="text-inherit" to inherit the button’s foreground color instead of Text’s default color.
Typography and direction
Section titled “Typography and direction”The component accepts every Text styling prop: as, type, size, weight, color, align, italic, truncate, maxLines, className, and style. Native props and ref belong to the rendered Text root. align holds the corresponding logical edge during width changes and also controls Text alignment. Use start for text in a paragraph or list; the default is center for button labels.
direction="up" lifts the outgoing label and brings the new one from below. Use down to reverse it. duration is in milliseconds, and easing accepts a CSS easing string. An interrupted transition starts from the width currently on screen.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Current non-interactive label content. |
swapKey | string | number | — | Required identity for the displayed label. A change starts a transition. |
animated | boolean | true | Enables rolling and width transitions. |
duration | number | 200 | Animation duration in milliseconds. Zero swaps immediately. |
easing | string | cubic-bezier(0.16, 1, 0.3, 1) | Timing curve for the roll and width transition. |
direction | up | down | up | Direction of the outgoing label. |
align | TextAlign | center | Text alignment and the edge held during width transitions. |
Text props / ref | TextProps<C> | — | Typography, polymorphic root semantics, native props, and root ref. |
Accessibility and styling
Section titled “Accessibility and styling”Only the current label is exposed to assistive technology. The outgoing snapshot is inert, hidden, and removed when motion finishes. Its previous color and font remain in place during the exit. The first render does not animate. Reduced motion or missing browser animation support produces an immediate text change; changing the system preference also stops active transitions.
Use short, non-interactive labels. The rolling viewport clips its contents, so keep focusable controls outside it. Add live-region semantics only when a status needs to be announced. Stable slots are animated-label, animated-label-viewport, animated-label-current, and animated-label-outgoing.