Time Picker

Pick a time of day from generated slots. The value is always HH:mm in 24-hour form regardless of how it is displayed — the format is presentation, the value is data.

src/components/ui/time-picker.tsx

About

From the component's own source, where it was written.

Pick a time of day.

The value is HH:mm in 24-hour form regardless of how it is displayed. A component that hands back "2:30 PM" pushes parsing onto every caller and breaks the moment the locale changes; the display format is presentation and the value is data.

Options are generated at a fixed interval rather than offering free entry. Typing a time is a parsing problem with a dozen ambiguous cases ("230", "2.30", "14h"), and for scheduling a list of slots is what people actually want.

Install

npx astralyx-ui add time-picker

Usage

import { TimePicker } from '@/components/ui/time-picker'

<TimePicker value={time} onValueChange={setTime} interval={15} />

Composer

Change the props and the source below follows.

Props
tsx
<TimePicker
  value={time}
  onValueChange={setTime}
  interval={30}
  hour12={false}
/>

Examples

Slots

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

TimePicker

Extends Omit<ComponentProps<'div'>, 'defaultValue' | 'onChange'>.

PropTypeDefaultDescription
valuestring—HH:mm, 24-hour, whatever the display format.
defaultValuestring——
onValueChange(value: string) => void—HH:mm, 24-hour, whatever the display format.
intervalnumber30Minutes between options.
minstring'00:00'Bounds the generated list — business hours, a booking window.
maxstring'23:59'Bounds the generated list — business hours, a booking window.
hour12booleanfalseDisplay only; formatting goes through Intl.
placeholderstring'Select a time'—
sizekeyof typeof fieldSize'md'—
variant'default' | 'secondary' | 'ghost''default'—
errorbooleanfalse—
disabledbooleanfalse—
localestring'en-GB'Display only; formatting goes through Intl.
listLabelstring'Times'Accessible name for the listbox.

Behaviour

TopicDetailDescription
no free entryby designTyping a time is a parsing problem with a dozen ambiguous cases ("230", "2.30", "14h"); for scheduling, slots are what people want.