{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slot-picker",
  "type": "registry:ui",
  "title": "Slot Picker",
  "description": "Offered times as a set of pills to choose one from, optionally under named groups, each able to carry a note and to be unavailable for a stated reason.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react",
    "radix-ui"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn"
  ],
  "files": [
    {
      "path": "registry/ui/slot-picker.tsx",
      "type": "registry:ui",
      "target": "components/ui/slot-picker.tsx",
      "content": "\"use client\";\n/**\n * @name slot-picker\n * @category ui\n * @description Offered times as a set of pills to choose one from, optionally under named groups, each able to carry a note and to be unavailable for a stated reason.\n * @when The times are a short list that someone else decides: appointment slots, sittings, departures. One is chosen, so it is a radio group. For any time of the person's own choosing use time-picker; for more than about twenty slots, narrow them first (by day, by part of the day) or use select.\n * @example\n * <SlotPicker defaultValue=\"10:00\" aria-label=\"Time\" locale=\"en-GB\">\n *   <SlotPickerGroup label=\"Morning\">\n *     <SlotPickerItem value=\"09:30\" />\n *     <SlotPickerItem value=\"10:00\" note=\"2 places left\" />\n *     <SlotPickerItem value=\"11:30\" unavailable=\"Full\" />\n *   </SlotPickerGroup>\n *   <SlotPickerGroup label=\"Afternoon\">\n *     <SlotPickerItem value=\"14:00\" />\n *   </SlotPickerGroup>\n * </SlotPicker>\n *\n * // Controlled, with its own labels, and nothing on offer\n * <SlotPicker value={slot} onValueChange={setSlot} aria-label=\"Sitting\">\n *   {sittings.length === 0 ? <SlotPickerEmpty>Nothing is open on this day.</SlotPickerEmpty> : null}\n *   {sittings.map((sitting) => <SlotPickerItem key={sitting.id} value={sitting.id}>{sitting.name}</SlotPickerItem>)}\n * </SlotPicker>\n */\nimport { RadioGroup as RadioGroupPrimitive } from \"radix-ui\";\nimport { Check } from \"lucide-react\";\nimport { createContext, use, useId, useMemo, type ComponentProps, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/cn\";\n\nconst SlotPickerContext = createContext<{ format: (value: string) => string }>({ format: (value) => value });\n\nexport type SlotPickerProps = Omit<ComponentProps<typeof RadioGroupPrimitive.Root>, \"orientation\"> & {\n  /** The language tag used to write a slot whose value is a time (\"14:00\" becomes \"2:00 pm\" where that is the custom). Default \"en\". */\n  locale?: string;\n};\n\n/**\n * A radio group: Tab reaches the chosen slot (or the first), arrow keys move through the slots and choose\n * as they go (Left and Right the other way round in right-to-left pages), and an unavailable slot can be\n * reached, so that its reason is read, but not chosen. `value`, `defaultValue` and `onValueChange` control\n * it; `name` submits it with a form. Name the group with `aria-label` or `aria-labelledby`.\n */\nexport function SlotPicker({ className, locale = \"en\", ...props }: SlotPickerProps) {\n  const format = useMemo(() => {\n    const formatter = new Intl.DateTimeFormat(locale, { timeStyle: \"short\", timeZone: \"UTC\" });\n    return (value: string): string => {\n      const time = /^([01]\\d|2[0-3]):([0-5]\\d)$/.exec(value);\n      return time ? formatter.format(Date.UTC(1970, 0, 1, Number(time[1]), Number(time[2]))) : value;\n    };\n  }, [locale]);\n  return (\n    <SlotPickerContext value={{ format }}>\n      <RadioGroupPrimitive.Root data-slot=\"slot-picker\" className={cn(\"flex max-w-full flex-col gap-4\", className)} {...props} />\n    </SlotPickerContext>\n  );\n}\n\nexport type SlotPickerGroupProps = Omit<ComponentProps<\"div\">, \"label\"> & {\n  /** The group's name (\"Morning\"). Leave it out for one unnamed set of slots. */\n  label?: ReactNode;\n};\n\n/** A set of slots that wraps onto more lines, under a name when one is given. Slots outside any group need one too, for the layout. */\nexport function SlotPickerGroup({ className, label, children, ...props }: SlotPickerGroupProps) {\n  const id = useId();\n  return (\n    <div data-slot=\"slot-picker-group\" role={label ? \"group\" : undefined} aria-labelledby={label ? id : undefined} className={cn(\"flex flex-col gap-2\", className)} {...props}>\n      {label ? (\n        <div id={id} data-slot=\"slot-picker-group-label\" className=\"text-sm font-medium text-muted-foreground\">\n          {label}\n        </div>\n      ) : null}\n      <div className=\"flex flex-wrap gap-2\">{children}</div>\n    </div>\n  );\n}\n\nexport type SlotPickerItemProps = Omit<ComponentProps<typeof RadioGroupPrimitive.Item>, \"disabled\"> & {\n  /** A few words under the time: places left, a price. */\n  note?: ReactNode;\n  /** Makes the slot impossible to choose. Pass the reason (\"Full\"): it is shown and read. */\n  unavailable?: boolean | string;\n};\n\n/**\n * One slot. Its text is its children, or its value written as a time for the locale when the value is\n * \"HH:mm\". The chosen slot has a tick and a stronger edge as well as its ground; an unavailable one is\n * struck through and says why.\n */\nexport function SlotPickerItem({ className, value, children, note, unavailable = false, onClick, ...props }: SlotPickerItemProps) {\n  const { format } = use(SlotPickerContext);\n  const blocked = unavailable !== false;\n  return (\n    <RadioGroupPrimitive.Item\n      data-slot=\"slot-picker-item\"\n      data-unavailable={blocked ? \"\" : undefined}\n      value={value}\n      aria-disabled={blocked || undefined}\n      onClick={(event) => {\n        onClick?.(event);\n        // Stops the choice (also when an arrow key lands here) while leaving the slot focusable.\n        if (blocked) event.preventDefault();\n      }}\n      className={cn(\n        \"group/slot relative inline-flex min-h-(--control-h) min-w-20 flex-col items-center justify-center rounded-control border border-input bg-background px-3 py-1 text-sm text-foreground transition-[background-color,border-color,color,scale] duration-instant ease-out select-none hover:bg-accent active:scale-[0.98] motion-reduce:transition-none motion-reduce:active:scale-100\",\n        \"data-[state=checked]:border-primary data-[state=checked]:bg-highlight-soft data-[state=checked]:hover:bg-highlight-soft\",\n        \"data-unavailable:cursor-not-allowed data-unavailable:border-border data-unavailable:bg-muted data-unavailable:hover:bg-muted data-unavailable:active:scale-100\",\n        className,\n      )}\n      {...props}\n    >\n      <span className=\"inline-flex items-center gap-1.5 font-medium tabular-nums group-data-unavailable/slot:line-through\">\n        <Check aria-hidden=\"true\" strokeWidth={2} className=\"hidden size-3.5 shrink-0 group-data-[state=checked]/slot:block\" />\n        {/* Isolated, so a time keeps its own order inside text of the other direction. */}\n        {children ?? <bdi>{format(value)}</bdi>}\n      </span>\n      {note || typeof unavailable === \"string\" ? (\n        <span data-slot=\"slot-picker-note\" className=\"text-xs text-muted-foreground\">\n          {typeof unavailable === \"string\" ? unavailable : note}\n        </span>\n      ) : null}\n    </RadioGroupPrimitive.Item>\n  );\n}\n\n/** What to say when there is nothing to choose from. */\nexport function SlotPickerEmpty({ className, ...props }: ComponentProps<\"p\">) {\n  return <p data-slot=\"slot-picker-empty\" className={cn(\"text-sm text-muted-foreground\", className)} {...props} />;\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "The times are a short list that someone else decides: appointment slots, sittings, departures. One is chosen, so it is a radio group. For any time of the person's own choosing use time-picker; for more than about twenty slots, narrow them first (by day, by part of the day) or use select.",
    "example": "<SlotPicker defaultValue=\"10:00\" aria-label=\"Time\" locale=\"en-GB\">\n  <SlotPickerGroup label=\"Morning\">\n    <SlotPickerItem value=\"09:30\" />\n    <SlotPickerItem value=\"10:00\" note=\"2 places left\" />\n    <SlotPickerItem value=\"11:30\" unavailable=\"Full\" />\n  </SlotPickerGroup>\n  <SlotPickerGroup label=\"Afternoon\">\n    <SlotPickerItem value=\"14:00\" />\n  </SlotPickerGroup>\n</SlotPicker>\n\n// Controlled, with its own labels, and nothing on offer\n<SlotPicker value={slot} onValueChange={setSlot} aria-label=\"Sitting\">\n  {sittings.length === 0 ? <SlotPickerEmpty>Nothing is open on this day.</SlotPickerEmpty> : null}\n  {sittings.map((sitting) => <SlotPickerItem key={sitting.id} value={sitting.id}>{sitting.name}</SlotPickerItem>)}\n</SlotPicker>",
    "client": true
  }
}
