{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "picker",
  "title": "Picker",
  "description": "A button that opens a searchable list of choices, with groups, two-line rows, pages and footer actions.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/internal-command"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/picker.tsx",
      "content": "\"use client\";\n\nimport {\n  type PickerCommandState,\n  type PickerOptions,\n  type PickerRow,\n  type PickerSection,\n  pickerPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts, renderElement } from \"@ui-sdk/react/primitive\";\nimport { type ComponentProps, Fragment, type ReactElement, type ReactNode } from \"react\";\nimport {\n  KindCommand,\n  KindCommandEmpty,\n  KindCommandGroup,\n  KindCommandGroupLabel,\n  KindCommandInput,\n  KindCommandItem,\n  KindCommandItemIcon,\n  KindCommandItemText,\n  KindCommandList,\n  KindCommandPage,\n  KindCommandSeparator,\n  KindCommandStatus,\n} from \"./internal/command\";\n\nconst parts = createParts(pickerPrimitive, {\n  root: \"div\",\n  trigger: \"button\",\n  content: \"div\",\n  viewport: \"div\",\n  command: \"div\",\n  item: \"span\",\n  note: \"p\",\n});\n\n/** An item, whose `icon` is an image URL or an element such as an inline `svg`. */\nexport type PickerChoice = Omit<NonNullable<PickerOptions[\"items\"]>[number], \"icon\" | \"items\"> & {\n  icon?: string | ReactElement;\n  items?: PickerChoice[];\n};\n\n/** A footer action, whose `icon` is an image URL or an element. */\nexport type PickerFooterAction = Omit<NonNullable<PickerOptions[\"actions\"]>[number], \"icon\"> & {\n  icon?: string | ReactElement;\n};\n\nconst iconOf = (icon: unknown) =>\n  typeof icon === \"string\" ? <img src={icon} alt=\"\" /> : (icon as ReactElement | undefined);\n\nexport type PickerProps = Omit<ComponentProps<typeof parts.Root>, \"children\" | \"items\" | \"actions\"> & {\n  items?: PickerChoice[];\n  actions?: PickerFooterAction[];\n  children?: ReactNode;\n};\n\nexport type PickerTriggerProps = ComponentProps<typeof parts.Trigger>;\nexport type PickerContentProps = ComponentProps<typeof parts.Content>;\nexport type PickerListProps = Omit<ComponentProps<typeof parts.Command>, \"children\"> & {\n  /** What sits in the list, from the rows: every page by default. */\n  children?: (state: PickerCommandState) => ReactNode;\n};\nexport type PickerSectionRowsProps = {\n  section: PickerSection;\n  /** Whether a separator comes before it, as before the footer. */\n  separated?: boolean;\n  /** Renders each row: a `PickerRowItem` by default. */\n  children?: (row: PickerRow) => ReactNode;\n};\nexport type PickerRowItemProps = Omit<ComponentProps<typeof KindCommandItem>, keyof PickerRow[\"option\"]> & {\n  row: PickerRow;\n  /** The row's content: a `PickerItem` by default. */\n  children?: ReactNode;\n};\nexport type PickerItemProps = ComponentProps<typeof parts.Item>;\n\n/** The parts a picker renders through: Picker's, or those of a component that spreads `pickerBase`. */\nexport type PickerParts = Pick<\n  typeof parts,\n  \"Trigger\" | \"Content\" | \"Viewport\" | \"Command\" | \"Item\" | \"Note\"\n>;\n\n/**\n * The trigger, popover, list and rows of a picker, rendered through `parts`, for Model Selector and the other\n * components that spread `pickerBase` to share Picker's markup, each part named `<name><Part>` in React's tools.\n * `Default` is the trigger and the popover. `icon` draws a row's icon (an image URL or an element by default; `null`\n * draws none), and `trailing` what follows its `meta`.\n */\nexport function pickerParts(\n  parts: PickerParts,\n  name: string,\n  {\n    icon = (row: PickerRow) => iconOf(row.icon),\n    trailing,\n  }: { icon?: (row: PickerRow) => ReactNode; trailing?: (row: PickerRow) => ReactNode } = {},\n) {\n  function Trigger({\n    children = ({ text, icon }) => (\n      <>\n        {icon !== undefined ? <span data-picker-icon=\"\">{iconOf(icon)}</span> : null}\n        <span data-picker-text=\"\">{text}</span>\n        <span data-picker-chevron=\"\" />\n      </>\n    ),\n    ...props\n  }: PickerTriggerProps) {\n    return <parts.Trigger {...props}>{children}</parts.Trigger>;\n  }\n\n  function Content({ children = DEFAULT_LIST, render, ...props }: PickerContentProps) {\n    return (\n      <parts.Content\n        initialFocus=\"input\"\n        sideOffset={6}\n        align=\"start\"\n        {...props}\n        // A sheet sits in a full-screen viewport, which renders only while the content presents as one.\n        render={(content, state) => {\n          const element = renderElement(\"div\", content, render, state);\n          return state.presentation === \"sheet\" ? <parts.Viewport>{element}</parts.Viewport> : element;\n        }}\n      >\n        {children}\n      </parts.Content>\n    );\n  }\n\n  function List({ children = DEFAULT_ROWS, ...props }: PickerListProps) {\n    return (\n      <parts.Command {...props}>\n        {(state) => (\n          <KindCommand {...state.props}>\n            <KindCommandInput aria-label={state.label} placeholder={state.placeholder} data-agent-hidden=\"\" />\n            {state.statusText !== undefined ? (\n              <KindCommandStatus>{state.statusText}</KindCommandStatus>\n            ) : null}\n            <KindCommandEmpty>{state.emptyText}</KindCommandEmpty>\n            <KindCommandList>{children(state)}</KindCommandList>\n          </KindCommand>\n        )}\n      </parts.Command>\n    );\n  }\n\n  const DEFAULT_ROWS = ({ pages }: PickerCommandState) =>\n    pages.map(({ page, sections }) => (\n      <KindCommandPage key={page ?? \"\"} value={page}>\n        {sections.map((section, index) => (\n          <SectionRows\n            key={section.footer ? \"\\u0000footer\" : (section.label ?? \"\")}\n            section={section}\n            separated={section.footer && index > 0}\n          />\n        ))}\n      </KindCommandPage>\n    ));\n\n  function SectionRows({\n    section,\n    separated = false,\n    children = (row) => <RowItem row={row} />,\n  }: PickerSectionRowsProps) {\n    return (\n      <>\n        {separated ? <KindCommandSeparator /> : null}\n        <KindCommandGroup>\n          {section.label ? <KindCommandGroupLabel>{section.label}</KindCommandGroupLabel> : null}\n          {section.rows.map((row) => (\n            // Keyed by its label too: React Command filters a row by the label it mounted with, and a footer row's\n            // label can hold the search.\n            <Fragment key={`${row.option.value}\\u0000${row.option.label}`}>{children(row)}</Fragment>\n          ))}\n        </KindCommandGroup>\n      </>\n    );\n  }\n\n  function RowItem({ row, children, ...props }: PickerRowItemProps) {\n    return (\n      <KindCommandItem {...props} {...row.option}>\n        {children ?? <Item value={row.option.value} />}\n      </KindCommandItem>\n    );\n  }\n\n  function Item({\n    children = ({ row, description }) => (\n      <>\n        {iconOfRow(row)}\n        <span data-picker-item-text=\"\">\n          <KindCommandItemText>{row.label}</KindCommandItemText>\n          {description.length ? (\n            <span data-picker-description=\"\">\n              {description.map((segment, index) =>\n                segment.match ? <mark key={index}>{segment.text}</mark> : segment.text,\n              )}\n            </span>\n          ) : null}\n        </span>\n        {row.meta ? (\n          <span data-picker-meta=\"\" aria-hidden={row.metaLabel ? \"true\" : undefined}>\n            {row.meta}\n          </span>\n        ) : null}\n        {row.meta && row.metaLabel ? <span data-picker-meta-label=\"\">{row.metaLabel}</span> : null}\n        {trailing?.(row)}\n        <span data-picker-mark=\"\" />\n      </>\n    ),\n    ...props\n  }: PickerItemProps) {\n    return <parts.Item {...props}>{children}</parts.Item>;\n  }\n\n  const iconOfRow = (row: PickerRow) => {\n    const drawn = row.icon === undefined ? null : icon(row);\n    return drawn == null ? null : <KindCommandItemIcon>{drawn}</KindCommandItemIcon>;\n  };\n\n  /** A line under the list, like what a model's cost means. Rendered only with one. */\n  function Note({ children = ({ note }) => note, ...props }: ComponentProps<typeof parts.Note>) {\n    return <parts.Note {...props}>{children}</parts.Note>;\n  }\n\n  // Shared, so an update doesn't render the default parts' wrappers again.\n  const DEFAULT_LIST = (\n    <>\n      <List />\n      <Note />\n    </>\n  );\n  const Default = (\n    <>\n      <Trigger />\n      <Content />\n    </>\n  );\n\n  const named = { Trigger, Content, List, SectionRows, RowItem, Item, Note };\n  for (const [part, component] of Object.entries(named))\n    (component as { displayName?: string }).displayName = `${name}${part}`;\n  return { ...named, Default };\n}\n\nconst picker = pickerParts(parts, \"Picker\");\n\n/**\n * A button that shows the chosen item and opens a searchable list of them, with groups, two-line rows, pages and\n * footer actions. Any `children` replace the trigger and the list.\n */\nexport function Picker({ children = picker.Default, ...props }: PickerProps) {\n  return <parts.Root {...props}>{children}</parts.Root>;\n}\n\n/** Opens the list. Shows the chosen item's icon and label, or the `label` while none is chosen, unless you pass children. */\nexport const PickerTrigger = picker.Trigger;\n/** The popover: the search field and the list, unless you pass children. Focus moves to the search field. */\nexport const PickerContent = picker.Content;\n/** UI SDK Command: the search field, the empty text, and every page of rows unless you pass children. */\nexport const PickerList = picker.List;\n/** A group of rows under its label, or the footer. */\nexport const PickerSectionRows = picker.SectionRows;\n/** A row: UI SDK's `CommandItem` with the row's props, holding its `PickerItem` unless you pass children. */\nexport const PickerRowItem = picker.RowItem;\n/** A row's content: its icon, marked label, description, `meta`, and its check or chevron. */\nexport const PickerItem = picker.Item;\n",
      "type": "registry:ui",
      "target": "@ui/picker.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
