Time slot picker
Bookable times for one day as a grid of radio buttons, grouped by part of the day, with taken slots shown but disabled.
pnpm dlx shadcn@latest add @haze/time-slot-picker---
import { Check } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Slot {
/** Time as it should read, such as "09:30". Also the submitted value unless `value` is set. */
time: string;
value?: string;
/** A taken slot stays visible but cannot be chosen. */
available?: boolean;
}
interface Group {
/** Part of the day, such as "Morning". */
label: string;
slots: Slot[];
}
interface Props {
/** Required. Every radio id and the description id are derived from it. */
id: string;
name?: string;
/** Visible question, such as the day being booked. */
legend?: string;
/** Helper line under the legend: duration, staff, time zone. */
description?: string;
groups?: Group[];
/** Value of the slot checked on load. */
value?: string;
/** Word read after a taken slot, for translation. */
takenLabel?: string;
required?: boolean;
class?: string;
}
const {
id,
name = id,
legend = "Tuesday, 25 November",
description = "Haircut and styling with Lena · 45 min",
groups = [
{
label: "Morning",
slots: [
{ time: "09:00", available: false },
{ time: "09:45" },
{ time: "10:30" },
{ time: "11:15", available: false },
],
},
{
label: "Afternoon",
slots: [{ time: "13:00" }, { time: "13:45" }, { time: "14:30", available: false }, { time: "15:15" }, { time: "16:00" }],
},
],
value = "10:30",
takenLabel = "taken",
required = true,
class: className,
} = Astro.props;
const descId = `${id}-description`;
---
<fieldset id={id} aria-describedby={description ? descId : undefined} class={cn("min-w-0", className)}>
<legend class="text-[0.8125rem]/5 font-medium text-foreground">{legend}</legend>
{description && <p id={descId} class="mt-1 text-[0.8125rem]/5 text-muted-foreground">{description}</p>}
<div class="mt-4 flex flex-col gap-4">
{
groups.map((group, g) => (
<div role="group" aria-labelledby={`${id}-group-${g}`}>
<p id={`${id}-group-${g}`} class="text-xs/4 font-medium text-muted-foreground">
{group.label}
</p>
<div class="mt-2 grid grid-cols-[repeat(auto-fill,minmax(5rem,1fr))] gap-2">
{group.slots.map((slot, s) => {
const v = slot.value ?? slot.time;
const taken = slot.available === false;
const inputId = `${id}-${g}-${s}`;
return (
<label
for={inputId}
class={cn(
"group relative flex h-10 items-center justify-center gap-1 rounded-lg border text-[0.8125rem]/5 font-medium tabular-nums transition-[border-color,background-color,color,scale] duration-150 ease-snappy",
"has-focus-visible:outline-2 has-focus-visible:outline-offset-1 has-focus-visible:outline-ring",
taken
? "cursor-not-allowed border-dashed border-border text-muted-foreground/60 line-through"
: "cursor-pointer border-frame bg-field text-foreground hover:border-frame-strong hover:bg-accent active:scale-[0.97] active:duration-100 motion-reduce:active:scale-100 has-checked:border-foreground has-checked:bg-accent has-checked:text-foreground",
)}
>
<input
type="radio"
id={inputId}
name={name}
value={v}
checked={!taken && v === value}
disabled={taken}
required={required}
class="sr-only"
/>
<Check aria-hidden="true" class="hidden size-3.5 group-has-checked:block" />
{slot.time}
{taken && <span class="sr-only">, {takenLabel}</span>}
</label>
);
})}
</div>
</div>
))
}
</div>
</fieldset>When to use
- A customer books an appointment, a table or a call for a chosen day
- Availability comes in fixed slots of known length
When not to use
- Any time can be typed in freely. Use time-picker.
- The customer first has to choose the day. Put calendar above this picker.
Installation
Add the Haze registry to components.json once, then install Time slot picker with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/time-slot-pickernpx shadcn@latest add @haze/time-slot-pickeryarn dlx shadcn@latest add @haze/time-slot-pickerbunx --bun shadcn@latest add @haze/time-slot-pickerFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Base for every radio id and the description id. |
| name | string | id | Form field name of the radios. |
| legend | string | "Tuesday, 25 November" | Visible question, usually the day. |
| description | string | – | Helper line: service, staff member, duration. |
| groups | { label: string; slots: { time: string; value?: string; available?: boolean }[] }[] | – | Parts of the day with their slots. |
| value | string | "10:30" | Value checked on load. |
| takenLabel | string | "taken" | Word read after a disabled slot. |
| required | boolean | true | Makes choosing a slot required. |
| class | string | – | Additional classes on the fieldset. |
Keyboard interactions
- Tab
- Move into the slots.
- Arrow keys
- Choose the next or previous free slot.
Accessibility
- Slots are native radios in a fieldset, so arrow keys move between them and the form submits the chosen time.
- A taken slot is disabled, struck through and read as taken; the chosen slot gets a check mark as well as a color.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Time slot picker" with `npx shadcn@latest add @haze/time-slot-picker`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import TimeSlotPicker from "@/components/haze/ui/time-slot-picker.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/time-slot-picker.md
Customize with real content
Adapt the Haze time-slot-picker ui for our product. Replace the demo values of these props with our real content: id, name, legend, description, groups, value, takenLabel, required, class. Keep the layout, the heading level rules and these accessibility details: Slots are native radios in a fieldset, so arrow keys move between them and the form submits the chosen time. A taken slot is disabled, struck through and read as taken; the chosen slot gets a check mark as well as a color. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using time-slot-picker, check it fits: use it when a customer books an appointment, a table or a call for a chosen day; availability comes in fixed slots of known length. Avoid it when any time can be typed in freely. use time-picker.; the customer first has to choose the day. put calendar above this picker.. Alternatives: @haze/time-picker, @haze/calendar, @haze/choice-card.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.