DitherCharts

Time picker

Updated

TimePicker is a select-style field that opens scrolling hour, minute and AM/PM columns in the dithered popup. Arrow keys move within a column and Left and Right between them; it shows the time in the reader's locale and submits "HH:mm". Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

Office hours, every 15 minutes.

Pick a reminder time

import "@/components/dithercharts/controls.css"
import { TimePicker } from "@/components/dithercharts/time-picker"

<TimePicker
  label="Standup"
  name="standup"
  minuteStep={15}
  min="08:00"
  max="18:00"
  onValueChange={(time) => setStandup(time)} // "HH:mm"
/>

Install

Controls install with DitherCharts Pro. See Installation to log in, then import controls.css once, e.g. in your root layout.

npx dithercharts add time-picker

Props

It renders a native element, so every other attribute that element takes passes through.

TimePicker props
PropTypeDefaultDescription
labelrequiredType ReactNodeDefault –The caption above the field, and its accessible name.
placeholderType stringDefault "Pick a time"Shown while nothing is chosen.
nameType stringDefault –The form field name for the time's hidden input.
disabledType booleanDefault false
collisionPaddingType { top?: number; bottom?: number }Default 8 eachSpace in px the popup keeps clear at the window's top and bottom, e.g. a sticky header's height. It opens on the side with more room.
classNameType stringDefault –
valueType stringDefault –The chosen time as 24-hour "HH:mm", for a controlled picker; pair it with onValueChange.
defaultValueType stringDefault –The time chosen at first, for an uncontrolled picker.
onValueChangeType (value: string) => voidDefault –Called with the time as "HH:mm" each time a column changes it.
minType stringDefault –The earliest time that can be chosen, as "HH:mm".
maxType stringDefault –The latest time that can be chosen, as "HH:mm".
minuteStepType numberDefault 5The gap between the minutes offered.
hourCycleType 12 | 24Default the locale's12 adds an AM/PM column; 24 doesn't.
localeType stringDefault the browser'sThe BCP 47 locale for the field's time and the day periods.
hintType ReactNodeDefault –Help text under the field, read after its label.
errorType ReactNodeDefault –An error under the field; it also marks the field invalid.