{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-group",
  "title": "Button group",
  "description": "Keys joined in one strip, horizontal or vertical, with hold-to-repeat.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.5",
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json",
    "https://www.cyberspec.dev/r/button.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/button-group.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { bindRepeat } from \"@ui-sdk/core\"\nimport { Button as SdkButton } from \"@ui-sdk/react/button\"\nimport { haptic } from \"@/registry/cyber/lib/haptics\"\nimport { sfx } from \"@/registry/cyber/lib/sound\"\nimport type { ButtonSize, ButtonTone } from \"@/registry/cyber/ui/button\"\nimport \"@/registry/cyber/ui/cyber/button.css\"\nimport \"@/registry/cyber/ui/cyber/button-group.css\"\n\ntype GroupKey = {\n  /** The key's name. It's also what the key shows, unless `icon` or `content` draws something else. */\n  label: string\n  /** One icon, on a square key. */\n  icon?: React.ReactNode\n  /** Anything else to show in place of the label, like a readout. Keep any text it shows in `label` too. */\n  content?: React.ReactNode\n  /** Return `false` when nothing changes; this also stops a repeating hold. */\n  onPress?: () => boolean | void\n  /** A value-changing key's direction, independent of its label or icon. */\n  action?: \"increment\" | \"decrement\"\n  /** Keeps stepping while held: once on the press, then every 80ms after 380ms. */\n  repeat?: boolean\n  disabled?: boolean\n}\n\n// The cuts of a strip sit on its far side: under a row, and at the trailing\n// ends of a column. A key on its own is cut like any other key.\nfunction frameAt(index: number, count: number, vertical: boolean) {\n  if (count === 1) return \"notch br\"\n  if (index === 0) return vertical ? \"tl\" : \"bl\"\n  return index === count - 1 ? \"br\" : \"mid\"\n}\n\ntype KeyProps = { spec: GroupKey; frame: string; tone: ButtonTone; size: ButtonSize }\n\nconst face = (spec: GroupKey) => spec.icon ?? spec.content ?? spec.label\nconst named = (spec: GroupKey) => (spec.icon != null || spec.content != null ? spec.label : undefined)\n\nfunction Key({ spec, frame, tone, size }: KeyProps) {\n  return (\n    <SdkButton\n      data-kit=\"button\"\n      data-frame={frame}\n      data-press-flash=\"\"\n      data-tone={tone}\n      data-size={size}\n      data-icon={spec.icon != null ? \"\" : undefined}\n      data-sfx={spec.action ? \"none\" : undefined}\n      aria-label={named(spec)}\n      disabled={spec.disabled}\n      onClick={() => {\n        if (spec.disabled || !spec.onPress) return\n        if (spec.onPress() !== false && spec.action) sfx(spec.action)\n      }}\n    >\n      {face(spec)}\n    </SdkButton>\n  )\n}\n\n// A key that keeps stepping while it's held, through core's bindRepeat. It\n// sounds for every accepted step, so it silences the page's own press sound, and the\n// marks in its corner light while it runs. It stays focusable when disabled:\n// a stepper that reaches its bound mustn't drop the focus that got it there.\nfunction RepeatKey({ spec, frame, tone, size }: KeyProps) {\n  const el = React.useRef<HTMLButtonElement>(null)\n  const latest = React.useRef(spec)\n  React.useLayoutEffect(() => {\n    latest.current = spec\n  })\n  React.useEffect(() => {\n    const node = el.current\n    if (!node) return\n    const rest = () => node.removeAttribute(\"data-repeating\")\n    const unbind = bindRepeat(node, {\n      delay: 380,\n      repeat: 80,\n      // Keys are left to the button: one press each, repeating as the\n      // keyboard does.\n      keys: [],\n      disabled: () => Boolean(latest.current.disabled),\n      onStep: ({ count }) => {\n        const current = latest.current\n        if (current.disabled || !current.onPress || current.onPress() === false) return false\n        sfx(current.action ?? \"tick\")\n        if (count > 1) {\n          haptic(\"selection\")\n          node.setAttribute(\"data-repeating\", \"\")\n        }\n      },\n      onEnd: rest,\n    })\n    return () => {\n      unbind()\n      rest()\n    }\n  }, [])\n\n  return (\n    <SdkButton\n      ref={el}\n      data-kit=\"button\"\n      data-frame={frame}\n      data-press-flash=\"\"\n      data-tone={tone}\n      data-size={size}\n      data-icon={spec.icon != null ? \"\" : undefined}\n      data-sfx=\"none\"\n      aria-label={named(spec)}\n      disabled={spec.disabled}\n      focusableWhenDisabled\n    >\n      {face(spec)}\n      <span data-kit=\"button-group-repeat\" aria-hidden />\n    </SdkButton>\n  )\n}\n\n// Keys joined into one strip, each sharing an edge with the next: the minus,\n// readout and plus of a stepper, or a pair of answers. Every cell is still\n// its own button.\n//\n// - `label` names the strip for assistive technology.\n// - `keys` are its cells. One marked `repeat` keeps firing while held, for\n//   nudging a value, and carries three marks in its corner to say so.\n// - `orientation=\"vertical\"` stacks them.\nfunction ButtonGroup({\n  label,\n  keys,\n  orientation = \"horizontal\",\n  tone = \"secondary\",\n  size = \"md\",\n  ...props\n}: Omit<React.ComponentProps<\"div\">, \"children\" | \"role\"> & {\n  label: string\n  keys: GroupKey[]\n  orientation?: \"horizontal\" | \"vertical\"\n  tone?: ButtonTone\n  size?: ButtonSize\n}) {\n  return (\n    <div data-kit=\"button-group\" data-orientation={orientation} role=\"group\" aria-label={label} {...props}>\n      {keys.map((spec, index) => {\n        const Cell = spec.repeat ? RepeatKey : Key\n        return <Cell key={index} spec={spec} frame={frameAt(index, keys.length, orientation === \"vertical\")} tone={tone} size={size} />\n      })}\n    </div>\n  )\n}\n\nexport { ButtonGroup }\nexport type { GroupKey }\n",
      "type": "registry:ui",
      "target": "@ui/button-group.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/button-group.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  /* A strip of keys. Each cell is a key in its own frame (the look is\n     button.css's), so each draws its own states and its own focus; the strip\n     only lays them edge over edge, so neighbours share one line. */\n  [data-skin=\"cyber\"] [data-kit=\"button-group\"] {\n    display: inline-flex;\n    max-width: 100%;\n    /* The cells restack as they light, and that stays inside the strip. */\n    isolation: isolate;\n\n    & > * {\n      flex: 0 1 auto;\n    }\n\n    & > * + * {\n      margin-inline-start: -1px;\n    }\n\n    /* The shared line belongs to whichever cell is hot: a hovered, held or\n       focused cell comes forward, and a dead one drops back so its dim edge\n       never covers a live neighbour's. */\n    & > :is(:hover, :active, :focus-visible, [data-repeating]) {\n      z-index: 1;\n    }\n    & > :is(:disabled, [data-disabled]) {\n      z-index: -1;\n    }\n\n    /* A column is as wide as its widest cell, and never narrower than a\n       square one, so a short readout between two icons stays square. */\n    &[data-orientation=\"vertical\"] {\n      flex-direction: column;\n\n      & > * {\n        min-width: var(--cy-h);\n        padding-inline: 8px;\n      }\n\n      & > * + * {\n        margin-inline-start: 0;\n        margin-block-start: -1px;\n      }\n    }\n  }\n\n  /* Three marks in the corner of a key that repeats while held. They're\n     drawn as one gradient so they stay crisp, and they light in the signal\n     color for as long as the key is running. */\n  [data-skin=\"cyber\"] [data-kit=\"button-group-repeat\"] {\n    position: absolute;\n    inset-block-start: 3px;\n    inset-inline-end: 3px;\n    width: 8px;\n    height: 3px;\n    color: var(--cy-line-ctl);\n    background: repeating-linear-gradient(to right, currentColor 0 2px, transparent 2px 3px);\n    pointer-events: none;\n    transition: color var(--cy-t-fast) linear;\n\n    [data-repeating] > & {\n      color: var(--cy-signal);\n    }\n\n    [data-disabled] > & {\n      color: var(--cy-line-deco);\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/button-group.css"
    }
  ],
  "type": "registry:ui"
}
