Roll Text
3D horizontal-axis cube roll text transition with automatic numeric direction detection, configurable perspective, and optional screen-reader live announcements.
Customize
Installation
npx shadcn@latest add @kinetic/roll-textUsage
Pass a controlled string to value. Whenever value changes, the outgoing text rotates away by 90 degrees while the incoming text rotates in from the opposite face on the shared cubeRoll WAAPI helper.
import { RollText } from "@/components/kinetic/ui/roll-text";
interface StatusBadgeProps {
readonly label: string;
}
export function StatusBadge({ label }: StatusBadgeProps) {
return (
<span className="inline-flex items-center rounded-md border border-border px-2.5 py-1 text-sm font-medium">
<RollText value={label} />
</span>
);
}Direction and perspective
Set direction to 1 (roll forward), -1 (roll backward), or "auto" (default). In "auto" mode, values that share the same prefix and suffix around a number (such as "$19.00" to "$24.00" or "Step 2" to "Step 1") automatically roll forward when increasing and backward when decreasing. Use perspective (default 420, clamped 120 to 2000) to adjust the 3D depth.
import { RollText, type RollTextDirection } from "@/components/kinetic/ui/roll-text";
interface StepHeaderProps {
readonly label: string;
readonly direction: RollTextDirection;
}
export function StepHeader({ label, direction }: StepHeaderProps) {
return (
<RollText
value={label}
direction={direction}
perspective={520}
className="text-2xl font-semibold tracking-tight"
/>
);
}Screen reader and reduced motion
By default live="off" keeps RollText silent so frequent updates do not flood assistive technology. Pass live="polite" (renders role="status") or live="assertive" (role="alert") on a stably mounted outer span when updates should be announced. The outgoing face always carries aria-hidden="true" so old and new strings are never read twice.
speed and durationMs scale with the global Kinetic tempo. Under reduced motion, RollText cancels any active roll, skips the width transition, swaps immediately, and fires onComplete.
API Reference
RollText
3D cube-face text swap powered by the shared cubeRoll WAAPI helper with smooth inline width transitions.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | Text value to display. Updating this prop triggers a 3D cube roll. |
direction | 1 | -1 | "auto" | "auto" | Roll direction: 1 for forward, -1 for reverse, or auto to infer direction from numeric tokens. |
perspective | number | 420 | CSS perspective depth in pixels applied to the 3D stage (clamped 120 to 2000). |
durationMs | number | 280 | Base roll duration in milliseconds before tempo and speed scaling. |
speed | number | 1 | Speed multiplier clamped between 0.25 and 4, combined with global tempo. |
live | "off" | "polite" | "assertive" | "off" | Optional ARIA live region politeness on the stable outer span; outgoing face is always aria-hidden. |
onComplete | () => void | - | Called when the cube roll finishes (or immediately under reduced motion). |