TimePicker
An hour of the day. Hours and minutes are typed on their own; the screen shows 12 or 24 hours as the person’s language does, and the value is always 24 hours (14:30).
import { TimePicker } from '@sypnia/ui/react'
On this page
An hour
In English it shows AM and PM; in Spanish, 24 hours. The value under it is the same in both.
Saved as 03:00, in the time zone of the project.
Code
import { useState } from 'react';
import { Field, FormGrid, TimePicker } from '@sypnia/ui/react';
export default function Basic() {
const [at, setAt] = useState<string | null>('03:00');
return (
<FormGrid>
<Field label="Back up every day at" hint={at ? <>Saved as <code>{at}</code>, in the time zone of the project.</> : 'Choose a quiet hour.'}>
<TimePicker value={at} onChange={setAt} />
</Field>
</FormGrid>
);
} States
Always 24 hours, with an error that says how to fix it, and disabled.
Reports go out between 06:00 and 22:00. Choose an hour in that window.
Set by Sypnia for every project in this region.
Code
import { Field, FormGrid, TimePicker } from '@sypnia/ui/react';
export default function States() {
return (
<FormGrid>
<Field label="Always in 24 hours">
<TimePicker hourCycle={24} defaultValue="18:45" />
</Field>
<Field label="Send the report at" error="Reports go out between 06:00 and 22:00. Choose an hour in that window.">
<TimePicker defaultValue="23:30" min="06:00" max="22:00" />
</Field>
<Field label="Maintenance starts at" hint="Set by Sypnia for every project in this region.">
<TimePicker disabled defaultValue="04:00" />
</Field>
</FormGrid>
);
} When to use it
Use it when
- Something happens every day at an hour: a backup, a report, a quiet period.
- The hour has limits:
minandmax.
Do not use it when
- It needs the day too: DateTimePicker.
- It is a length of time (90 minutes), not an hour of the day: NumberInput with a unit, or DurationInput.
- Only a few fixed hours can be chosen: Select.
For everyone
- Each part is a
spinbutton: typing fills it and jumps to the next; up and down arrows change it; left and right move between parts. - With 12 hours, «a» and «p» set AM and PM.
- The parts are announced as hour, minute and AM/PM, in the language of the page.
- Inside a Field it takes the label, the hint and the error by itself; alone, give it an
aria-label.
Props
| TimePicker | Type | Default |
|---|---|---|
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | string | |
disabled | boolean | |
hourCycle12 or 24 hours on screen. By default, what the language uses. | 12 | 24 | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
maxThe latest hour. | string | |
minThe earliest hour, as `08:00`. | string | |
name | string | |
onChange | ((time: string | null) => void) | |
valueThe hour, as `14:30` (always 24 hours in the value), or null while it is empty. | string | null |