motion/roll
import { … } from 'zidane-ui'ui/src/motion/roll.tsx
Components#
RollingTextComponent#
Text whose changed characters roll like an odometer: up when the value
grows, down when it shrinks. Unchanged characters hold still, so a
counter ticking 3.51k → 3.52k moves one digit. The formatting stays
whatever the caller renders (3.51k, $42.057, 12s); pass value so
the direction follows the number rather than the characters. Wrap in
SmoothWidth when the length can change.
function RollingText(props: RollingTextProps): ElementParameters
| Name | Type | Description |
|---|---|---|
| props | RollingTextProps | Component props. |
Returns
ElementProps
| Name | Type | Description |
|---|---|---|
| className? | string | Extra classes on the wrapping element. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
| text | string | The formatted text to show. Characters that differ from the previous text roll. |
| value? | number | The number behind |
Functions#
readRollMsFunction#
How long one roll plays, read off the motion vars: the longer of the enter (settle, fade) and the exit.
function readRollMs(): numberReturns
numberrollCellsFunction#
Per-character diff for RollingText, aligned from the RIGHT so the
units stay in their column when the number grows a digit (9.99k →
10.0k). Each cell is the new character plus the one it replaces:
null when unchanged, '' when the column is new.
function rollCells(prev: string, next: string): { char: string; from: string | null }[]Parameters
| Name | Type | Description |
|---|---|---|
| prev | string | The text before the change. |
| next | string | The text after the change. |
Returns
{ char: string; from: string | null }[]One cell per character of next.
Interfaces#
RollingTextPropsInterface#
Props for RollingText.
interface RollingTextPropsProperties
| Name | Type | Description |
|---|---|---|
| className? | string | Extra classes on the wrapping element. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
| text | string | The formatted text to show. Characters that differ from the previous text roll. |
| value? | number | The number behind |
Types#
RollDirectionType#
Direction characters roll in RollingText: up when the value grows, down when it
shrinks.
type RollDirection = 'up' | 'down'