{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toggle",
  "title": "Toggle",
  "description": "A latching key that stays lit while pressed. Set cipher to decode its label when switched on.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/toggle.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Toggle as SdkToggle, ToggleIcon } from \"@ui-sdk/react/toggle\"\nimport { playCipherText } from \"@/registry/cyber/lib/cipher\"\nimport \"@/registry/cyber/ui/cyber/toggle.css\"\n\ntype Size = \"sm\" | \"md\"\n\nfunction ToggleLabelEffect({ lamp, pressed, disabled }: {\n  lamp: React.RefObject<HTMLSpanElement | null>\n  pressed: boolean\n  disabled: boolean\n}) {\n  const wasPressed = React.useRef(pressed)\n  React.useLayoutEffect(() => {\n    const turnedOn = pressed && !wasPressed.current\n    wasPressed.current = pressed\n    const toggle = lamp.current?.parentElement\n    if (turnedOn && !disabled && toggle) return playCipherText(toggle)\n  }, [lamp, pressed, disabled])\n  return null\n}\n\n// A latching key: press it and it stays lit until it's pressed again. It's\n// cut like a Button, with a lamp in its far corner that's hollow while off\n// and solid while on, so the state never rests on the fill alone.\n//\n// - `icon` goes before the label. With no label the key is square, and\n//   needs an aria-label.\n// - Keep the label the same in both states: \"Silent mode\", not \"Unmute\".\n//   Assistive technology announces whether it's pressed.\n//\n// The rest goes to ui-sdk's Toggle: `pressed`, `defaultPressed`,\n// `onPressedChange`, `disabled`, `controller`, and `value` inside a group.\nfunction Toggle({\n  size = \"md\",\n  icon,\n  mirror,\n  cipher = false,\n  children,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkToggle>, \"children\" | \"render\"> & {\n  size?: Size\n  icon?: React.ReactNode\n  /** Flips the icon in right-to-left text, for one that points a way. */\n  mirror?: boolean\n  /** Decode the label once when the toggle switches on at full FX. */\n  cipher?: boolean\n  children?: React.ReactNode\n}) {\n  const lamp = React.useRef<HTMLSpanElement>(null)\n  return (\n    <SdkToggle\n      data-kit=\"toggle\"\n      data-frame=\"notch br\"\n      data-press-flash=\"\"\n      data-size={size}\n      data-icon-only={icon != null && children == null ? \"\" : undefined}\n      {...props}\n      // The page plays a sound for every press from what was pressed. This\n      // one is a latch, so it says which way it's about to go: the click is\n      // heard before the state changes.\n      render={(part, state) => <button {...part} data-sfx={state.pressed ? \"off\" : \"on\"} />}\n    >\n      {state => <>\n        {icon != null && (\n          <ToggleIcon data-kit=\"toggle-icon\" data-cipher-ignore={cipher ? \"\" : undefined} mirror={mirror}>\n            {icon}\n          </ToggleIcon>\n        )}\n        {children}\n        <span ref={lamp} data-kit=\"toggle-lamp\" aria-hidden />\n        {cipher && children != null && <ToggleLabelEffect lamp={lamp} pressed={state.pressed} disabled={state.disabled} />}\n      </>}\n    </SdkToggle>\n  )\n}\n\nexport { Toggle }\nexport type { Size as ToggleSize }\n",
      "type": "registry:ui",
      "target": "@ui/toggle.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/toggle.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  /* A key that latches. It runs the same states as a Button, and adds the\n     one a Button doesn't have: pressed is the lit fill, held.\n       idle     line 70%, no fill, lamp hollow\n       hover    line 100%, fill 10%\n       pressed  line 100%, fill 40%, bright ink, lamp solid\n       down     a flash to 70% as it lands (data-press-flash) */\n  [data-skin=\"cyber\"] [data-kit=\"toggle\"] {\n    --frame-cut: var(--cy-cut-sm);\n    --frame-line: var(--cy-line-ctl);\n    --frame-fill: var(--cy-panel-a);\n    --frame-notch-x: 22px;\n    --frame-notch: 4px;\n    /* How far the lamp sits from the key's top edge. Under a notch the edge\n       is lower, so the lamp is too. */\n    --lamp-top: 4px;\n\n    display: inline-flex;\n    align-items: center;\n    justify-content: center;\n    gap: 8px;\n    min-width: 72px;\n    height: var(--cy-h);\n    padding-inline: 16px;\n    font-size: var(--cy-text-md);\n    font-weight: 600;\n    line-height: 1;\n    letter-spacing: var(--cy-track);\n    text-transform: uppercase;\n    white-space: nowrap;\n    color: var(--cy-ink);\n    cursor: pointer;\n    user-select: none;\n    transition:\n      background-color var(--cy-t-fast) linear,\n      border-color var(--cy-t-fast) linear,\n      color var(--cy-t-fast) linear;\n\n    &[data-frame~=\"notch\"] {\n      --lamp-top: 8px;\n    }\n\n    @media (hover: hover) {\n      &:hover:not([data-disabled]) {\n        --frame-line: var(--cy-line-hot);\n        --frame-fill: var(--cy-fill-hover);\n      }\n    }\n\n    &:active:not([data-disabled]) {\n      --frame-line: var(--cy-line-hot);\n      --frame-fill: var(--cy-fill-active);\n      color: var(--cy-ink-hi);\n    }\n\n    &[data-pressed] {\n      --frame-line: var(--cy-line-hot);\n      --frame-fill: var(--cy-fill-active);\n      color: var(--cy-ink-hi);\n\n      @media (hover: hover) {\n        &:hover:not([data-disabled]) {\n          --frame-fill: color-mix(in srgb, var(--cy-accent) 52%, var(--cy-panel));\n        }\n      }\n    }\n\n    &[data-size=\"sm\"] {\n      min-width: 56px;\n      height: var(--cy-h-sm);\n      padding-inline: 14px;\n      font-size: var(--cy-text-sm);\n    }\n\n    /* One icon and nothing else: a square. */\n    &[data-icon-only] {\n      min-width: 0;\n      width: var(--cy-h);\n      padding-inline: 0;\n\n      &[data-size=\"sm\"] {\n        width: var(--cy-h-sm);\n      }\n    }\n\n    /* A cell of a strip (a toggle group, a toolbar): no minimum, tighter\n       sides, so three words fit a narrow panel. */\n    &[data-joined]:not([data-icon-only]) {\n      min-width: 0;\n      padding-inline: 12px;\n    }\n\n    /* A row of a column reads from its leading edge, like a list. */\n    &[data-orientation=\"vertical\"]:not([data-icon-only]) {\n      justify-content: flex-start;\n      padding-inline-end: 22px;\n    }\n\n    /* Unavailable: hatched, and a pressed one keeps a trace of its fill and\n       its solid lamp, so it still says which way it was left. */\n    &[data-disabled] {\n      --frame-line: var(--cy-line-deco);\n      --frame-image: repeating-linear-gradient(135deg, transparent 0 5px, var(--cy-line-deco) 5px 6px);\n      color: var(--cy-ink-mute);\n      cursor: not-allowed;\n\n      &[data-pressed] {\n        --frame-fill: var(--cy-fill-hover);\n      }\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"toggle-icon\"] {\n    display: grid;\n    place-items: center;\n\n    & svg {\n      width: 16px;\n      height: 16px;\n    }\n\n    &[data-mirror]:dir(rtl) {\n      scale: -1 1;\n    }\n  }\n\n  /* The lamp: a block in the corner away from the notch. Hollow while off;\n     solid, in the signal color, while on. It strikes like a tube as it\n     lights: one unsteady moment, then steady. */\n  [data-skin=\"cyber\"] [data-kit=\"toggle-lamp\"] {\n    position: absolute;\n    inset-block-start: var(--lamp-top);\n    inset-inline-end: 4px;\n    width: 5px;\n    height: 5px;\n    border: 1px solid var(--cy-line-ctl);\n    pointer-events: none;\n    transition:\n      background-color var(--cy-t-fast) linear,\n      border-color var(--cy-t-fast) linear;\n\n    [data-pressed] > & {\n      border-color: var(--cy-signal);\n      background: var(--cy-signal);\n      box-shadow: 0 0 calc(6px * var(--cy-fx)) var(--cy-signal);\n      animation: var(--cy-fx-flicker) 420ms linear 1;\n    }\n\n    [data-disabled] > & {\n      border-color: var(--cy-line-deco);\n      box-shadow: none;\n      animation: none;\n    }\n\n    [data-disabled][data-pressed] > & {\n      border-color: var(--cy-ink-mute);\n      background: var(--cy-ink-mute);\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/toggle.css"
    }
  ],
  "type": "registry:ui"
}
