{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "context-bar-solid",
  "title": "Context Bar (Solid)",
  "description": "A row of removable context chips, the ones that don't fit behind a +N button that lists them.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/solid@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/solid/context-bar.tsx",
      "content": "import {\n  CONTEXT_BAR_FIRST_ITEM,\n  type ContextBarChipState,\n  type ContextBarListState,\n  type ContextBarOptions,\n  contextBarPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport type { ComponentProps, JSX } from \"@solidjs/web\";\nimport { createParts } from \"@ui-sdk/solid/primitive\";\nimport { For, omit, Show, untrack } from \"solid-js\";\n\nconst parts = createParts(contextBarPrimitive, {\n  root: \"div\",\n  list: \"ul\",\n  chip: \"li\",\n  remove: \"span\",\n  \"item-remove\": \"span\",\n  overflow: \"button\",\n  content: \"div\",\n  viewport: \"div\",\n  title: \"h2\",\n  \"overflow-list\": \"ul\",\n  item: \"li\",\n});\n\n/**\n * A chip, whose `icon` is an image URL, an element such as an inline `svg`, or a function that returns one. A chip that\n * doesn't fit shows in the bar and in the list of the rest at once, so an element is cloned for each; a function is\n * called for each.\n */\nexport type ContextBarChipData = Omit<NonNullable<ContextBarOptions[\"chips\"]>[number], \"icon\"> & {\n  icon?: string | JSX.Element | (() => JSX.Element);\n};\n\nexport type ContextBarProps = Omit<ComponentProps<typeof parts.Root>, \"chips\"> & {\n  chips?: readonly ContextBarChipData[];\n};\nexport type ContextBarListProps = ComponentProps<typeof parts.List>;\nexport type ContextBarChipProps = ComponentProps<typeof parts.Chip>;\nexport type ContextBarOverflowProps = ComponentProps<typeof parts.Overflow>;\nexport type ContextBarContentProps = ComponentProps<typeof parts.Content>;\nexport type ContextBarTitleProps = ComponentProps<typeof parts.Title>;\nexport type ContextBarOverflowListProps = ComponentProps<typeof parts.OverflowList>;\nexport type ContextBarItemProps = ComponentProps<typeof parts.Item>;\nexport type ContextBarRemoveProps = ComponentProps<typeof parts.Remove>;\nexport type ContextBarItemRemoveProps = ComponentProps<typeof parts.ItemRemove>;\n\n/** A chip's remove control in the bar, for the pointer: hidden from assistive technology, which uses Delete. */\nexport const ContextBarRemove = parts.Remove;\n/** A chip's remove control in the list of the rest, as `ContextBarRemove` is in the bar. */\nexport const ContextBarItemRemove = parts.ItemRemove;\n\nconst drawIcon = (icon: unknown): JSX.Element => {\n  if (typeof icon === \"string\") return <img src={icon} alt=\"\" />;\n  if (typeof icon === \"function\") return untrack(icon as () => JSX.Element);\n  if (typeof Node !== \"undefined\" && icon instanceof Node) return icon.cloneNode(true) as JSX.Element;\n  return icon as JSX.Element;\n};\n\nconst chipContent = (state: ContextBarChipState, remove: () => JSX.Element) => (\n  <>\n    <Show when={state.chip?.icon !== undefined}>\n      <span data-context-bar-icon=\"\">{drawIcon(state.chip?.icon)}</span>\n    </Show>\n    <span data-context-bar-label=\"\">{state.chip?.label}</span>\n    {remove()}\n  </>\n);\n\n/** One chip in the bar: its icon, its label and a `ContextBarRemove`, unless you pass children. */\nexport function ContextBarChip(props: ContextBarChipProps) {\n  return (\n    <parts.Chip {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: ContextBarChipState) => chipContent(state, () => <ContextBarRemove value={props.value} />))}\n    </parts.Chip>\n  );\n}\n\n// Keyed by id, so adding a chip renders only that one.\nconst chips = (state: ContextBarListState) => (\n  <For each={state.rows} keyed={(row) => row.item.id}>\n    {(row) => <ContextBarChip value={row().item.id} />}\n  </For>\n);\n\n/** The row of chips, one Tab stop with arrow keys between them. Without children, a `ContextBarChip` per row. */\nexport function ContextBarList(props: ContextBarListProps) {\n  return <parts.List {...omit(props, \"children\")}>{props.children ?? chips}</parts.List>;\n}\n\n/** The \"+N\" button, present while some chips don't fit, which opens the list of them. */\nexport function ContextBarOverflow(props: ContextBarOverflowProps) {\n  return (\n    <parts.Overflow {...omit(props, \"children\")}>\n      {props.children ?? ((state: { count: number }) => `+${state.count}`)}\n    </parts.Overflow>\n  );\n}\n\n/** Names the list of the chips that don't fit: the `label`. The styles keep it for assistive technology only. */\nexport function ContextBarTitle(props: ContextBarTitleProps) {\n  return (\n    <parts.Title {...omit(props, \"children\")}>\n      {props.children ?? ((state: { label: string }) => state.label)}\n    </parts.Title>\n  );\n}\n\n/** One chip in the list of the rest, as `ContextBarChip` is in the bar, with a `ContextBarItemRemove`. */\nexport function ContextBarItem(props: ContextBarItemProps) {\n  return (\n    <parts.Item {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: ContextBarChipState) =>\n          chipContent(state, () => <ContextBarItemRemove value={props.value} />))}\n    </parts.Item>\n  );\n}\n\nconst items = (state: ContextBarListState) => (\n  <For each={state.rows} keyed={(row) => row.item.id}>\n    {(row) => <ContextBarItem value={row().item.id} />}\n  </For>\n);\n\n/** The chips that don't fit, one Tab stop with arrow keys between them. Without children, a `ContextBarItem` per row. */\nexport function ContextBarOverflowList(props: ContextBarOverflowListProps) {\n  return <parts.OverflowList {...omit(props, \"children\")}>{props.children ?? items}</parts.OverflowList>;\n}\n\ntype Render = (props: Record<string, unknown>, state: { presentation?: string }) => JSX.Element;\n\n/** The popover of the chips that don't fit, unless you pass children. Focus moves to the first. */\nexport function ContextBarContent(props: ContextBarContentProps) {\n  const render = (content: Record<string, unknown>, state: { presentation?: string }) => {\n    const element = () => {\n      const own = props.render as Render | undefined;\n      return own ? own(content, state) : <div {...content} />;\n    };\n    // A sheet sits in a full-screen viewport, which renders only while the content presents as one.\n    return (\n      <Show when={state.presentation === \"sheet\"} fallback={element()}>\n        <parts.Viewport>{element()}</parts.Viewport>\n      </Show>\n    );\n  };\n  return (\n    <parts.Content\n      initialFocus={CONTEXT_BAR_FIRST_ITEM}\n      sideOffset={6}\n      align=\"end\"\n      {...omit(props, \"children\", \"render\")}\n      render={render as ContextBarContentProps[\"render\"]}\n    >\n      {props.children ?? (\n        <>\n          <ContextBarTitle />\n          <ContextBarOverflowList />\n        </>\n      )}\n    </parts.Content>\n  );\n}\n\n/**\n * A row of context chips: the ones that don't fit go behind a \"+N\" button whose popover lists them. With `onRemove`,\n * Delete, Backspace or a chip's remove control removes it. Any `children` replace the list, the button and the popover.\n */\nexport function ContextBar(props: ContextBarProps) {\n  return (\n    <parts.Root {...omit(props, \"children\")}>\n      {props.children ?? (\n        <>\n          <ContextBarList />\n          <ContextBarOverflow />\n          <ContextBarContent />\n        </>\n      )}\n    </parts.Root>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/solid/context-bar.tsx"
    }
  ],
  "meta": {
    "layer": "solid"
  },
  "type": "registry:ui"
}
