{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "select",
  "title": "Select",
  "description": "Single select: field-frame trigger with a caret cell; the list docks to the frame. Options form (with groups) or parts named as Base UI names them (SelectRoot, SelectTrigger, SelectValue, SelectPopup, SelectItem, SelectGroup, SelectSeparator …).",
  "dependencies": [
    "@base-ui/react@1.9.0"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/keyline-scope",
    "@keyline-ui/options",
    "@keyline-ui/field",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/select.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Select as SelectPrimitive } from \"@base-ui/react/select\";\nimport { Field as FieldPrimitive } from \"@base-ui/react/field\";\n\nimport { cn } from \"@/lib/utils\";\nimport { dockGeometry, scopeProps, useKeylineScope } from \"../lib/keyline-scope\";\nimport { resolveClassName, resolveStyle } from \"../lib/keyline-render\";\nimport { groupBy, hasGroups } from \"../lib/options\";\nimport { FieldMessages, type FieldParticipantProps } from \"./field\";\n\n/*\n * Select, as parts named as Base UI names them, and `Select`, the field built from them (a label, options, the\n * field's messages). The trigger is a field frame of cells:\n *\n *   ┌────────────────────────────────┬────┐\n *   │ Standard                       │ ⌄  │   value cell (truncates on one line) · caret cell (inverse while open)\n *   └────────────────────────────────┴────┘\n *\n * The list docks to the frame (dock geometry, owner weight on the shared edge, no cut). Two cues never confused:\n * the chosen option carries the exclusive-choice mark (RadioGroup's square-and-dot), the cursor is the inverse row.\n */\n\ntype Layout = \"control\" | \"cell\";\n\ntype Option = {\n  value: string;\n  label: React.ReactNode;\n  description?: React.ReactNode;\n  code?: React.ReactNode;\n  /** Options sharing a group are listed under one heading, in first-appearance order. */\n  group?: string;\n  disabled?: boolean;\n};\n\n/* ------------------------------------------------------------------ parts */\n\n/** Base UI's Select.Root: state, typeahead, the form value. Generic over the value and `multiple`. */\nconst SelectRoot = SelectPrimitive.Root;\n\n/** The field's label. Inside `layout=\"cell\"` hide it (`className=\"kl-sr\"`); the trigger keeps the name. */\nfunction SelectLabel({ className, ...props }: SelectPrimitive.Label.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.Label\n      className={resolveClassName(\"kl-field-label\", className)}\n      {...props}\n      data-slot=\"select-label\"\n    />\n  );\n}\n\nconst Caret = () => (\n  <svg\n    viewBox=\"0 0 16 16\"\n    width=\"16\"\n    height=\"16\"\n    fill=\"none\"\n    stroke=\"currentColor\"\n    strokeWidth=\"1.75\"\n    strokeLinecap=\"square\"\n    aria-hidden\n  >\n    <path d=\"m4 6 4 4 4-4\" />\n  </svg>\n);\n\n/**\n * The trigger: a field frame of cells. It holds the attention cell a Field inserts when invalid, then its children\n * (by default the value and the caret). Its own edge takes keyboard focus; open is the inverse caret cell, never a\n * ring. `layout=\"cell\"`: it fills a cell of an enclosing frame instead of drawing its own.\n */\nfunction SelectTrigger({\n  layout = \"control\",\n  className,\n  children,\n  ...props\n}: SelectPrimitive.Trigger.Props & { layout?: Layout }): React.ReactElement {\n  return (\n    <SelectPrimitive.Trigger\n      data-kl-layout={layout}\n      className={resolveClassName(\n        cn(\n          \"kl-ctl kl-cells kl-field-frame kl-edge group/select-trigger w-full cursor-pointer p-0 text-start\",\n          \"font-(family-name:--kl-font) text-inherit\",\n          // disabled: out of service\n          \"data-disabled:cursor-not-allowed data-disabled:border-kl-dis-line data-disabled:bg-(image:--kl-hatch)\",\n          \"data-disabled:text-kl-dis\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"select-trigger\"\n    >\n      {/* the attention cell a Field inserts when invalid (Select is a Field participant) */}\n      <span className=\"kl-slot kl-field-bang\" aria-hidden>\n        <span>\n          <span>!</span>\n        </span>\n      </span>\n      {children ?? (\n        <>\n          <SelectValue />\n          <SelectIcon />\n        </>\n      )}\n    </SelectPrimitive.Trigger>\n  );\n}\n\n/**\n * The value cell. A block, not a flex box: text-overflow applies only to a block's own line, so on a flex box the\n * ellipsis never appeared and a long value pushed the caret cell. It is centred, not stretched, so the seam a Field\n * draws after the attention cell would be a text-high red stub: the ! cell's red fill is already the edge there, and\n * the value draws no start border (`border-s-0` outranks the Field's cell rule).\n */\nfunction SelectValue({ className, ...props }: SelectPrimitive.Value.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.Value\n      className={resolveClassName(\n        cn(\n          \"block min-w-0 flex-[1_1_0] self-center truncate border-s-0 px-(--kl-inset)\",\n          \"text-(length:--kl-text-lead)/[1.3] data-placeholder:text-kl-ink-3\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"select-value\"\n    />\n  );\n}\n\n/** The caret cell: inverse while the list is open. */\nfunction SelectIcon({ className, children, ...props }: SelectPrimitive.Icon.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.Icon\n      className={resolveClassName(\n        cn(\n          \"grid w-9 flex-none place-items-center self-stretch\",\n          \"group-data-popup-open/select-trigger:bg-kl-inverse group-data-popup-open/select-trigger:text-kl-on-inverse\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"select-icon\"\n    >\n      {children ?? <Caret />}\n    </SelectPrimitive.Icon>\n  );\n}\n\ntype PopupProps = SelectPrimitive.Popup.Props &\n  Pick<\n    SelectPrimitive.Positioner.Props,\n    \"anchor\" | \"side\" | \"align\" | \"sideOffset\" | \"alignOffset\" | \"collisionPadding\" | \"alignItemWithTrigger\"\n  > & {\n    /** The frame the list docks to: `cell` when the trigger has `layout=\"cell\"`. */\n    layout?: Layout;\n    /** Where the portal renders (defaults to <body>). */\n    container?: SelectPrimitive.Portal.Props[\"container\"];\n    /** Props for Base UI's Select.Portal. */\n    portalProps?: Omit<SelectPrimitive.Portal.Props, \"container\" | \"children\">;\n  };\n\n/**\n * The list's surface: Base UI's Portal, Positioner and Popup in one part, with the positioner's placement props\n * lifted. It docks to the frame (its shared edge on the frame's keyline, no cut), unfolds from that edge, is at least\n * the owner's width (15rem only when the owner is clearly narrower), and carries the configuration (cut, density,\n * motion, theme, dir) of the place it is written. Rows are separated by soft rules.\n */\nfunction SelectPopup({\n  layout = \"control\",\n  anchor,\n  side,\n  align = \"start\",\n  sideOffset,\n  alignOffset,\n  collisionPadding = 12,\n  alignItemWithTrigger = false,\n  container,\n  portalProps,\n  className,\n  style,\n  ...props\n}: PopupProps): React.ReactElement {\n  const dock = dockGeometry(layout);\n  const [marker, scope, probe] = useKeylineScope(false, container);\n  return (\n    <>\n      {marker}\n      <SelectPrimitive.Portal container={container} {...portalProps}>\n        <SelectPrimitive.Positioner\n          anchor={anchor}\n          side={side}\n          align={align}\n          sideOffset={sideOffset ?? dock.sideOffset}\n          alignOffset={alignOffset ?? dock.alignOffset}\n          collisionPadding={collisionPadding}\n          alignItemWithTrigger={alignItemWithTrigger}\n          {...scopeProps(scope, { className: \"kl-positioner\" })}\n          // Base UI keeps a select's popup mounted once it has opened, so a probe beside it would read the scope\n          // only the first time. Rendered here, a fresh probe runs on every render of the positioner, which\n          // includes each open: a configuration changed while the list was closed reaches it when it reopens.\n          render={(positionerProps) => (\n            <div {...positionerProps}>\n              {React.cloneElement(probe)}\n              {positionerProps.children}\n            </div>\n          )}\n        >\n          <SelectPrimitive.Popup\n            className={resolveClassName(\n              cn(\n                \"kl-attached kl-dock kl-dock-min [--kl-dock-w:15rem]\",\n                \"max-h-[min(var(--available-height),360px)] scroll-py-1 overflow-auto overscroll-contain\",\n                \"bg-kl-cell text-kl-ink outline-0\",\n                \"[&_[data-slot=select-item]+[data-slot=select-item]]:border-t-(length:--kl-k1)\",\n                \"[&_[data-slot=select-item]+[data-slot=select-item]]:border-t-kl-line-soft\",\n              ),\n              className,\n            )}\n            style={resolveStyle(dock.style, style)}\n            {...props}\n            data-slot=\"select-popup\"\n          />\n        </SelectPrimitive.Positioner>\n      </SelectPrimitive.Portal>\n    </>\n  );\n}\n\n/** The options' container inside the popup. */\nfunction SelectList({ className, ...props }: SelectPrimitive.List.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.List className={resolveClassName(\"outline-0\", className)} {...props} data-slot=\"select-list\" />\n  );\n}\n\n/** The chosen option's mark: the exclusive-choice square and dot, drawn with borders so it survives forced colours.\n * Unchosen rows keep the cell empty. */\nfunction SelectItemIndicator({\n  className,\n  children,\n  keepMounted = true,\n  ...props\n}: SelectPrimitive.ItemIndicator.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.ItemIndicator\n      keepMounted={keepMounted}\n      className={resolveClassName(\n        \"grid size-4 place-items-center border-2 border-current not-data-selected:invisible\",\n        className,\n      )}\n      {...props}\n      data-slot=\"select-item-indicator\"\n    >\n      {/* Base UI renders a \"✔️\" glyph when the indicator has no children; ours is the mark itself */}\n      {children ?? <span className=\"size-1.5 bg-current\" />}\n    </SelectPrimitive.ItemIndicator>\n  );\n}\n\n/** The option's text: what the trigger shows once it is chosen. */\nfunction SelectItemText({ className, ...props }: SelectPrimitive.ItemText.Props): React.ReactElement {\n  return <SelectPrimitive.ItemText className={className} {...props} data-slot=\"select-item-text\" />;\n}\n\ntype ItemProps = SelectPrimitive.Item.Props & {\n  description?: React.ReactNode;\n  /** Trailing code cell: ≤ 4 mono characters (an ID, a key). */\n  code?: React.ReactNode;\n};\n\n/**\n * One option: the mark cell, the label (wraps; the full text is always readable here) with an optional\n * description, and an optional trailing code cell that never squeezes. The cursor is the inverse row. Disabled\n * options stay reachable (they can be read) but can't be chosen.\n */\nfunction SelectItem({ className, description, code, children, ...props }: ItemProps): React.ReactElement {\n  return (\n    <SelectPrimitive.Item\n      className={resolveClassName(\n        cn(\n          \"group/select-item grid min-h-(--kl-row) cursor-default grid-cols-[36px_minmax(0,1fr)_auto] items-stretch\",\n          \"outline-0 select-none\",\n          \"data-highlighted:bg-kl-inverse data-highlighted:text-kl-on-inverse\",\n          \"data-disabled:cursor-not-allowed data-disabled:bg-(image:--kl-hatch) data-disabled:text-kl-dis\",\n          \"forced-colors:data-highlighted:outline-3 forced-colors:data-highlighted:outline-offset-[-4px]\",\n          \"forced-colors:data-highlighted:outline-[Highlight]\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"select-item\"\n    >\n      <span\n        className=\"grid place-items-center border-e-(length:--kl-k1) border-e-kl-seam group-data-highlighted/select-item:border-e-kl-on-inverse\"\n        aria-hidden\n      >\n        <SelectItemIndicator />\n      </span>\n      <span\n        data-slot=\"select-item-label\"\n        className=\"grid min-w-0 content-center gap-px px-(--kl-inset) py-2 leading-[1.3] wrap-anywhere\"\n      >\n        <SelectItemText>{children}</SelectItemText>\n        {description ? (\n          <small\n            className={cn(\"text-(length:--kl-text-meta) text-kl-ink-2 group-data-highlighted/select-item:text-inherit\")}\n          >\n            {description}\n          </small>\n        ) : null}\n      </span>\n      {code != null ? (\n        <span\n          data-slot=\"select-item-code\"\n          className=\"kl-code flex items-center px-(--kl-inset) whitespace-nowrap group-data-highlighted/select-item:text-inherit\"\n        >\n          {code}\n        </span>\n      ) : null}\n    </SelectPrimitive.Item>\n  );\n}\n\n/** A run of options under one heading. A group after a group is divided by a seam. */\nfunction SelectGroup({ className, ...props }: SelectPrimitive.Group.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.Group\n      className={resolveClassName(\n        \"[[data-slot=select-group]+&]:border-t-(length:--kl-k1) [[data-slot=select-group]+&]:border-t-kl-seam\",\n        className,\n      )}\n      {...props}\n      data-slot=\"select-group\"\n    />\n  );\n}\n\n/** A group's heading, in the Code voice; the group's first option sits on its seam. */\nfunction SelectGroupLabel({ className, ...props }: SelectPrimitive.GroupLabel.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.GroupLabel\n      className={resolveClassName(\n        cn(\n          \"block cursor-default px-(--kl-inset) pt-2.5 pb-1 text-kl-ink-2 not-italic normal-nums\",\n          \"font-(family-name:--kl-font-mono) text-(length:--kl-text-code)/[1.2] font-medium\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"select-group-label\"\n    />\n  );\n}\n\n/** A seam between options; the option after it draws no second rule. */\nfunction SelectSeparator({ className, ...props }: SelectPrimitive.Separator.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.Separator\n      className={resolveClassName(\"h-0 border-t-(length:--kl-k1) border-t-kl-seam\", className)}\n      {...props}\n      data-slot=\"select-separator\"\n    />\n  );\n}\n\nconst arrow = cn(\n  \"sticky z-1 flex h-6 cursor-default items-center justify-center bg-kl-cell text-kl-ink-2\",\n  \"data-[direction=up]:top-0 data-[direction=up]:border-b-(length:--kl-k1) data-[direction=up]:border-b-kl-seam\",\n  \"data-[direction=down]:bottom-0 data-[direction=down]:border-t-(length:--kl-k1) data-[direction=down]:border-t-kl-seam\",\n);\n\n/** Scrolls the list up while the pointer rests on it; shown only while there is more above. */\nfunction SelectScrollUpArrow({\n  className,\n  children,\n  ...props\n}: SelectPrimitive.ScrollUpArrow.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.ScrollUpArrow\n      className={resolveClassName(arrow, className)}\n      {...props}\n      data-slot=\"select-scroll-up-arrow\"\n    >\n      {children ?? (\n        <span className=\"grid rotate-180\">\n          <Caret />\n        </span>\n      )}\n    </SelectPrimitive.ScrollUpArrow>\n  );\n}\n\n/** Scrolls the list down while the pointer rests on it; shown only while there is more below. */\nfunction SelectScrollDownArrow({\n  className,\n  children,\n  ...props\n}: SelectPrimitive.ScrollDownArrow.Props): React.ReactElement {\n  return (\n    <SelectPrimitive.ScrollDownArrow\n      className={resolveClassName(arrow, className)}\n      {...props}\n      data-slot=\"select-scroll-down-arrow\"\n    >\n      {children ?? <Caret />}\n    </SelectPrimitive.ScrollDownArrow>\n  );\n}\n\n/* ------------------------------------------------------------------ the field */\n\ntype SelectProps<V extends string> = Omit<SelectPrimitive.Root.Props<V>, \"children\" | \"items\"> & {\n  label: React.ReactNode;\n  options: Option[];\n  placeholder?: React.ReactNode;\n  /** control: its own 2px frame. cell: a cell of an enclosing frame (the label is visually hidden). */\n  layout?: Layout;\n  /** Where the list's portal renders (defaults to <body>). */\n  container?: SelectPrimitive.Portal.Props[\"container\"];\n  className?: string;\n} & FieldParticipantProps;\n\nconst renderOption = (o: Option) => (\n  <SelectItem key={o.value} value={o.value} disabled={o.disabled} description={o.description} code={o.code}>\n    {o.label}\n  </SelectItem>\n);\n\n/**\n * Single select from an options list, built from the parts above. Options with a `group` are listed under headings.\n * For custom rows, separators or groups you build yourself, compose the parts instead. The trigger's accessible name\n * always carries the full value; option labels wrap in the list.\n *\n * Behaviour, keyboard, typeahead, form participation (`name`, `required`) and controlled/uncontrolled state are Base\n * UI Select's; `onValueChange` receives Base UI's event details (the reason, the event) after the value. The wrapper\n * is a Base UI Field.Root: a Form collects the value under `name`, and the Form's `errors`, `validate` and `required`\n * produce the message under the frame.\n */\nfunction Select<V extends string>({\n  label,\n  options,\n  placeholder = \"Choose…\",\n  layout = \"control\",\n  container,\n  className,\n  description,\n  error,\n  invalid,\n  validate,\n  validationMode,\n  orientation,\n  ...props\n}: SelectProps<V>) {\n  const items = React.useMemo(() => Object.fromEntries(options.map((o) => [o.value, o.label])), [options]);\n  const groups = React.useMemo(() => (hasGroups(options) ? groupBy(options) : null), [options]);\n  return (\n    <FieldPrimitive.Root\n      data-slot=\"select\"\n      data-kl-layout={layout}\n      data-kl-orientation={orientation}\n      name={props.name}\n      disabled={props.disabled}\n      invalid={invalid}\n      validate={validate}\n      validationMode={validationMode}\n      className={cn(\"kl-field\", className)}\n    >\n      <SelectRoot<V> items={items} {...props}>\n        <SelectLabel className={layout === \"cell\" ? \"kl-sr\" : undefined}>{label}</SelectLabel>\n        <SelectTrigger layout={layout}>\n          <SelectValue placeholder={placeholder} />\n          <SelectIcon />\n        </SelectTrigger>\n        <SelectPopup layout={layout} container={container}>\n          <SelectList>\n            {groups\n              ? groups.map((g) =>\n                  g.group ? (\n                    <SelectGroup key={g.group}>\n                      <SelectGroupLabel>{g.group}</SelectGroupLabel>\n                      {g.items.map(renderOption)}\n                    </SelectGroup>\n                  ) : (\n                    <SelectGroup key=\"\">{g.items.map(renderOption)}</SelectGroup>\n                  ),\n                )\n              : options.map(renderOption)}\n          </SelectList>\n        </SelectPopup>\n        <FieldMessages description={description} error={error} invalid={invalid} layout={layout} />\n      </SelectRoot>\n    </FieldPrimitive.Root>\n  );\n}\n\nexport {\n  Select,\n  SelectRoot,\n  SelectLabel,\n  SelectTrigger,\n  SelectValue,\n  SelectIcon,\n  SelectPopup,\n  SelectList,\n  SelectItem,\n  SelectItemText,\n  SelectItemIndicator,\n  SelectGroup,\n  SelectGroupLabel,\n  SelectSeparator,\n  SelectScrollUpArrow,\n  SelectScrollDownArrow,\n  type Option as SelectOption,\n};\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/select.tsx"
    }
  ],
  "type": "registry:ui"
}