Clock
A time on wheels, out of a field: hours, minutes and the day period, scrolled or stepped with the arrows.
Installation
pnpm dlx @human-kit/design add clocknpx @human-kit/design add clockyarn dlx @human-kit/design add clockbunx @human-kit/design add clockThe command copies the files to src/lib/components/ui/clock. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Clock from '$lib/components/ui/clock';
let time = $state<string | null>('09:30');
</script>
<Clock.Root label="Appointment" bind:value={time} /> Examples
Steps and limits
minuteStep keeps only the minutes the schedule books, and minValue and maxValue turn off the times outside opening hours. A time outside them stays on the wheel, greyed out, so the wheel keeps its order.
Guidelines
- Use
Clock.Rootwhen picking the time is the whole task: on its own in a panel, or beside a calendar. In a row of form fields, use the time picker, which opens these same wheels from a field. - Use the
outlinevariant when the clock stands on the page,filledfor one that should read lighter than a card, andghostinside a card or a popover that already draws a box. - Set
minuteStepto what the schedule books, 5 or 15. Sixty rows of minutes make a long wheel for a choice that has four answers. - Leave
hourCycleto the locale unless the product fixes one. A clinic that prints 24-hour times everywhere should ask for them here too. - Ask for seconds with
granularity="second"only when they mean something, as in a lab log.
Accessibility
- Each wheel is a
role="spinbutton"with its value, its text and its limits, so a screen reader reads "9 hours" and not a list of numbers. - Up and Down step the focused wheel, Home and End go to its first and last value, and Left and Right move between the wheels.
labelnames the clock througharia-labelledby. Without it, give the clock anaria-label.- The keyboard focus is drawn inside the chosen row, as a ring outside it would be cut by the scroll of the wheel.
disabledtakes every wheel out of the tab order and dims the clock.
API reference
| Prop | Type | Default |
|---|---|---|
value | string | null The time, as | — |
defaultValue | string | null The time at the start, when no | — |
onChange | (value: string | null) => void Runs each time a wheel settles on a new value. | — |
variant | 'outline' | 'filled' | 'ghost' A card of its own around the wheels, a soft grey, or the wheels straight on the surface. | 'outline' |
label | string The name over the clock. | — |
granularity | 'hour' | 'minute' | 'second' The smallest unit it asks for. | 'minute' |
hourCycle | 12 | 24 Hours to 12 with a day-period wheel, or to 24. Without it, the locale decides. | — |
hourStep | number The step between the hours of the wheel. | 1 |
minuteStep | number The step between the minutes of the wheel. | 1 |
secondStep | number The step between the seconds of the wheel. | 1 |
minValue | string The earliest time it takes, as | — |
maxValue | string The latest time it takes, as | — |
disabled | boolean Turns every wheel off. | false |
class styles the outer box, with the label. Every other attribute of a <div>, aria-label among them, goes on the element that holds the wheels.