{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shell-toolbar",
  "type": "registry:component",
  "title": "Toolbar",
  "description": "A horizontal action strip with an overflow menu",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-icons.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/shell/src/recipe.ts",
      "target": "@ui/gpuixui/shell/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { classesToStyle } from \"../tw/index.js\";\nimport * as MutableHashMap from \"effect/MutableHashMap\";\nimport * as Option from \"effect/Option\";\nimport type { Theme } from \"./theme.js\";\n\nconst CACHE_LIMIT = 256;\n\nconst compiled = new WeakMap<\n  Theme,\n  MutableHashMap.MutableHashMap<string, StyleDesc>\n>();\n\nexport const recipeStyle = (recipe: string, theme: Theme): StyleDesc => {\n  const byRecipe = compiled.get(theme);\n  if (byRecipe !== undefined) {\n    const hit = MutableHashMap.get(byRecipe, recipe);\n    if (Option.isSome(hit)) return hit.value;\n  }\n  const style = Object.freeze(classesToStyle(recipe, theme).style);\n  if (byRecipe === undefined) {\n    compiled.set(theme, MutableHashMap.make([recipe, style]));\n  } else if (MutableHashMap.size(byRecipe) < CACHE_LIMIT) {\n    MutableHashMap.set(byRecipe, recipe, style);\n  }\n  return style;\n};\n"
    },
    {
      "path": "packages/shell/src/theme.ts",
      "target": "@ui/gpuixui/shell/theme.ts",
      "type": "registry:lib",
      "content": "import type { Theme } from \"../tokens/index.js\";\nimport { useTheme as useTokenTheme } from \"../tokens/react.js\";\n\nexport {\n  currentPlatform,\n  disabledOpacity,\n  materialFill,\n  statusTone,\n  textStyle,\n} from \"../tokens/index.js\";\nexport type {\n  PlatformName,\n  StatusTone,\n  TextRole,\n  Theme,\n} from \"../tokens/index.js\";\n\nexport const useTheme = (): Theme => useTokenTheme();\n"
    },
    {
      "path": "packages/shell/src/toolbar/logic.ts",
      "target": "@ui/gpuixui/shell/toolbar/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport { decideMove, rovingIndex } from \"../../primitives/index.js\";\n\nexport interface ToolbarItemSpec {\n  readonly id: string;\n  readonly disabled: boolean;\n}\n\nexport interface OverflowSplit {\n  readonly visible: ReadonlyArray<ToolbarItemSpec>;\n  readonly overflow: ReadonlyArray<ToolbarItemSpec>;\n}\n\nexport const splitOverflow = (\n  items: ReadonlyArray<ToolbarItemSpec>,\n  max: number,\n): OverflowSplit => {\n  const count = Arr.length(items);\n  if (max <= 0) return { visible: [], overflow: items };\n  if (count <= max) return { visible: items, overflow: [] };\n  const visibleCount = max - 1;\n  return {\n    visible: Arr.take(items, visibleCount),\n    overflow: Arr.drop(items, visibleCount),\n  };\n};\n\nexport const initialRoving = (\n  count: number,\n  isDisabled: (index: number) => boolean,\n): Option.Option<number> => rovingIndex(count, Option.none(), isDisabled);\n\nexport const moveRoving = (\n  current: number,\n  count: number,\n  delta: 1 | -1,\n  isDisabled: (index: number) => boolean,\n): Option.Option<number> =>\n  decideMove(\n    current,\n    count,\n    delta === 1 ? \"right\" : \"left\",\n    \"horizontal\",\n    isDisabled,\n  );\n"
    },
    {
      "path": "packages/shell/src/toolbar/toolbar.tsx",
      "target": "@ui/gpuixui/shell/toolbar/toolbar.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { KeyEvent, Props, PublicInstance, StyleDesc } from \"@gpuix/react\";\nimport { useGpuix } from \"@gpuix/react\";\nimport {\n  FloatingLayer,\n  floatingRootStyle,\n  mergeStyles,\n} from \"@gpuix/react/floating\";\nimport { Icon, type IconName } from \"../../icons/index.js\";\nimport {\n  Button,\n  IconButton,\n  isPlainKey,\n  ToolbarScope,\n  Separator,\n  ToggleGroup,\n} from \"../../primitives/index.js\";\nimport { cn, MENU_CONTENT, MENU_ITEM } from \"../../tw/index.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport { Fragment, useRef, useState } from \"react\";\nimport { recipeStyle } from \"../recipe.js\";\nimport { disabledOpacity, useTheme } from \"../theme.js\";\nimport type { Theme } from \"../theme.js\";\nimport {\n  initialRoving,\n  moveRoving,\n  splitOverflow,\n  type ToolbarItemSpec,\n} from \"./logic.js\";\n\nconst TOOLBAR =\n  \"flex w-full flex-row items-center gap-1 border-b border-input bg-card px-2 py-1\";\nconst TOOLBAR_ITEM_LABEL = \"text-sm font-medium font-sans\";\n\nexport interface ToolbarAction {\n  readonly id: string;\n  readonly label: string;\n  readonly icon?: IconName;\n\n  readonly group?: string;\n  readonly disabled?: boolean;\n}\n\nexport interface ToolbarMode {\n  readonly id: string;\n  readonly label: string;\n  readonly disabled?: boolean;\n}\n\nexport interface ToolbarProps extends Omit<Props, \"children\"> {\n  readonly label?: string;\n  readonly actions: ReadonlyArray<ToolbarAction>;\n\n  readonly max?: number;\n\n  readonly onAction?: (id: string) => void;\n\n  readonly modes?: ReadonlyArray<ToolbarMode>;\n\n  readonly mode?: string;\n\n  readonly onModeChange?: (id: string) => void;\n\n  readonly modesLabel?: string;\n  readonly className?: string;\n}\n\nconst isOverflowSlot = (slot: number, visibleCount: number): boolean =>\n  slot === visibleCount;\n\nconst overflowItemStyle = (theme: Theme, disabled: boolean): StyleDesc => ({\n  ...recipeStyle(MENU_ITEM, theme),\n  ...(disabled ? { opacity: disabledOpacity } : {}),\n  cursor: disabled ? \"not-allowed\" : \"pointer\",\n});\n\nexport const Toolbar = ({\n  label,\n  actions,\n  max,\n  onAction,\n  modes,\n  mode,\n  onModeChange,\n  modesLabel = \"View\",\n  className,\n  style,\n  ...rest\n}: ToolbarProps) => {\n  const theme = useTheme();\n  const renderer = useGpuix().renderer;\n\n  const specs: ReadonlyArray<ToolbarItemSpec> = Arr.map(actions, (action) => ({\n    id: action.id,\n    disabled: action.disabled === true,\n  }));\n  const split =\n    max === undefined\n      ? { visible: specs, overflow: [] as ReadonlyArray<ToolbarItemSpec> }\n      : splitOverflow(specs, max);\n  const visibleCount = Arr.length(split.visible);\n  const hasOverflow = Arr.length(split.overflow) > 0;\n  const slotCount = visibleCount + (hasOverflow ? 1 : 0);\n  const modeOptions = Arr.map(modes ?? [], (candidate) => ({\n    value: candidate.id,\n    label: candidate.label,\n    disabled: candidate.disabled === true,\n  }));\n\n  const isDisabled = (slot: number): boolean =>\n    isOverflowSlot(slot, visibleCount)\n      ? false\n      : (split.visible[slot]?.disabled ?? true);\n\n  const [roving, setRoving] = useState<Option.Option<number>>(() =>\n    initialRoving(slotCount, isDisabled),\n  );\n  const [overflowOpen, setOverflowOpen] = useState(false);\n\n  const refs = useRef<Array<PublicInstance | null>>([]);\n  const overflowRef = useRef<PublicInstance | null>(null);\n\n  const focusSlot = (slot: number): void => {\n    const target = refs.current[slot];\n    if (target !== null && target !== undefined) {\n      renderer?.focusElement?.(target.id);\n    }\n  };\n\n  const handleKeyDown = (event: KeyEvent): void => {\n    const key = event.key ?? \"\";\n    if (!isPlainKey(event.modifiers)) return;\n    if (key !== \"left\" && key !== \"right\") return;\n    const next = moveRoving(\n      Option.getOrElse(roving, () => 0),\n      slotCount,\n      key === \"right\" ? 1 : -1,\n      isDisabled,\n    );\n    setRoving(next);\n    Option.map(next, focusSlot);\n  };\n\n  const closeOverflow = (): void => {\n    setOverflowOpen(false);\n    if (overflowRef.current !== null)\n      renderer?.focusElement?.(overflowRef.current.id);\n  };\n\n  return (\n    <ToolbarScope.Provider value>\n      <div\n        role=\"toolbar\"\n        {...(label === undefined ? {} : { \"aria-label\": label })}\n        {...rest}\n        onKeyDown={handleKeyDown}\n        style={mergeStyles(\n          mergeStyles(\n            recipeStyle(cn(TOOLBAR, className), theme),\n            floatingRootStyle(),\n          ),\n          style,\n        )}\n      >\n        {Arr.map(Arr.take(actions, visibleCount), (action, index) => {\n          const disabled = action.disabled === true;\n          const groupBefore =\n            index === 0\n              ? false\n              : (actions[index - 1]?.group ?? undefined) !==\n                (action.group ?? undefined);\n          return (\n            <Fragment key={action.id}>\n              {groupBefore ? (\n                <Separator orientation=\"vertical\" className=\"h-4\" />\n              ) : null}\n              <Button\n                variant=\"ghost\"\n                size=\"sm\"\n                label={action.label}\n                disabled={disabled}\n                tabIndex={Option.contains(roving, index) ? 0 : -1}\n                testId={`toolbar-action-${action.id}`}\n                ref={(instance) => {\n                  refs.current[index] = instance;\n                }}\n                onActivate={() => onAction?.(action.id)}\n                leading={\n                  action.icon === undefined ? undefined : (\n                    <Icon\n                      name={action.icon}\n                      color={\n                        disabled\n                          ? theme.colors.disabledForeground\n                          : theme.colors.foreground\n                      }\n                      size=\"sm\"\n                    />\n                  )\n                }\n              >\n                <text\n                  style={{\n                    ...recipeStyle(TOOLBAR_ITEM_LABEL, theme),\n                    color: disabled\n                      ? theme.colors.disabledForeground\n                      : theme.colors.foreground,\n                  }}\n                >\n                  {action.label}\n                </text>\n              </Button>\n            </Fragment>\n          );\n        })}\n\n        <div style={{ flexGrow: 1, flexBasis: 0 }} />\n\n        {modeOptions.length === 0 ? null : (\n          <Fragment>\n            <Separator orientation=\"vertical\" className=\"h-4\" />\n            <ToggleGroup\n              type=\"single\"\n              label={modesLabel}\n              size=\"sm\"\n              options={modeOptions}\n              {...(mode === undefined ? {} : { value: mode })}\n              onValueChange={onModeChange}\n              itemTestId={(id) => `toolbar-mode-${id}`}\n            />\n          </Fragment>\n        )}\n\n        {hasOverflow ? (\n          <Fragment>\n            <IconButton\n              label=\"More actions\"\n              size=\"sm\"\n              aria-haspopup=\"menu\"\n              aria-expanded={overflowOpen}\n              testId=\"toolbar-overflow\"\n              tabIndex={Option.contains(roving, visibleCount) ? 0 : -1}\n              ref={(instance) => {\n                refs.current[visibleCount] = instance;\n                overflowRef.current = instance;\n              }}\n              onActivate={() => setOverflowOpen((open) => !open)}\n              icon={<Icon name=\"ellipsis\" color={theme.colors.foreground} />}\n            />\n            {overflowOpen ? (\n              <FloatingLayer\n                role=\"menu\"\n                aria-label=\"More actions\"\n                tabIndex={-1}\n                side=\"bottom\"\n                align=\"end\"\n                sideOffset={2}\n                onKeyDown={(event) => {\n                  if (event.key === \"escape\") {\n                    event.preventDefault();\n                    closeOverflow();\n                  }\n                }}\n                style={recipeStyle(cn(MENU_CONTENT, \"min-w-40\"), theme)}\n              >\n                {Arr.map(Arr.drop(actions, visibleCount), (action) => {\n                  const disabled = action.disabled === true;\n                  return (\n                    <div\n                      key={action.id}\n                      role=\"menuitem\"\n                      aria-disabled={disabled}\n                      testId={`toolbar-overflow-item-${action.id}`}\n                      onClick={() => {\n                        if (disabled) return;\n                        onAction?.(action.id);\n                        setOverflowOpen(false);\n                      }}\n                      style={overflowItemStyle(theme, disabled)}\n                    >\n                      <text\n                        style={{\n                          ...recipeStyle(TOOLBAR_ITEM_LABEL, theme),\n                          color: disabled\n                            ? theme.colors.disabledForeground\n                            : theme.colors.popoverForeground,\n                        }}\n                      >\n                        {action.label}\n                      </text>\n                    </div>\n                  );\n                })}\n              </FloatingLayer>\n            ) : null}\n          </Fragment>\n        ) : null}\n      </div>\n    </ToolbarScope.Provider>\n  );\n};\n"
    }
  ],
  "docs": "[Toolbar](https://gpuixui.sudokw.com/shell/toolbar) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/shell/toolbar",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}