{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pull-cord-lamp",
  "title": "Pull-Cord Lamp",
  "author": "VenusUI",
  "description": "A hanging lamp you switch by pulling its cord; it can toggle the page between light and dark mode.",
  "files": [
    {
      "path": "registry/default/ui/pull-cord-lamp.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface PullCordLampProps extends Omit<React.ComponentProps<\"div\">, \"onToggle\"> {\n  /** Controlled state. Ignored when `controlsTheme` is set. */\n  on?: boolean\n  defaultOn?: boolean\n  onToggle?: (on: boolean) => void\n  /** Pull to switch the page between light (lamp on) and dark (lamp off) by toggling `.dark` on `<html>`. */\n  controlsTheme?: boolean\n  /** Accessible name for the cord, e.g. \"Light\". */\n  label?: string\n}\n\nconst PULL_DISTANCE = 28\nconst MAX_PULL = 56\n\n/** Whether `<html>` has the `.dark` class, kept in sync as it changes. */\nfunction useHtmlDark() {\n  return React.useSyncExternalStore(\n    (onChange) => {\n      const observer = new MutationObserver(onChange)\n      observer.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\"] })\n      return () => observer.disconnect()\n    },\n    () => document.documentElement.classList.contains(\"dark\"),\n    () => false\n  )\n}\n\n/**\n * A hanging lamp with a pull cord. Drag the bead down and let go (or click\n * it, or press Enter or Space) to switch the lamp; it swings a little each\n * time. With `controlsTheme` it switches the page between light and dark.\n */\nfunction PullCordLamp({ on: onProp, defaultOn = true, onToggle, controlsTheme = false, label = \"Light\", className, ...props }: PullCordLampProps) {\n  const htmlDark = useHtmlDark()\n  const [uncontrolled, setUncontrolled] = React.useState(defaultOn)\n  const on = controlsTheme ? !htmlDark : (onProp ?? uncontrolled)\n  const [pull, setPull] = React.useState<number | null>(null)\n  const [swings, setSwings] = React.useState(0)\n  const start = React.useRef(0)\n  const dragged = React.useRef(false)\n\n  const toggle = () => {\n    const next = !on\n    if (controlsTheme) document.documentElement.classList.toggle(\"dark\", !next)\n    setUncontrolled(next)\n    setSwings((n) => n + 1)\n    onToggle?.(next)\n  }\n\n  return (\n    <div data-slot=\"pull-cord-lamp\" data-on={on || undefined} className={cn(\"relative flex w-56 flex-col items-center select-none\", className)} {...props}>\n      {/* Light from the bulb. */}\n      <div\n        aria-hidden=\"true\"\n        className={cn(\n          \"pointer-events-none absolute top-[9.5rem] left-1/2 h-[26rem] w-[34rem] -translate-x-1/2 transition-opacity duration-500 [clip-path:polygon(38%_0,62%_0,100%_100%,0_100%)]\",\n          \"bg-[radial-gradient(ellipse_at_top,rgb(253_224_71/0.35),rgb(253_186_116/0.12)_45%,transparent_75%)]\",\n          on ? \"opacity-100\" : \"opacity-0\"\n        )}\n      />\n\n      {/* The lamp, which swings from its ceiling mount. */}\n      <div key={swings} className={cn(\"flex origin-top flex-col items-center\", swings > 0 && \"animate-pull-cord-lamp-swing motion-reduce:animate-none\")}>\n        <span aria-hidden=\"true\" className=\"h-3 w-8 rounded-b-md bg-neutral-400 dark:bg-neutral-600\" />\n        <span aria-hidden=\"true\" className=\"h-24 w-px bg-neutral-500\" />\n        {/* Shade */}\n        <span aria-hidden=\"true\" className=\"relative h-16 w-36\">\n          <span className=\"absolute inset-0 bg-linear-to-b from-neutral-700 via-neutral-800 to-neutral-950 [clip-path:polygon(32%_0,68%_0,100%_100%,0_100%)] dark:from-neutral-500 dark:via-neutral-700 dark:to-neutral-900\" />\n          <span className=\"absolute inset-x-[33%] top-0 h-1.5 rounded-full bg-neutral-600\" />\n          {/* Bulb */}\n          <span\n            className={cn(\n              \"absolute -bottom-3 left-1/2 size-7 -translate-x-1/2 rounded-full transition-[background-color,box-shadow] duration-300\",\n              on\n                ? \"bg-amber-100 shadow-[0_0_20px_8px_rgb(253_224_71/0.6),0_0_60px_20px_rgb(253_186_116/0.35)]\"\n                : \"bg-neutral-300 shadow-[inset_0_-3px_4px_rgb(0_0_0/0.15)] dark:bg-neutral-600\"\n            )}\n          />\n        </span>\n      </div>\n\n      {/* Pull cord, hanging to the side of the shade. */}\n      <div className=\"absolute top-[8.5rem] left-[calc(50%+3.25rem)] flex flex-col items-center\">\n        <span aria-hidden=\"true\" className=\"w-px bg-neutral-400 transition-[height] duration-300 ease-out dark:bg-neutral-500\" style={{ height: 64 + (pull ?? 0) }} />\n        <button\n          type=\"button\"\n          role=\"switch\"\n          aria-checked={on}\n          aria-label={label}\n          onPointerDown={(event) => {\n            event.currentTarget.setPointerCapture(event.pointerId)\n            start.current = event.clientY\n            dragged.current = false\n            setPull(0)\n          }}\n          onPointerMove={(event) => {\n            if (pull === null) return\n            const dy = Math.min(MAX_PULL, Math.max(0, event.clientY - start.current))\n            if (dy > 4) dragged.current = true\n            setPull(dy)\n          }}\n          onPointerUp={() => {\n            if (pull !== null && pull > PULL_DISTANCE) toggle()\n            setPull(null)\n          }}\n          onPointerCancel={() => setPull(null)}\n          onClick={() => {\n            // Drags are handled on pointer up; this is a plain click, tap or key press.\n            if (!dragged.current) toggle()\n            dragged.current = false\n          }}\n          className=\"-mt-px grid size-6 cursor-grab touch-none place-items-center rounded-full outline-none focus-visible:ring-3 focus-visible:ring-ring/50 active:cursor-grabbing\"\n        >\n          <span aria-hidden=\"true\" className=\"h-4 w-2.5 rounded-full bg-linear-to-b from-amber-200 to-amber-600 shadow-[0_2px_3px_rgb(0_0_0/0.3)]\" />\n        </button>\n      </div>\n    </div>\n  )\n}\n\nexport { PullCordLamp }\n",
      "type": "registry:ui"
    }
  ],
  "cssVars": {
    "theme": {
      "animate-pull-cord-lamp-swing": "pull-cord-lamp-swing 1.1s ease-out"
    }
  },
  "css": {
    "@keyframes pull-cord-lamp-swing": {
      "0%": {
        "transform": "rotate(0deg)"
      },
      "20%": {
        "transform": "rotate(4deg)"
      },
      "45%": {
        "transform": "rotate(-3deg)"
      },
      "70%": {
        "transform": "rotate(1.5deg)"
      },
      "100%": {
        "transform": "rotate(0deg)"
      }
    }
  },
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "buttons"
  ],
  "type": "registry:ui"
}