← All components
Motion
ComponentsMorph Bars
Morph Bars
Bars spring from where they are.
- Motion layer
- Implemented
- Kosh Pro · $15 once
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
Charts that redraw from zero on every update make you find your bar again. Springing from the old value turns the update into the information: you see which bars moved and how far. Push twice quickly and they turn around mid-flight, because a spring keeps its velocity.
Use it
npx shadcn@latest add @kosh-pro/morph-barsimport { MorphBars } from "@/kosh/morph-bars/morph-bars";
<MorphBars
data={[
{ id: "mon", label: "Mon", value: 42 },
{ id: "tue", label: "Tue", value: 68 },
{ id: "wed", label: "Wed", value: 31 },
]}
sort="desc"
highlight="tue"
/>Morph Bars is part of Kosh Pro. Your license key unlocks the @kosh-pro registry, which installs it with the motion core it needs. Set up the Pro registry ↗ Get Kosh Pro ↗
At each motion level
full- Each changed bar springs from its current height, with its current velocity, to the new one (about 11% overshoot, about 400 ms). Changed bars flash the signal colour. A new order slides bars sideways with no overshoot. A bar that is added rises from the baseline, one that is removed fades, and the others slide and resize to make room.
reduced- Bars jump to their new height and place. The flash stays: it is now the only cue that something changed.
none- Plain elements at their new size. The Motion engine is not used, and is not downloaded if nothing else needs it.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
data | { id: string; label: string; value: number }[] | required | The bars. The id must be stable: it is what lets a bar animate from its own previous value. |
max | number | a round number above the tallest bar | A fixed top of the scale. |
sort | "none" | "desc" | "asc" | "none" | Reordering slides bars to their new places. |
formatValue | (value: number) => string | String | How the value above each bar is printed. |
height | number | string | 240 | The plot reserves this height. A CSS value such as var(--h) works too. |
highlight | string | none | The id of one bar to draw in the signal colour. |
label | string | "Bar chart" | Caption of the table that screen readers get. |
enter | boolean | false | If the chart is off screen at load, its bars rise from the baseline as it scrolls into view. |
| 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-bars-fill, --k-bars-gap, --k-bars-radius.
Accessibility
- The bars are decoration to a screen reader. The same data is a real table, in the visible order.
- Values are printed above the bars, so the flash is never the only way to see a change.
Limits and differences
- While the number of bars is changing, each bar's rounded corners are stretched for a moment, because the width change is replayed with a transform.