Skip to content
Get Kosh Pro
← All components
Motion

ComponentsMorph Bars

Morph Bars

Bars spring from where they are.

  • Motion layer
  • Implemented
  • Kosh Pro · $15 once
Minutes of practice by weekday
Mon42
Tue68
Wed31
Thu77
Fri54
Sat23
Sun60
motion prop

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

PowerShell / install with a Kosh Pro key
npx shadcn@latest add @kosh-pro/morph-bars
React / TypeScript
import { 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

Morph Bars props
PropTypeDefaultWhat it does
data{ id: string; label: string; value: number }[]requiredThe bars. The id must be stable: it is what lets a bar animate from its own previous value.
maxnumbera round number above the tallest barA fixed top of the scale.
sort"none" | "desc" | "asc""none"Reordering slides bars to their new places.
formatValue(value: number) => stringStringHow the value above each bar is printed.
heightnumber | string240The plot reserves this height. A CSS value such as var(--h) works too.
highlightstringnoneThe id of one bar to draw in the signal colour.
labelstring"Bar chart"Caption of the table that screen readers get.
enterbooleanfalseIf the chart is off screen at load, its bars rise from the baseline as it scrolls into view.
Shared by every Kosh component
PropTypeDefaultWhat 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() => voidnoneCalled once the component has come to rest after an update.
classNamestringnoneAdded 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.