{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "context-bar",
  "title": "Context Bar",
  "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/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/context-bar.tsx",
      "content": "\"use client\";\n\nimport {\n  CONTEXT_BAR_FIRST_ITEM,\n  type ContextBarChipState,\n  type ContextBarListState,\n  type ContextBarOptions,\n  contextBarPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts, renderElement } from \"@ui-sdk/react/primitive\";\nimport { type ComponentProps, memo, type ReactElement } from \"react\";\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/** A chip, whose `icon` is an image URL or an element such as an inline `svg`. */\nexport type ContextBarChipData = Omit<NonNullable<ContextBarOptions[\"chips\"]>[number], \"icon\"> & {\n  icon?: string | ReactElement;\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 chipContent = ({ chip }: ContextBarChipState, remove: ReactElement) => {\n  const icon = chip?.icon as string | ReactElement | undefined;\n  return (\n    <>\n      {icon === undefined ? null : (\n        <span data-context-bar-icon=\"\">{typeof icon === \"string\" ? <img src={icon} alt=\"\" /> : icon}</span>\n      )}\n      <span data-context-bar-label=\"\">{chip?.label}</span>\n      {remove}\n    </>\n  );\n};\n\n/**\n * One chip in the bar: its icon, its label and a `ContextBarRemove`, unless you pass children. Memoized, so adding a\n * chip renders only that one.\n */\nexport const ContextBarChip = memo(function ContextBarChip({\n  value,\n  children = (state) => chipContent(state, <ContextBarRemove value={value} />),\n  ...props\n}: ContextBarChipProps) {\n  return (\n    <parts.Chip value={value} {...props}>\n      {children}\n    </parts.Chip>\n  );\n});\n\nconst CHIPS = ({ rows }: ContextBarListState) =>\n  rows.map((row) => <ContextBarChip key={row.item.id} value={row.item.id} />);\n\n/** The row of chips, one Tab stop with arrow keys between them. Without children, a `ContextBarChip` per row. */\nexport function ContextBarList({ children = CHIPS, ...props }: ContextBarListProps) {\n  return <parts.List {...props}>{children}</parts.List>;\n}\n\n/** The \"+N\" button, present while some chips don't fit, which opens the list of them. */\nexport function ContextBarOverflow({\n  children = ({ count }) => `+${count}`,\n  ...props\n}: ContextBarOverflowProps) {\n  return <parts.Overflow {...props}>{children}</parts.Overflow>;\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({ children = ({ label }) => label, ...props }: ContextBarTitleProps) {\n  return <parts.Title {...props}>{children}</parts.Title>;\n}\n\n/** One chip in the list of the rest, as `ContextBarChip` is in the bar, with a `ContextBarItemRemove`. */\nexport const ContextBarItem = memo(function ContextBarItem({\n  value,\n  children = (state) => chipContent(state, <ContextBarItemRemove value={value} />),\n  ...props\n}: ContextBarItemProps) {\n  return (\n    <parts.Item value={value} {...props}>\n      {children}\n    </parts.Item>\n  );\n});\n\nconst ITEMS = ({ rows }: ContextBarListState) =>\n  rows.map((row) => <ContextBarItem key={row.item.id} value={row.item.id} />);\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({ children = ITEMS, ...props }: ContextBarOverflowListProps) {\n  return <parts.OverflowList {...props}>{children}</parts.OverflowList>;\n}\n\nconst DEFAULT_PANEL = (\n  <>\n    <ContextBarTitle />\n    <ContextBarOverflowList />\n  </>\n);\n\n/** The popover of the chips that don't fit, unless you pass children. Focus moves to the first. */\nexport function ContextBarContent({ children = DEFAULT_PANEL, render, ...props }: ContextBarContentProps) {\n  return (\n    <parts.Content\n      initialFocus={CONTEXT_BAR_FIRST_ITEM}\n      sideOffset={6}\n      align=\"end\"\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// Shared, so an update doesn't render the default parts' wrappers again.\nconst DEFAULT_PARTS = (\n  <>\n    <ContextBarList />\n    <ContextBarOverflow />\n    <ContextBarContent />\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({ children = DEFAULT_PARTS, ...props }: ContextBarProps) {\n  return <parts.Root {...props}>{children}</parts.Root>;\n}\n",
      "type": "registry:ui",
      "target": "@ui/context-bar.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
