{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-tuner",
  "title": "Radio Tuner",
  "author": "VenusUI",
  "description": "A valve radio's tuning dial with a needle, a signal lamp and stations that fade in.",
  "files": [
    {
      "path": "registry/default/ui/radio-tuner.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface RadioStation {\n  frequency: number\n  name: string\n  /** What's on, shown when tuned in. */\n  genre?: string\n}\n\ninterface RadioTunerProps extends Omit<React.ComponentProps<\"div\">, \"onChange\"> {\n  stations: RadioStation[]\n  min?: number\n  max?: number\n  defaultFrequency?: number\n  onTune?: (frequency: number, station: RadioStation | null) => void\n}\n\n/**\n * A valve radio's tuning dial. Turn the knob or drag the needle across the\n * band (arrow keys move 0.1 MHz). Close to a station the signal lamp glows and\n * its name comes through; between stations there's only hiss.\n */\nfunction RadioTuner({ stations, min = 88, max = 108, defaultFrequency = 92.4, onTune, className, ...props }: RadioTunerProps) {\n  const [frequency, setFrequency] = React.useState(defaultFrequency)\n  const band = React.useRef<HTMLDivElement>(null)\n  const dragging = React.useRef(false)\n  const nearest = stations.reduce<RadioStation | null>((best, station) => (!best || Math.abs(station.frequency - frequency) < Math.abs(best.frequency - frequency) ? station : best), null)\n  const distance = nearest ? Math.abs(nearest.frequency - frequency) : 99\n  const signal = Math.max(0, 1 - distance / 0.6)\n  const tuned = signal > 0.55 ? nearest : null\n  const share = (frequency - min) / (max - min)\n\n  const set = (next: number) => {\n    const value = Math.round(Math.min(max, Math.max(min, next)) * 10) / 10\n    setFrequency(value)\n    const station = stations.find((s) => Math.abs(s.frequency - value) < 0.27) ?? null\n    onTune?.(value, station)\n  }\n\n  const fromPointer = (clientX: number) => {\n    const box = band.current?.getBoundingClientRect()\n    if (box) set(min + ((clientX - box.left) / box.width) * (max - min))\n  }\n\n  return (\n    <div data-slot=\"radio-tuner\" className={cn(\"w-full max-w-lg rounded-2xl bg-[linear-gradient(90deg,#5b3417,#7c4a24_45%,#4a2a12)] p-4 shadow-[0_18px_30px_-14px_rgb(0_0_0/0.65)]\", className)} {...props}>\n      <div className=\"rounded-lg bg-[#efe3c4] p-3 shadow-[inset_0_2px_6px_rgb(0_0_0/0.35)]\">\n        <div\n          ref={band}\n          onPointerDown={(event) => {\n            event.currentTarget.setPointerCapture(event.pointerId)\n            dragging.current = true\n            fromPointer(event.clientX)\n          }}\n          onPointerMove={(event) => dragging.current && fromPointer(event.clientX)}\n          onPointerUp={() => (dragging.current = false)}\n          className=\"relative h-16 cursor-ew-resize touch-none select-none\"\n        >\n          {Array.from({ length: (max - min) * 2 + 1 }, (_, i) => (\n            <span key={i} aria-hidden=\"true\" className=\"absolute bottom-5 w-px bg-neutral-700\" style={{ left: `${(i / ((max - min) * 2)) * 100}%`, height: i % 4 === 0 ? 14 : 7 }} />\n          ))}\n          {Array.from({ length: (max - min) / 2 + 1 }, (_, i) => (\n            <span key={i} aria-hidden=\"true\" className=\"absolute bottom-0 -translate-x-1/2 font-mono text-[10px] text-neutral-700\" style={{ left: `${(i / ((max - min) / 2)) * 100}%` }}>\n              {min + i * 2}\n            </span>\n          ))}\n          {stations.map((station) => (\n            <span key={station.name} aria-hidden=\"true\" className=\"absolute top-0 -translate-x-1/2 font-serif text-[9px] whitespace-nowrap text-red-900/80 italic\" style={{ left: `${((station.frequency - min) / (max - min)) * 100}%` }}>\n              {station.name}\n            </span>\n          ))}\n          <span aria-hidden=\"true\" className=\"absolute top-0 bottom-0 w-0.5 -translate-x-1/2 bg-red-600 shadow-[0_0_4px_rgb(220_38_38/0.6)] transition-[left] duration-100 motion-reduce:transition-none\" style={{ left: `${share * 100}%` }} />\n        </div>\n      </div>\n      <div className=\"mt-4 flex items-center gap-4\">\n        <span aria-hidden=\"true\" className=\"size-3 rounded-full transition-[background-color,box-shadow] duration-200\" style={{ background: `rgb(${Math.round(80 + 175 * signal)} ${Math.round(60 + 120 * signal)} 40)`, boxShadow: signal > 0.2 ? `0 0 ${10 * signal}px ${4 * signal}px rgb(251 191 36 / ${signal})` : \"none\" }} />\n        <div className=\"min-w-0 flex-1\">\n          <p aria-live=\"polite\" className=\"truncate font-mono text-sm text-amber-100\">\n            {frequency.toFixed(1)} MHz {tuned ? `· ${tuned.name}` : \"· …hiss…\"}\n          </p>\n          <p className=\"truncate text-xs text-amber-200/70\">{tuned?.genre ?? \"Turn the knob to find a station\"}</p>\n        </div>\n        <button\n          type=\"button\"\n          role=\"slider\"\n          aria-label=\"Tuning\"\n          aria-valuemin={min}\n          aria-valuemax={max}\n          aria-valuenow={frequency}\n          aria-valuetext={`${frequency.toFixed(1)} megahertz${tuned ? `, ${tuned.name}` : \"\"}`}\n          onKeyDown={(event) => {\n            const moves: Record<string, number> = { ArrowRight: 0.1, ArrowUp: 0.1, ArrowLeft: -0.1, ArrowDown: -0.1, PageUp: 1, PageDown: -1 }\n            const move = moves[event.key]\n            if (move === undefined) return\n            event.preventDefault()\n            set(frequency + move)\n          }}\n          onWheel={(event) => set(frequency - Math.sign(event.deltaY) * 0.1)}\n          style={{ rotate: `${share * 720}deg` }}\n          className=\"size-14 shrink-0 rounded-full bg-[conic-gradient(#3f3f46,#a1a1aa,#27272a,#d4d4d8,#3f3f46)] shadow-[0_4px_10px_rgb(0_0_0/0.5)] outline-none focus-visible:ring-3 focus-visible:ring-ring/60\"\n        >\n          <span aria-hidden=\"true\" className=\"mx-auto mt-1 block h-3 w-1 rounded-full bg-amber-100\" />\n        </button>\n      </div>\n    </div>\n  )\n}\n\nexport { RadioTuner }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "inputs",
    "interactive"
  ],
  "type": "registry:ui"
}