ComponentsFlow Number
Flow Number
Only the digits that changed roll.
- CSS layer
- Implemented
- Free to install · MIT
onSettle has fired 0 times. The prop can only calm this component further. The switch at the top of the page and your system setting still apply.
Why it moves this way
A count-up re-animates the whole number and hides what changed. Rolling only the changed digits makes the size of the change visible: one digit rolling is a small change, four digits rolling is a big one. The colour says which way it went.
Use it
npx shadcn@latest add https://kosh-hazel.vercel.app/r/flow-number.jsonimport { FlowNumber } from "@/kosh/flow-number/flow-number";
<FlowNumber data={balance} />
<FlowNumber
data={balance}
locale="en-IN"
prefix="₹"
format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }}
onSettle={() => console.log("at rest")}
/>Add the @kosh registry entry to components.json first, so the CLI can fetch motion-core as well. Then wrap your app in KoshProvider once, and import tokens.css and motion.css in your global stylesheet. Read the setup guide ↗ Read the source ↗
At each motion level
full- Each changed digit rolls to its new value in 300 ms, the short way round (9 to 0 is one step), 20 ms apart from the right. Changed digits flash the trend colour and cool back over 2.4 s.
reduced- Digits swap at once. The flash and the cool-down still run, because they are opacity only.
none- The new number, immediately. The digits that changed keep the trend colour until the next update.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
data | number | required | The value to show. A different number triggers an update. |
format | Intl.NumberFormatOptions | no fraction digits | Passed to Intl.NumberFormat. |
locale | string | "en-US" | Grouping and digit style. |
prefix | string | none | Shown before the number, for example "₹". |
suffix | string | none | Shown after the number, for example "%". |
minChars | number | none | Reserves room for at least this many characters, so a growing number never shifts the layout. |
| Prop | Type | Default | What it does |
|---|---|---|---|
motion | "auto" | "full" | "reduced" | "none" | "auto" | Motion for this component only. The calmest of this prop, the provider and the operating system wins. |
tone | "ink" | "signal" | "muted" | "ink" | Which colour carries the data. |
onSettle | () => void | none | Called once the component has come to rest after an update. |
className | string | none | Added to the root element. |
Theme with CSS variables on any ancestor: --k-flow-up, --k-flow-down, --k-dur-roll, --k-dur-cool.
Accessibility
- Screen readers get the formatted number as real text. The rolling digits are hidden from them.
- It does not announce itself. A ticking number that speaks is noise. Put a status region beside it if a change needs announcing.
- The signal colour is about 3:1 on a light canvas. For numbers under 24 px, set --k-flow-up to var(--k-signal-deep).
Limits and differences
- The fade of a place that disappears (1,000 to 999) is positioned for a right-aligned number. Set minChars, or right-align it, when that matters.