Bar picker
Columns of lights with one picked, as a radiogroup.
Demo
Usage
import { BarPicker } from '@tuttn/slant'
// Each column's level is its share of the busiest, from 0 to 1.
const days = [
{ value: 'mon', label: 'Mon', level: 9 / 17, 'aria-label': 'Monday, 9 deploys' },
{ value: 'thu', label: 'Thu', level: 1, 'aria-label': 'Thursday, 17 deploys' },
{ value: 'sun', label: 'Sun', level: 1 / 17, 'aria-label': 'Sunday, 1 deploy' },
] as const
// Controlled: pass value and onValueChange, and show the chosen figure beside it.
const [day, setDay] = useState<'mon' | 'thu' | 'sun'>('thu')
<BarPicker options={days} value={day} onValueChange={setDay} label="Deploys by day" />
// Uncontrolled: leave value out; it starts from defaultValue (or the first enabled column).
<BarPicker size="sm" options={hours} defaultValue="11" lights={6} tone="success" label="Builds by hour" />
// In a form: a name adds a hidden input holding the chosen value.
<BarPicker options={days} defaultValue="mon" label="Deploys by day" name="day" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | readonly BarPickerOption<T>[] | — | The columns, in order from the inline start. `T` is inferred from their values. |
value | T | — | The chosen column's value. Pass it to control the picker; leave it out to let the picker keep its own. |
defaultValue | T | the first enabled option | The value an uncontrolled picker starts with. |
onValueChange | (value: T) => void | — | Called with the new value when a click or an arrow key chooses a column. |
label | string | — | The group's accessible name, e.g. "Deploys by day". |
lights | number | 8 | The number of lights in each column. |
tone | Tone | 'accent' | The colour of the chosen column's lights. |
size | 'sm' | 'md' | 'md' | `md` spreads its columns across the row; `sm` is the compact variant with smaller lights that hugs its columns. |
disabled | boolean | false | Disables every column. A disabled picker is not submitted with its form. |
name | string | — | Submits the picker with a form: a hidden input with this name carries the chosen value. |
form | string | — | The id of the form the hidden input belongs to, when the picker sits outside it. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style, other attributes and the ref reach the radiogroup element. |
A bar picker suits a handful of values with one in focus: the days of a week, the hours of a shift. For many values, several series or a precise reading, use a bar chart; for one level on its own, a meter.
Keyboard
It behaves like Segmented. Tab reaches only the chosen column (or the first enabled one). The arrow keys move to the next or previous column and choose it, wrapping at the ends, and Home and End jump to the first and last; disabled columns are passed over. Under <Slant dir="rtl"> the columns run from the right and Left and Right swap.
Accessibility
The row is a radiogroup named by label, and each column a radio. The lights are drawn only, hidden from assistive technology, so a column's level is not read out: give each option an aria-label that carries the figure ("Thursday, 17 deploys"); without one, the radio is named by its visible label. A level is clamped to 0–1 and rounded to the nearest light, and any level above 0 lights at least one, so a quiet column never looks empty.
Motion
There is no running animation, so nothing to pause off screen. A change of choice or level pours the light up the column in short transitions on the motion tokens; under reduced motion it happens at once.