# 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.

- Kind: ui · Category: Forms · Interactivity: native
- Install: `npx shadcn@latest add @haze/time-slot-picker`
- File: `src/components/haze/ui/time-slot-picker.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/time-slot-picker

## Use when
- A customer books an appointment, a table or a call for a chosen day
- Availability comes in fixed slots of known length

## Avoid 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
- [time-picker](https://hazeui.com/ui/time-picker.md)
- [calendar](https://hazeui.com/ui/calendar.md)
- [choice-card](https://hazeui.com/ui/choice-card.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Base for every radio id and the description id. |
| name | `string` | id | no | Form field name of the radios. |
| legend | `string` | "Tuesday, 25 November" | no | Visible question, usually the day. |
| description | `string` |  | no | Helper line: service, staff member, duration. |
| groups | `{ label: string; slots: { time: string; value?: string; available?: boolean }[] }[]` |  | no | Parts of the day with their slots. |
| value | `string` | "10:30" | no | Value checked on load. |
| takenLabel | `string` | "taken" | no | Word read after a disabled slot. |
| required | `boolean` | true | no | Makes choosing a slot required. |
| class | `string` |  | no | Additional classes on the fieldset. |

## 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.
- Key Tab: Move into the slots.
- Key Arrow keys: Choose the next or previous free slot.

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Add a slot picker for Tuesday with morning and afternoon times, two of them already booked.

## Source

```astro
---
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>
```
