{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toolbar",
  "title": "Toolbar",
  "description": "Keys, toggles and separators in one bar, moved through with arrow keys.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json",
    "https://www.cyberspec.dev/r/button.json",
    "https://www.cyberspec.dev/r/toggle.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/toolbar.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ToggleGroup as SdkToggleGroup } from \"@ui-sdk/react/toggle\"\nimport { Toolbar as SdkToolbar, ToolbarButton, ToolbarSeparator } from \"@ui-sdk/react/toolbar\"\nimport { Toggle } from \"@/registry/cyber/ui/toggle\"\nimport \"@/registry/cyber/ui/cyber/button.css\"\nimport \"@/registry/cyber/ui/cyber/toolbar.css\"\n\n// What a toolbar holds, as data:\n//\n// - a key:        { label, icon?, onPress?, disabled?, confirm? }\n// - a latch:      { type: \"toggle\", label, icon?, pressed? | defaultPressed?, onPressedChange?, disabled? }\n// - one of a set: { type: \"choice\", label, options, value? | defaultValue?, onValueChange? }\n// - a rule:       { type: \"separator\" }\n//\n// A cell with an `icon` shows only that, and its `label` is its name;\n// without one it shows the label.\ntype ToolbarEntry =\n  | {\n      type?: \"button\"\n      label: string\n      icon?: React.ReactNode\n      /** Return a Promise to keep the key pending until it settles. */\n      onPress?: () => void | Promise<unknown>\n      disabled?: boolean\n      /** A sentence saying what it does. An agent has to ask a person before pressing it. */\n      confirm?: string\n    }\n  | {\n      type: \"toggle\"\n      label: string\n      icon?: React.ReactNode\n      pressed?: boolean\n      defaultPressed?: boolean\n      onPressedChange?: (pressed: boolean) => void\n      disabled?: boolean\n    }\n  | {\n      type: \"choice\"\n      /** Names the set, like \"Tool\". */\n      label: string\n      options: { value: string; label: string; icon?: React.ReactNode; disabled?: boolean }[]\n      value?: string\n      defaultValue?: string\n      onValueChange?: (value: string) => void\n    }\n  | { type: \"separator\" }\n\ntype Cell = Exclude<ToolbarEntry, { type: \"separator\" } | { type: \"choice\" }>\ntype Choice = Extract<ToolbarEntry, { type: \"choice\" }>\ntype Section = { kind: \"run\"; cells: Cell[] } | { kind: \"choice\"; choice: Choice } | { kind: \"separator\" }\n\n// Neighbouring keys and latches join into one strip. A choice is a strip of\n// its own, and a separator ends one.\nfunction sections(items: ToolbarEntry[]): Section[] {\n  const out: Section[] = []\n  for (const item of items) {\n    if (item.type === \"separator\") out.push({ kind: \"separator\" })\n    else if (item.type === \"choice\") out.push({ kind: \"choice\", choice: item })\n    else {\n      const last = out[out.length - 1]\n      if (last?.kind === \"run\") last.cells.push(item)\n      else out.push({ kind: \"run\", cells: [item] })\n    }\n  }\n  return out\n}\n\n// The cuts of a strip sit on its far side: under a row, and at the two ends\n// of a column.\nfunction frameAt(index: number, count: number, vertical: boolean) {\n  if (count === 1) return \"br\"\n  if (index === 0) return vertical ? \"tl\" : \"bl\"\n  return index === count - 1 ? \"br\" : \"mid\"\n}\n\n// The name of the control an event came from, as a person would say it.\nfunction nameOf(target: EventTarget | null) {\n  const control = target instanceof Element ? target.closest<HTMLElement>(\"button, a\") : null\n  return control ? (control.getAttribute(\"aria-label\") ?? control.textContent ?? \"\").trim() || null : null\n}\n\n// The tools of an editor in one bar: keys, latches and sets of either, with\n// rules between them. Tab stops on it once; the arrow keys move along it,\n// Home and End jump to its ends, and Space or Enter presses.\n//\n// Its cells are mostly icons, so the bar ends in a readout that prints the\n// name of whichever one the pointer or the keyboard is on, and the bar's own\n// `label` the rest of the time. (It's decoration: every cell carries its\n// name for assistive technology.) A vertical bar has no room for one.\n//\n// The rest goes to ui-sdk's Toolbar: `orientation`, `loop`, `disabled`,\n// `controller`.\nfunction Toolbar({\n  label,\n  items,\n  orientation,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkToolbar>, \"children\"> & {\n  label: string\n  items: ToolbarEntry[]\n}) {\n  const vertical = orientation === \"vertical\"\n  const [hovered, setHovered] = React.useState<string | null>(null)\n  const [focused, setFocused] = React.useState<string | null>(null)\n  const name = hovered ?? focused\n\n  return (\n    <SdkToolbar\n      data-kit=\"toolbar\"\n      data-frame=\"br\"\n      aria-label={label}\n      orientation={orientation}\n      onPointerOver={(event) => setHovered(nameOf(event.target))}\n      onPointerLeave={() => setHovered(null)}\n      onFocus={(event) => setFocused(nameOf(event.target))}\n      onBlur={(event) => {\n        if (!event.currentTarget.contains(event.relatedTarget)) setFocused(null)\n      }}\n      {...props}\n    >\n      {sections(items).map((section, at) => {\n        if (section.kind === \"separator\") return <ToolbarSeparator key={at} data-kit=\"toolbar-separator\" />\n        if (section.kind === \"choice\") {\n          const { choice } = section\n          return (\n            <SdkToggleGroup\n              key={at}\n              data-kit=\"toolbar-run\"\n              aria-label={choice.label}\n              orientation={orientation}\n              // A tool is always chosen: pressing the current one keeps it.\n              deselectable={false}\n              value={choice.value === undefined ? undefined : [choice.value]}\n              defaultValue={choice.defaultValue === undefined ? undefined : [choice.defaultValue]}\n              onValueChange={([value]) => {\n                if (value !== undefined) choice.onValueChange?.(value)\n              }}\n            >\n              {choice.options.map((option, index) => (\n                <Toggle\n                  key={option.value}\n                  value={option.value}\n                  icon={option.icon}\n                  disabled={option.disabled}\n                  aria-label={option.icon != null ? option.label : undefined}\n                  data-frame={frameAt(index, choice.options.length, vertical)}\n                  data-joined=\"\"\n                >\n                  {option.icon != null ? undefined : option.label}\n                </Toggle>\n              ))}\n            </SdkToggleGroup>\n          )\n        }\n        return (\n          <div key={at} data-kit=\"toolbar-run\">\n            {section.cells.map((cell, index) => {\n              const frame = frameAt(index, section.cells.length, vertical)\n              const named = cell.icon != null ? cell.label : undefined\n              return cell.type === \"toggle\" ? (\n                <Toggle\n                  key={index}\n                  icon={cell.icon}\n                  pressed={cell.pressed}\n                  defaultPressed={cell.defaultPressed}\n                  onPressedChange={cell.onPressedChange}\n                  disabled={cell.disabled}\n                  aria-label={named}\n                  data-frame={frame}\n                  data-joined=\"\"\n                >\n                  {cell.icon != null ? undefined : cell.label}\n                </Toggle>\n              ) : (\n                <ToolbarButton\n                  key={index}\n                  data-kit=\"button\"\n                  data-frame={frame}\n                  data-press-flash=\"\"\n                  data-tone=\"secondary\"\n                  data-icon={cell.icon != null ? \"\" : undefined}\n                  data-agent-confirm={cell.confirm}\n                  aria-label={named}\n                  disabled={cell.disabled}\n                  onClick={() => cell.onPress?.()}\n                >\n                  {cell.icon ?? cell.label}\n                </ToolbarButton>\n              )\n            })}\n          </div>\n        )\n      })}\n      {!vertical && (\n        <span data-kit=\"toolbar-readout\" data-idle={name == null ? \"\" : undefined} aria-hidden>\n          {name ?? label}\n        </span>\n      )}\n    </SdkToolbar>\n  )\n}\n\nexport { Toolbar }\nexport type { ToolbarEntry }\n",
      "type": "registry:ui",
      "target": "@ui/toolbar.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/toolbar.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  /* The bar: a shallow tray with a decorative edge. The cells in it are\n     keys (button.css) and latches (toggle.css) in their own frames; the bar\n     only groups them into strips. Too narrow for its strips, it wraps, and\n     a strip never breaks in two. */\n  [data-skin=\"cyber\"] [data-kit=\"toolbar\"] {\n    --frame-cut: var(--cy-cut);\n    --frame-line: var(--cy-line-deco);\n    --frame-fill: var(--cy-panel);\n\n    display: flex;\n    flex-wrap: wrap;\n    align-items: center;\n    gap: 5px;\n    width: 100%;\n    min-width: 0;\n    padding: 5px;\n\n    &[data-orientation=\"vertical\"] {\n      display: inline-flex;\n      flex-direction: column;\n      flex-wrap: nowrap;\n      align-items: stretch;\n      width: auto;\n    }\n  }\n\n  /* A strip: cells laid edge over edge, so neighbours share one line. */\n  [data-skin=\"cyber\"] [data-kit=\"toolbar-run\"] {\n    flex: none;\n    display: flex;\n    /* The cells restack as they light, and that stays inside the strip. */\n    isolation: isolate;\n\n    & > * + * {\n      margin-inline-start: -1px;\n    }\n\n    /* The shared line belongs to whichever cell is hot: pressed cells come\n       forward, the one under the pointer or the keyboard further still, and\n       a dead one drops back. */\n    & > [data-pressed] {\n      z-index: 1;\n    }\n    & > :is(:hover, :active, :focus-visible) {\n      z-index: 2;\n    }\n    & > [data-disabled] {\n      z-index: -1;\n    }\n\n    [data-orientation=\"vertical\"] > & {\n      flex-direction: column;\n\n      & > * + * {\n        margin-inline-start: 0;\n        margin-block-start: -1px;\n      }\n    }\n  }\n\n  /* A rule between strips, running across the bar: short of the bar's full\n     depth, so it reads as a tick rather than a wall. */\n  [data-skin=\"cyber\"] [data-kit=\"toolbar-separator\"] {\n    flex: none;\n    align-self: stretch;\n    width: 1px;\n    margin: 6px 3px;\n    background: var(--cy-line-ctl);\n\n    &[data-orientation=\"horizontal\"] {\n      width: auto;\n      height: 1px;\n      margin: 3px 6px;\n    }\n  }\n\n  /* The readout at the end of the bar: the bar's own name, muted, until the\n     pointer or the keyboard lands on a cell; then that cell's name, in the\n     signal color. One line, cut short rather than wrapped, so the bar never\n     changes size as it changes. */\n  [data-skin=\"cyber\"] [data-kit=\"toolbar-readout\"] {\n    flex: 1 1 96px;\n    min-width: 0;\n    margin-inline-start: auto;\n    padding-inline: 8px 12px;\n    overflow: hidden;\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-xs);\n    line-height: 1.6;\n    letter-spacing: 0.04em;\n    text-align: end;\n    text-overflow: ellipsis;\n    text-transform: uppercase;\n    white-space: nowrap;\n    color: var(--cy-signal);\n\n    /* A caret before the name: lit with it, hollowed out while idle. */\n    &::before {\n      content: \"▸ \";\n    }\n\n    &[data-idle] {\n      color: var(--cy-ink-mute);\n\n      &::before {\n        content: \"▹ \";\n      }\n    }\n\n    [data-disabled] > & {\n      color: var(--cy-ink-mute);\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/toolbar.css"
    }
  ],
  "type": "registry:ui"
}
