Time picker
A time of day, entered as an HH:mm field
Deployment window
Opens at
Installation
npx shadcn@latest add @sudokw/components-time-pickerimport { TimePicker } from "@gpuixui/components";Usage
import {
TimePicker,
TimePickerClear,
TimePickerSegment,
TimePickerSeparator,
} from "@gpuixui/components/time-picker";
import { Button } from "@gpuixui/primitives";
import { useState } from "react";
export const DeploymentWindow = () => {
const [opens, setOpens] = useState<string | null>("09:30");
const [saved, setSaved] = useState<string | null>(null);
return (
<>
<TimePicker
clearable
label="Opens at"
minuteStep={15}
onValueChange={(next) => {
setOpens(next);
setSaved(null);
}}
value={opens}
>
<TimePickerSegment segment="hours" />
<TimePickerSeparator />
<TimePickerSegment segment="minutes" />
<TimePickerClear />
</TimePicker>
{/* `opens` is `HH:mm` or `null`. */}
<Button disabled={opens === null} onClick={() => setSaved(opens)}>
{saved === null ? "Save window" : `Saved ${saved}`}
</Button>
</>
);
};Composition
TimePicker
├── TimePickerSegment
├── TimePickerSeparator
└── TimePickerClearAPI reference
TimePicker
| Prop | Type | Default | Consequence |
|---|---|---|---|
value | string | null | — | the controlled HH:mm; undefined makes the field uncontrolled |
defaultValue | string | null | null | the opening time when uncontrolled |
onValueChange | (value: string | null) => void | none | every accepted edit, including the clear path |
label | string | "Time" | the group's accessible name, and the prefix of each segment's name |
minuteStep | number | 1 | the arrow-key step, normalised to an integer in 1..59 |
clearable | boolean | false | renders the clear control while a time is set |
disabled | boolean | false | both segments become readOnly, leave the tab order, and no clear is rendered |
testId | string | "time-picker" | the base id of the parts: -hours, -minutes, -clear |
className | string | — | joined last |
children | ReactNode | none | the segments, separator and clear control, directly inside |
TimePickerSegment
| Prop | Type | Default | Consequence |
|---|---|---|---|
segment | "hours" | "minutes" | required | which half this input edits, and the maximum it clamps to |
style | StateStyle<TimePickerSegmentState> | the recipe | a style, or a function of { disabled, focused } |
TimePickerSeparator
| Prop | Type | Default | Consequence |
|---|---|---|---|
children | ReactNode | ":" | the painted separator |
TimePickerClear
| Prop | Type | Default | Consequence |
|---|---|---|---|
label | string | "Clear time" | the control's accessible name |
Keyboard
- Arrow UpArrow Down
- moves the focused segment by an hour, or by a minute step
- EnterSpace
- clears through the clear target
read from time-picker.tsx
Edit this page on GitHubapps/docs/content/docs/components/time-picker.mdx