10:45 to 12:00 GMT · 1 h 15 min
layoutpastdisabledimport { useState } from "react"
import { Button } from "@/components/ui/button"
import { TimeSlots, type TimeSlot } from "@/components/ui/time-slots"
export function Room({ busy, minutesNow }: { busy: TimeSlot[]; minutesNow: number }) {
const [slot, setSlot] = useState<TimeSlot | null>({ start: 645, end: 720 })
return (
<TimeSlots
aria-label="Room"
timeZone="GMT"
busy={busy}
now={minutesNow}
value={slot}
onValueChange={setSlot}
>
<Button size="sm" disabled={!slot}>Book</Button>
</TimeSlots>
)
}Usage
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { TimeSlots, type TimeSlot } from "@/components/ui/time-slots"
export function Room({ busy }: { busy: TimeSlot[] }) {
const [slot, setSlot] = useState<TimeSlot | null>(null)
return (
<TimeSlots aria-label="Room" timeZone="GMT" busy={busy} value={slot} onValueChange={setSlot}>
<Button size="sm" disabled={!slot}>Book</Button>
</TimeSlots>
)
}Examples
10:45 to 12:00 GMT · 1 h 15 min
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { TimeSlots, type TimeSlot } from '@/components/ui/time-slots';
export function Example({ busy }: { busy: TimeSlot[] }) {
const [slot, setSlot] = useState<TimeSlot | null>({ start: 645, end: 720 });
return (
<TimeSlots aria-label="Room" className="max-w-3xl" timeZone="GMT" busy={busy} value={slot} onValueChange={setSlot}>
<Button size="sm" disabled={!slot}>Book</Button>
</TimeSlots>
);
}11:00 to 12:00 GMT
1 h
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { TimeSlots, type TimeSlot } from '@/components/ui/time-slots';
export function Example({ busy }: { busy: TimeSlot[] }) {
const [slot, setSlot] = useState<TimeSlot | null>(null);
return (
<TimeSlots aria-label="Room" layout="vertical" className="h-96 w-80" timeZone="GMT" busy={busy} value={slot} onValueChange={setSlot}>
<Button size="sm" disabled={!slot}>Book</Button>
</TimeSlots>
);
}Notes
Minutes and zones
Every time is minutes since midnight, in whatever zone timeZone names. Convert before you pass busy, and after you read value. Pass now as a Date with an IANA timeZone and the track works out the time there.
Pressing the track
Pressing free time starts a new booking there, even on top of the current one. Only the handles at either end resize it. Near the end of a free stretch, the new booking runs back from the press so it still fits.
Phone and desktop
Below 768px the day turns vertical, as half-hour rows. Tap a free row, then a later one to stretch the booking to it. Tapping a lone booked row clears it.
API
{ start: 645, end: 720 }.details.cancel() refuses it.Europe/London, a now given as a Date is read in it.single picks one time, such as an arrival, held for minDuration. Its value is still { start, end }; forms and agents get HH:MM.timeZone against date: a later day has no past, an earlier one is all past.horizontal is a track to drag across. vertical is rows of half an hour, or the nearest whole number of steps, to tap. auto switches at 768px.HH:MM/HH:MM, or HH:MM in single mode.Agent
Inside an AgentProvider, it appears in agent.snapshot() as slider.
Reads
labelThe aria-label, "Booking" by default.
valueThe booking as ["HH:MM", "HH:MM"], "HH:MM" in single mode, or nothing.
Actions
setValue(["10:45", "12:00"])Books a span. "11am to 12:30" works too; null clears it. In single mode one time, "3pm", is enough.
An agent's change runs through onValueChange like anyone's. isAgentChange(details) is true for it; details.cancel() refuses it. A span that crosses busy time, starts before now, leaves the day, misses the step, or is shorter or longer than allowed is refused with the reason.
await agent.act({
steps: [{ ref: "Room", action: "setValue", args: [["14:00", "15:00"]] }],
})Accessibility
- The track is a slider named Time span, or Time in single mode, inside a group carrying the component's label. Its value text is the booking with its zone and length, such as 10:45 to 12:00 GMT, 1 h 15 min.
- The slider's description lists busy and past time, since the arrows step over it.
- In rows, each row is a button named with its time and whether it is free, booked, busy, past or unavailable. Only one row is in the tab order.
- In rows, the readout is a live region, so the booking is announced as it changes. On the track, the slider announces it instead.
- Busy and unavailable time is hatched, at 3:1 or more against free time in both themes, so it reads without color. Past time sits behind the now line.