Genesis
@beta

TimePicker

TimePicker — a time of day, picked from a list or typed: the twin of genesis-ui-native's NativeTimePicker. Its `value` is a `Date` (the day is kept, as NativeTimePicker's) or an "HH:MM" string (a time of day alone, as `<input type="time">` holds it), and `onChange` gives back the same kind. The list steps by `minuteStep`; typing "2:30 pm", "14:30" or "1430" puts that time first in the list, highlighted, so Enter picks the time that is highlighted. Reading and writing times is genesis-core's (`parseTimeOfDay`, `formatTimeOfDay`, `timeSlots`), as on the phone. A `Date` is read on the browser's clock once the page has hydrated, or on `timeZone`'s from the first render. The trigger's name is its visible label (`<label htmlFor={id}>`), or `aria-label`, followed by the time. Built from Command in a Popover, like Combobox: the search box is the combobox, arrow keys move through the times, and Enter picks the highlighted one.

packages/ui/src/components/ui/time-picker.tsx

Import
Subpath export: @marktiderman/genesis-ui
import { TimePicker } from "@marktiderman/genesis-ui";
Components
Auto-generated from TypeScript source via react-docgen-typescript.

TimePicker

TimePicker — a time of day, picked from a list or typed: the twin of genesis-ui-native's NativeTimePicker. Its `value` is a `Date` (the day is kept, as NativeTimePicker's) or an "HH:MM" string (a time of day alone, as `<input type="time">` holds it), and `onChange` gives back the same kind. The list steps by `minuteStep`; typing "2:30 pm", "14:30" or "1430" puts that time first in the list, highlighted, so Enter picks the time that is highlighted. Reading and writing times is genesis-core's (`parseTimeOfDay`, `formatTimeOfDay`, `timeSlots`), as on the phone. A `Date` is read on the browser's clock once the page has hydrated, or on `timeZone`'s from the first render. The trigger's name is its visible label (`<label htmlFor={id}>`), or `aria-label`, followed by the time. Built from Command in a Popover, like Combobox: the search box is the combobox, arrow keys move through the times, and Enter picks the highlighted one.

PropTypeDefaultDescription
onChange*((next: Date) => void) | ((next: string) => void)—
value*string | Date—
aria-labelstring—The trigger's name, followed by the time ("Starts, 2:30 PM"). Leave it out when a visible `<label htmlFor={id}>` names the trigger: the label's words and the time are its name then (through `aria-labelledby`). With neither, the name is "Pick a time" and the time.
aria-labelledbystring—The id of an element that names the trigger; the time is added after it.
classNamestring—
disabledboolean—
formatLabel((date: Date) => string) | ((time: string) => string)—The trigger's words. Default the time, in 12 or 24 hours. With `timeZone` it also runs on the server, so format on that same zone (`Intl.DateTimeFormat(…, { timeZone })`), or the server's words and the browser's differ. The trigger's words. Default the time, in 12 or 24 hours.
hour12boolean—12-hour times ("2:30 PM"). Default: the viewer's locale's preference, read after the page has hydrated (24-hour until then), so a server's locale never decides it. Pass it to render the viewer's form from the first paint.
idstring—
minuteStepnumber—Minutes between the listed times. Default 15.
placeholderstring—The trigger's words with no time chosen (an empty string value). Default "Pick a time".
testIDstring—
timeZonestring—The zone whose clock the time is read and picked on (an IANA name, "Europe/Paris"). Default the browser's. Without it the trigger shows no time until the page has hydrated, so a server's zone never decides it; pass it to render the time from the server too. A pick keeps the value's calendar day on this clock, daylight-saving days included (see the README).
Storybook
Storybook hosts the canonical visual reference with controls for every variant.