{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-rocker-switch",
  "type": "registry:component",
  "title": "Rocker Switch",
  "description": "A mechanical I/O rocker that tilts in perspective, presses deeper under the pointer and lights a flickering status LED. Press the side you want, like the real thing.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "switch",
    "toggle",
    "rocker",
    "hardware",
    "3d",
    "micro"
  ],
  "docs": "https://hyperblur.dev/effects/micro-rocker-switch",
  "files": [
    {
      "path": "registry/hyperblur/micro-rocker-switch.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-rocker-switch.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroRockerSwitchProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onChange\" | \"role\" | \"children\"> {\n  checked?: boolean;\n  defaultChecked?: boolean;\n  label?: string;\n  onLabel?: string;\n  offLabel?: string;\n  showStatus?: boolean;\n  size?: number;\n  accent?: string;\n  onChange?: (checked: boolean) => void;\n}\n\nconst css = `\n.hb-wf1 {\n  --hb-wf1-c: #ff6a3d;\n  --hb-wf1-s: 56px;\n  --hb-wf1-r: -13deg;\n  display: inline-flex;\n  align-items: center;\n  gap: 14px;\n  margin: 0;\n  padding: 0;\n  box-sizing: border-box;\n  font: inherit;\n  color: #ededed;\n  background: none;\n  border: 0;\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-wf1 *, .hb-wf1 *::before, .hb-wf1 *::after { box-sizing: border-box; }\n.hb-wf1:focus-visible { outline: none; }\n.hb-wf1:focus-visible .hb-wf1-bz { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-wf1-c), inset 0 1px 0 rgba(255,255,255,0.06), inset 0 -3px 8px rgba(0,0,0,0.7); }\n.hb-wf1:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-wf1[data-on=\"true\"] { --hb-wf1-r: 13deg; }\n.hb-wf1[data-press=\"l\"] { --hb-wf1-r: -17deg; }\n.hb-wf1[data-press=\"r\"] { --hb-wf1-r: 17deg; }\n.hb-wf1-bz {\n  position: relative;\n  flex: none;\n  width: calc(var(--hb-wf1-s) * 1.78);\n  height: var(--hb-wf1-s);\n  padding: calc(var(--hb-wf1-s) * 0.1);\n  border-radius: calc(var(--hb-wf1-s) * 0.24);\n  background: linear-gradient(180deg, #1d1d1f 0%, #0c0c0d 100%);\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), inset 0 -3px 8px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.04), 0 10px 22px -8px rgba(0,0,0,0.9);\n  perspective: calc(var(--hb-wf1-s) * 4.2);\n  transition: box-shadow 0.2s ease;\n}\n.hb-wf1-bz::before {\n  content: \"\";\n  position: absolute;\n  inset: calc(var(--hb-wf1-s) * 0.07);\n  border-radius: calc(var(--hb-wf1-s) * 0.17);\n  background: #050505;\n  box-shadow: inset 0 2px 5px rgba(0,0,0,0.9);\n}\n.hb-wf1-p {\n  position: relative;\n  display: grid;\n  grid-template-columns: 1fr 1fr;\n  width: 100%;\n  height: 100%;\n  border-radius: calc(var(--hb-wf1-s) * 0.13);\n  transform: rotateY(var(--hb-wf1-r));\n  transform-style: preserve-3d;\n  transition: transform 0.34s cubic-bezier(0.3, 1.7, 0.45, 1);\n  overflow: hidden;\n  box-shadow: 0 2px 0 rgba(0,0,0,0.6), 0 6px 10px -4px rgba(0,0,0,0.8);\n}\n.hb-wf1-h {\n  position: relative;\n  display: grid;\n  place-items: center;\n  transition: background 0.3s ease, box-shadow 0.3s ease;\n}\n.hb-wf1-h[data-side=\"l\"] { background: linear-gradient(90deg, #3a3a3d 0%, #2c2c2f 100%); box-shadow: inset 1px 1px 0 rgba(255,255,255,0.12); }\n.hb-wf1-h[data-side=\"r\"] { background: linear-gradient(90deg, #1a1a1c 0%, #141416 100%); box-shadow: inset -1px 0 0 rgba(0,0,0,0.4); }\n.hb-wf1[data-on=\"true\"] .hb-wf1-h[data-side=\"l\"] { background: linear-gradient(90deg, #141416 0%, #1a1a1c 100%); box-shadow: inset 1px 0 0 rgba(0,0,0,0.4); }\n.hb-wf1[data-on=\"true\"] .hb-wf1-h[data-side=\"r\"] { background: linear-gradient(90deg, #2c2c2f 0%, #3a3a3d 100%); box-shadow: inset -1px 1px 0 rgba(255,255,255,0.12); }\n.hb-wf1-h + .hb-wf1-h { border-left: 1px solid rgba(0,0,0,0.55); }\n.hb-wf1-o {\n  width: calc(var(--hb-wf1-s) * 0.24);\n  height: calc(var(--hb-wf1-s) * 0.24);\n  border-radius: 50%;\n  border: calc(var(--hb-wf1-s) * 0.04) solid #9a9a9e;\n  transition: border-color 0.3s ease;\n}\n.hb-wf1-i {\n  width: calc(var(--hb-wf1-s) * 0.045);\n  height: calc(var(--hb-wf1-s) * 0.28);\n  border-radius: 2px;\n  background: #6a6a6e;\n  transition: background 0.3s ease, box-shadow 0.3s ease;\n}\n.hb-wf1[data-on=\"true\"] .hb-wf1-o { border-color: #4a4a4e; }\n.hb-wf1[data-on=\"true\"] .hb-wf1-i { background: var(--hb-wf1-c); box-shadow: 0 0 10px var(--hb-wf1-c), 0 0 2px var(--hb-wf1-c); }\n.hb-wf1-sh {\n  position: absolute;\n  inset: 0;\n  pointer-events: none;\n  background: linear-gradient(180deg, rgba(255,255,255,0.07) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.25) 100%);\n}\n.hb-wf1-st {\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n  text-align: left;\n  line-height: 1;\n}\n.hb-wf1-lb { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; color: #ededed; }\n.hb-wf1-row { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono), ui-monospace, monospace; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: #7a7a7a; transition: color 0.3s ease; }\n.hb-wf1-led {\n  width: 7px;\n  height: 7px;\n  border-radius: 50%;\n  background: #2a2a2a;\n  box-shadow: inset 0 1px 1px rgba(0,0,0,0.8);\n  transition: background 0.25s ease, box-shadow 0.25s ease;\n}\n.hb-wf1[data-on=\"true\"] .hb-wf1-row { color: #d6d6d6; }\n.hb-wf1[data-on=\"true\"] .hb-wf1-led { background: var(--hb-wf1-c); box-shadow: 0 0 0 2px color-mix(in srgb, var(--hb-wf1-c) 22%, transparent), 0 0 12px var(--hb-wf1-c); animation: hb-wf1-flick 0.42s steps(1, end); }\n@keyframes hb-wf1-flick {\n  0% { opacity: 0.3; }\n  20% { opacity: 1; }\n  35% { opacity: 0.5; }\n  55% { opacity: 1; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-wf1-p, .hb-wf1-h, .hb-wf1-i, .hb-wf1-led, .hb-wf1-o, .hb-wf1-row { transition: none; animation: none; }\n  .hb-wf1[data-on=\"true\"] .hb-wf1-led { animation: none; }\n}\n`;\n\nexport function MicroRockerSwitch({\n  checked,\n  defaultChecked = false,\n  label = \"Power\",\n  onLabel = \"On\",\n  offLabel = \"Off\",\n  showStatus = true,\n  size = 56,\n  accent = \"#ff6a3d\",\n  disabled,\n  onChange,\n  className = \"\",\n  style,\n  onClick,\n  onKeyDown,\n  onPointerDown,\n  onPointerUp,\n  onPointerLeave,\n  onPointerCancel,\n  ...rest\n}: MicroRockerSwitchProps) {\n  const [inner, setInner] = React.useState(defaultChecked);\n  const on = checked ?? inner;\n  const [press, setPress] = React.useState<\"\" | \"l\" | \"r\">(\"\");\n  const paddleRef = React.useRef<HTMLSpanElement>(null);\n\n  const set = (next: boolean) => {\n    if (disabled || next === on) return;\n    if (checked === undefined) setInner(next);\n    onChange?.(next);\n  };\n\n  const sideOf = (clientX: number): \"l\" | \"r\" | \"\" => {\n    const el = paddleRef.current;\n    if (!el) return \"\";\n    const r = el.getBoundingClientRect();\n    if (clientX < r.left || clientX > r.right) return \"\";\n    return clientX - r.left < r.width / 2 ? \"l\" : \"r\";\n  };\n\n  return (\n    <button\n      type=\"button\"\n      role=\"switch\"\n      aria-checked={on}\n      aria-label={showStatus ? undefined : label}\n      disabled={disabled}\n      data-on={on}\n      data-press={press}\n      className={`hb-wf1 ${className}`}\n      style={{ ...style, [\"--hb-wf1-c\" as string]: accent, [\"--hb-wf1-s\" as string]: `${size}px` }}\n      onPointerDown={(e) => {\n        onPointerDown?.(e);\n        if (disabled) return;\n        const s = sideOf(e.clientX);\n        if (s) setPress(s);\n      }}\n      onPointerUp={(e) => {\n        onPointerUp?.(e);\n        setPress(\"\");\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        setPress(\"\");\n      }}\n      onPointerCancel={(e) => {\n        onPointerCancel?.(e);\n        setPress(\"\");\n      }}\n      onClick={(e) => {\n        onClick?.(e);\n        if (e.defaultPrevented) return;\n        const s = e.detail === 0 ? \"\" : sideOf(e.clientX);\n        if (s === \"\") set(!on);\n        else set(s === \"r\");\n      }}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        if (e.key === \"ArrowRight\") {\n          e.preventDefault();\n          set(true);\n        } else if (e.key === \"ArrowLeft\") {\n          e.preventDefault();\n          set(false);\n        }\n      }}\n      {...rest}\n    >\n      <style href=\"hb-micro-rocker-switch\" precedence=\"default\">\n        {css}\n      </style>\n      <span className=\"hb-wf1-bz\" aria-hidden=\"true\">\n        <span ref={paddleRef} className=\"hb-wf1-p\">\n          <span className=\"hb-wf1-h\" data-side=\"l\">\n            <span className=\"hb-wf1-o\" />\n          </span>\n          <span className=\"hb-wf1-h\" data-side=\"r\">\n            <span className=\"hb-wf1-i\" />\n          </span>\n          <span className=\"hb-wf1-sh\" />\n        </span>\n      </span>\n      {showStatus ? (\n        <span className=\"hb-wf1-st\">\n          <span className=\"hb-wf1-lb\">{label}</span>\n          <span className=\"hb-wf1-row\">\n            <span key={on ? \"on\" : \"off\"} className=\"hb-wf1-led\" />\n            {on ? onLabel : offLabel}\n          </span>\n        </span>\n      ) : null}\n    </button>\n  );\n}\n"
    }
  ]
}