{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-menu",
  "title": "Settings Menu",
  "description": "An icon button that opens a menu of settings: toggles drawn as switches, and choices in submenus showing their value.",
  "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-menu"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/settings-menu.tsx",
      "content": "\"use client\";\n\nimport {\n  type SettingsMenuContentState,\n  type SettingsMenuOptions,\n  type SettingsMenuRow,\n  settingsMenuPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { MenuItemIndicator, MenuTrigger } from \"@ui-sdk/react/menu\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport { type ComponentProps, Fragment, type ReactElement, type ReactNode } from \"react\";\nimport {\n  KindMenu,\n  KindMenuCheckboxItem,\n  KindMenuContent,\n  KindMenuGroup,\n  KindMenuGroupLabel,\n  KindMenuItem,\n  KindMenuItemContent,\n  KindMenuItemIndicator,\n  KindMenuRadioGroup,\n  KindMenuRadioItem,\n  KindMenuSeparator,\n  KindMenuSub,\n  KindMenuSubContent,\n  KindMenuSubTrigger,\n} from \"./internal/menu\";\n\nconst parts = createParts(settingsMenuPrimitive, { root: \"div\", trigger: \"span\", content: \"div\" });\n\ntype Entry = NonNullable<SettingsMenuOptions[\"settings\"]>[number];\ntype Choice = Extract<Entry, { type: \"choice\" }>;\ntype Icon = string | ReactElement;\n\n/** A setting, whose `icon` and options' `icon`s are image URLs or elements such as an inline `svg`. */\nexport type SettingsMenuSetting =\n  | (Extract<Entry, { type: \"toggle\" }> & { icon?: Icon })\n  | (Omit<Choice, \"options\"> & { icon?: Icon; options: (Choice[\"options\"][number] & { icon?: Icon })[] });\n\nexport type SettingsMenuProps = Omit<ComponentProps<typeof parts.Root>, \"children\" | \"settings\"> & {\n  settings?: SettingsMenuSetting[];\n  children?: ReactNode;\n};\n\ntype ChoiceRow = Extract<SettingsMenuRow, { type: \"choice\" }>;\n\n/** A choice's options in one radio group, under their group labels, then its actions. */\nfunction Choices({ row }: { row: ChoiceRow }) {\n  return (\n    <>\n      <KindMenuRadioGroup name={row.id} value={row.value ?? null}>\n        {row.groups.map((group, index) => {\n          const radios = group.options.map((option) => (\n            <KindMenuRadioItem\n              key={option.value}\n              value={option.value}\n              label={option.label}\n              disabled={option.disabled ?? false}\n            >\n              <KindMenuItemIndicator keepMounted>\n                <span data-menu-check=\"\" aria-hidden=\"true\" />\n              </KindMenuItemIndicator>\n              <KindMenuItemContent\n                icon={option.icon}\n                label={option.label}\n                meta={option.meta}\n                metaLabel={option.metaLabel}\n              />\n            </KindMenuRadioItem>\n          ));\n          // A labelled group sits inside the one radio group, which UI SDK keys by the setting's `id`.\n          return group.label === undefined ? (\n            radios\n          ) : (\n            // By position: an inline row's own label can match a host group's.\n            <KindMenuGroup key={index}>\n              <KindMenuGroupLabel>{group.label}</KindMenuGroupLabel>\n              {radios}\n            </KindMenuGroup>\n          );\n        })}\n      </KindMenuRadioGroup>\n      {row.actions.length && !row.inline ? <KindMenuSeparator /> : null}\n      {row.actions.map((action) => (\n        <KindMenuItem\n          key={action.value}\n          value={action.value}\n          label={action.label}\n          data-menu-inset={row.inline ? \"\" : undefined}\n        >\n          <KindMenuItemContent icon={action.icon} label={action.label} />\n        </KindMenuItem>\n      ))}\n      {row.note ? (\n        <>\n          <KindMenuSeparator />\n          {/* Each row's name says its cost in words, so the note is for the eye. */}\n          <span data-menu-note=\"\" aria-hidden=\"true\">\n            {row.note}\n          </span>\n        </>\n      ) : null}\n    </>\n  );\n}\n\nfunction Row({ row }: { row: SettingsMenuRow }) {\n  if (row.type === \"toggle\")\n    return (\n      <KindMenuCheckboxItem value={row.id} label={row.label} checked={row.checked}>\n        <KindMenuItemContent icon={row.icon} label={row.label} description={row.description} />\n        <MenuItemIndicator keepMounted data-menu-switch=\"\" aria-hidden=\"true\">\n          <span data-menu-switch-thumb=\"\" />\n        </MenuItemIndicator>\n      </KindMenuCheckboxItem>\n    );\n  if (row.inline) return <Choices row={row} />;\n  return (\n    <KindMenuSub>\n      <KindMenuSubTrigger>\n        <KindMenuItemContent icon={row.icon} label={row.label} />\n        <span data-settings-menu-value=\"\">\n          {row.options.map((option) => (\n            <span key={option.value} data-current={option.value === row.value ? \"\" : undefined}>\n              {option.label}\n            </span>\n          ))}\n        </span>\n        <span data-menu-chevron=\"\" />\n      </KindMenuSubTrigger>\n      <KindMenuSubContent>\n        <Choices row={row} />\n      </KindMenuSubContent>\n    </KindMenuSub>\n  );\n}\n\nexport type SettingsMenuRowsProps = { rows: SettingsMenuRow[] };\n\n/**\n * The rows: a switch for each toggle, and for each choice a submenu showing its value, or while `inline` a section of\n * the menu, holding its options under their group labels and any actions after them. A separator follows an inline\n * section. Model Control draws its rows with it too.\n */\nexport function SettingsMenuRows({ rows }: SettingsMenuRowsProps) {\n  return rows.map((row, index) => (\n    <Fragment key={row.id}>\n      <Row row={row} />\n      {row.type === \"choice\" && row.inline && index < rows.length - 1 ? <KindMenuSeparator /> : null}\n    </Fragment>\n  ));\n}\n\n/**\n * An icon button named \"Settings\" that opens a menu of settings: toggles drawn as switches, which keep the menu open,\n * and choices, each a submenu of options showing the current one. Any `children` replace the trigger and the content,\n * inside UI SDK Menu.\n */\nexport function SettingsMenu({ children = DEFAULT_PARTS, ...props }: SettingsMenuProps) {\n  return <parts.Root {...props}>{(menu) => <KindMenu {...menu}>{children}</KindMenu>}</parts.Root>;\n}\n\nexport type SettingsMenuTriggerProps = ComponentProps<typeof MenuTrigger>;\n\n/** Opens the menu: UI SDK's `MenuTrigger`, named by the `label`, showing a settings icon unless you pass children. */\nexport function SettingsMenuTrigger({ children = ICON, ...props }: SettingsMenuTriggerProps) {\n  return (\n    <parts.Trigger>\n      {(trigger) => (\n        // Hidden from agents, which use the Settings Menu's own actions.\n        <MenuTrigger {...trigger} data-agent-hidden=\"\" {...props}>\n          {children}\n        </MenuTrigger>\n      )}\n    </parts.Trigger>\n  );\n}\n\nexport type SettingsMenuContentProps = Omit<ComponentProps<typeof KindMenuContent>, \"children\"> & {\n  /** What the menu holds, or a function of its rows: the rows by default. */\n  children?: ReactNode | ((state: SettingsMenuContentState) => ReactNode);\n};\n\n/** The menu: UI SDK's `MenuContent` holding the rows unless you pass children. Props go to it. */\nexport function SettingsMenuContent({ children = DEFAULT_ROWS, ...props }: SettingsMenuContentProps) {\n  return (\n    <parts.Content>\n      {(state) => (\n        <KindMenuContent align=\"start\" sideOffset={6} {...props}>\n          {typeof children === \"function\" ? children(state) : children}\n        </KindMenuContent>\n      )}\n    </parts.Content>\n  );\n}\n\nconst DEFAULT_ROWS = ({ rows }: SettingsMenuContentState) => <SettingsMenuRows rows={rows} />;\n\n// Shared, so an update doesn't render the default parts' wrappers again.\nconst ICON = <span data-menu-trigger-icon=\"\" aria-hidden=\"true\" />;\nconst DEFAULT_PARTS = (\n  <>\n    <SettingsMenuTrigger />\n    <SettingsMenuContent />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/settings-menu.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
