{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-time-picker",
  "type": "registry:component",
  "title": "Clock Time Picker",
  "description": "A time picker with an analog dial: drag the hand to the hour and it moves on to minutes, which snap to a step. A large readout, an AM and PM switch and full keyboard control sit beside it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "forms",
    "time",
    "clock",
    "dial",
    "picker",
    "schedule",
    "input"
  ],
  "docs": "https://hyperblur.dev/effects/input-time-picker",
  "files": [
    {
      "path": "registry/hyperblur/input-time-picker.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/input-time-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface InputTimePickerProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  label?: string;\n  value?: string;\n  defaultValue?: string;\n  onChange?: (value: string) => void;\n  hourCycle?: 12 | 24;\n  step?: number;\n  size?: number;\n  accent?: string;\n}\n\nconst css = `\n.hb-xg9 {\n  --hb-xg9-c: #2f7bff;\n  --hb-xg9-size: 176px;\n  box-sizing: border-box;\n  display: flex;\n  flex-wrap: wrap;\n  align-items: center;\n  justify-content: center;\n  gap: 18px;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xg9 *, .hb-xg9 *::before, .hb-xg9 *::after { box-sizing: border-box; }\n.hb-xg9-side { display: flex; flex: 1 1 120px; flex-direction: column; gap: 10px; min-width: 0; }\n.hb-xg9-label { margin: 0; font-size: 12.5px; font-weight: 500; color: #a1a1a1; }\n.hb-xg9-read { display: flex; align-items: center; gap: 2px; }\n.hb-xg9-seg {\n  position: relative;\n  margin: 0;\n  padding: 2px 6px;\n  border: 0;\n  border-radius: 10px;\n  background: transparent;\n  color: #6f6f6f;\n  font-family: var(--font-grotesk), var(--font-sans), sans-serif;\n  font-size: 38px;\n  font-weight: 500;\n  line-height: 1;\n  letter-spacing: -0.02em;\n  font-variant-numeric: tabular-nums;\n  cursor: pointer;\n  transition: color 0.25s ease, background 0.25s ease;\n}\n.hb-xg9-seg:hover { color: #a1a1a1; }\n.hb-xg9-seg[aria-pressed=\"true\"] { color: #fff; background: color-mix(in srgb, var(--hb-xg9-c) 16%, transparent); }\n.hb-xg9-seg:focus-visible { outline: 2px solid var(--hb-xg9-c); outline-offset: 1px; }\n.hb-xg9-colon { font-family: var(--font-grotesk), var(--font-sans), sans-serif; font-size: 34px; color: #3a3a3a; line-height: 1; animation: hb-xg9-blink 1.2s steps(2, jump-none) infinite; }\n.hb-xg9-mer { display: inline-flex; padding: 3px; border: 1px solid #222; border-radius: 10px; background: #0f0f0f; width: max-content; }\n.hb-xg9-mer button {\n  position: relative;\n  min-width: 40px;\n  height: 26px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 7px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 11.5px;\n  font-weight: 600;\n  letter-spacing: 0.04em;\n  cursor: pointer;\n  transition: color 0.2s ease, background 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease;\n}\n.hb-xg9-mer button[aria-pressed=\"true\"] { color: #fff; background: linear-gradient(180deg, #262626, #1b1b1b); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 3px rgba(0, 0, 0, 0.6); }\n.hb-xg9-mer button:focus-visible { outline: 2px solid var(--hb-xg9-c); outline-offset: 1px; }\n.hb-xg9-cap { margin: 0; font-size: 11.5px; color: #6f6f6f; }\n.hb-xg9-cap b { font-weight: 500; color: #a1a1a1; }\n.hb-xg9-dial {\n  position: relative;\n  width: var(--hb-xg9-size);\n  height: var(--hb-xg9-size);\n  flex: none;\n  border-radius: 50%;\n  background:\n    radial-gradient(circle at 50% 50%, #0d0d0d 0 28%, transparent 29%),\n    radial-gradient(circle at 50% 35%, #1a1a1a, #101010 70%);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 0 0 1px #222, 0 18px 36px -18px rgba(0, 0, 0, 0.9);\n  touch-action: none;\n  user-select: none;\n  -webkit-user-select: none;\n  cursor: grab;\n  outline: 0;\n}\n.hb-xg9-dial:active { cursor: grabbing; }\n.hb-xg9-dial:focus-visible { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 0 0 1px #222, 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-xg9-c); }\n.hb-xg9-ticks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }\n.hb-xg9-ticks line { stroke: #2a2a2a; stroke-width: 1; }\n.hb-xg9-ticks line[data-major=\"true\"] { stroke: #3a3a3a; stroke-width: 1.4; }\n.hb-xg9-hand {\n  position: absolute;\n  left: 50%;\n  top: calc(50% - var(--hb-xg9-len));\n  width: 2px;\n  height: var(--hb-xg9-len);\n  margin-left: -1px;\n  border-radius: 2px;\n  background: linear-gradient(to top, color-mix(in srgb, var(--hb-xg9-c) 30%, transparent), var(--hb-xg9-c));\n  transform-origin: 50% 100%;\n  transform: rotate(var(--hb-xg9-rot));\n  transition: transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1), height 0.3s cubic-bezier(0.22, 1, 0.36, 1), top 0.3s cubic-bezier(0.22, 1, 0.36, 1);\n  pointer-events: none;\n}\n.hb-xg9[data-drag=\"true\"] .hb-xg9-hand { transition: height 0.3s ease, top 0.3s ease; }\n.hb-xg9-knob {\n  position: absolute;\n  left: 50%;\n  top: -15px;\n  width: 30px;\n  height: 30px;\n  margin-left: -15px;\n  border-radius: 50%;\n  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--hb-xg9-c) 65%, #fff), var(--hb-xg9-c) 70%);\n  box-shadow: 0 6px 16px -4px color-mix(in srgb, var(--hb-xg9-c) 70%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.35);\n}\n.hb-xg9-knob[data-off=\"true\"] { width: 10px; height: 10px; top: -5px; margin-left: -5px; }\n.hb-xg9-hub { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--hb-xg9-c); box-shadow: 0 0 0 3px #0d0d0d; pointer-events: none; }\n.hb-xg9-nums { position: absolute; inset: 0; pointer-events: none; animation: hb-xg9-swap 0.4s cubic-bezier(0.22, 1, 0.36, 1); }\n.hb-xg9-num {\n  position: absolute;\n  width: 28px;\n  height: 28px;\n  margin: -14px 0 0 -14px;\n  display: grid;\n  place-items: center;\n  font-size: 12.5px;\n  font-weight: 500;\n  color: #a1a1a1;\n  font-variant-numeric: tabular-nums;\n  transition: color 0.2s ease;\n}\n.hb-xg9-num[data-inner=\"true\"] { font-size: 10.5px; color: #6f6f6f; }\n.hb-xg9-num[data-on=\"true\"] { color: #fff; font-weight: 600; }\n.hb-xg9-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n@keyframes hb-xg9-swap { from { opacity: 0; transform: scale(1.12); } }\n@keyframes hb-xg9-blink { 50% { opacity: 0.35; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xg9 *, .hb-xg9-nums { transition: none !important; animation: none !important; }\n}\n`;\n\nfunction pad(n: number) {\n  return String(n).padStart(2, \"0\");\n}\n\nfunction parse(v: string) {\n  const r = /^(\\d{1,2}):(\\d{2})$/.exec(v.trim());\n  if (!r) return { h: 9, m: 0 };\n  return { h: Math.min(23, Number(r[1])), m: Math.min(59, Number(r[2])) };\n}\n\nexport function InputTimePicker({\n  label = \"Start time\",\n  value,\n  defaultValue = \"09:30\",\n  onChange,\n  hourCycle = 12,\n  step = 5,\n  size = 176,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: InputTimePickerProps) {\n  const id = React.useId();\n  const dialRef = React.useRef<HTMLDivElement>(null);\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState(defaultValue);\n  const { h, m } = parse(controlled ? value : inner);\n  const [mode, setMode] = React.useState<\"hour\" | \"minute\">(\"hour\");\n  const [drag, setDrag] = React.useState(false);\n  const [rot, setRot] = React.useState(() => ((parse(value ?? defaultValue).h % 12) * 30));\n\n  const isInner = hourCycle === 24 && (h === 0 || h > 12);\n  const target = mode === \"hour\" ? (h % 12) * 30 : m * 6;\n  const norm = ((rot % 360) + 360) % 360;\n  const shownRot = Math.abs(norm - target) < 0.01 ? rot : rot + ((((target - norm) % 360) + 540) % 360) - 180;\n\n  function aim(deg: number) {\n    setRot((r) => r + ((((deg - r) % 360) + 540) % 360) - 180);\n  }\n\n  function emit(nh: number, nm: number) {\n    const v = `${pad(nh)}:${pad(nm)}`;\n    if (!controlled) setInner(v);\n    onChange?.(v);\n  }\n\n  function setHour(nh: number) {\n    const hh = ((nh % 24) + 24) % 24;\n    emit(hh, m);\n    if (mode === \"hour\") aim((hh % 12) * 30);\n  }\n\n  function setMinute(nm: number) {\n    const mm = ((nm % 60) + 60) % 60;\n    emit(h, mm);\n    if (mode === \"minute\") aim(mm * 6);\n  }\n\n  function switchMode(next: \"hour\" | \"minute\") {\n    setMode(next);\n    aim(next === \"hour\" ? (h % 12) * 30 : m * 6);\n  }\n\n  function fromPointer(e: React.PointerEvent, snap: boolean) {\n    const el = dialRef.current;\n    if (!el) return;\n    const r = el.getBoundingClientRect();\n    const dx = e.clientX - (r.left + r.width / 2);\n    const dy = e.clientY - (r.top + r.height / 2);\n    const deg = ((Math.atan2(dx, -dy) * 180) / Math.PI + 360) % 360;\n    const dist = Math.hypot(dx, dy) / (r.width / 2);\n    if (mode === \"hour\") {\n      let idx = Math.round(deg / 30) % 12;\n      const innerRing = hourCycle === 24 && dist < 0.62;\n      if (hourCycle === 24) idx = innerRing ? (idx === 0 ? 0 : idx + 12) : idx === 0 ? 12 : idx;\n      else {\n        const pm = h >= 12;\n        idx = (idx === 0 ? 0 : idx) + (pm ? 12 : 0);\n      }\n      emit(idx, m);\n      aim((idx % 12) * 30);\n    } else {\n      let mm = Math.round(deg / 6) % 60;\n      if (snap) mm = (Math.round(mm / step) * step) % 60;\n      emit(h, mm);\n      aim(mm * 6);\n    }\n  }\n\n  function onKey(e: React.KeyboardEvent) {\n    const up = e.key === \"ArrowUp\" || e.key === \"ArrowRight\";\n    const down = e.key === \"ArrowDown\" || e.key === \"ArrowLeft\";\n    if (up || down) {\n      e.preventDefault();\n      if (mode === \"hour\") setHour(h + (up ? 1 : -1));\n      else setMinute(m + (up ? 1 : -1) * (e.shiftKey ? step : 1));\n    } else if (e.key === \"PageUp\" || e.key === \"PageDown\") {\n      e.preventDefault();\n      if (mode === \"minute\") setMinute(m + (e.key === \"PageUp\" ? step : -step));\n      else setHour(h + (e.key === \"PageUp\" ? 3 : -3));\n    } else if (e.key === \"Enter\") {\n      e.preventDefault();\n      switchMode(mode === \"hour\" ? \"minute\" : \"hour\");\n    }\n  }\n\n  const half = size / 2;\n  const outerR = half - 22;\n  const innerR = half * 0.46;\n  const hourNums =\n    hourCycle === 24\n      ? [...Array.from({ length: 12 }, (_, i) => ({ n: i === 0 ? 12 : i, r: outerR, inner: false })), ...Array.from({ length: 12 }, (_, i) => ({ n: i === 0 ? 0 : i + 12, r: innerR, inner: true }))]\n      : Array.from({ length: 12 }, (_, i) => ({ n: i === 0 ? 12 : i, r: outerR, inner: false }));\n  const minNums = Array.from({ length: 12 }, (_, i) => ({ n: i * 5, r: outerR, inner: false }));\n  const nums = mode === \"hour\" ? hourNums : minNums;\n  const len = mode === \"hour\" && isInner ? innerR : outerR;\n  const h12 = h % 12 === 0 ? 12 : h % 12;\n  const shownHour = hourCycle === 12 ? h12 : h;\n  const offStep = mode === \"minute\" && m % 5 !== 0;\n\n  const vars = {\n    \"--hb-xg9-c\": accent,\n    \"--hb-xg9-size\": `${size}px`,\n    \"--hb-xg9-rot\": `${shownRot.toFixed(2)}deg`,\n    \"--hb-xg9-len\": `${len.toFixed(1)}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div className={`hb-xg9 ${className}`} style={vars} data-drag={drag} role=\"group\" aria-labelledby={`${id}-l`} {...rest}>\n      <style href=\"hb-input-time-picker\" precedence=\"default\">{css}</style>\n      <div className=\"hb-xg9-side\">\n        <p className=\"hb-xg9-label\" id={`${id}-l`}>\n          {label}\n        </p>\n        <div className=\"hb-xg9-read\">\n          <button type=\"button\" className=\"hb-xg9-seg\" aria-pressed={mode === \"hour\"} aria-label={`Hour ${shownHour}, edit`} onClick={() => switchMode(\"hour\")}>\n            {pad(shownHour)}\n          </button>\n          <span className=\"hb-xg9-colon\" aria-hidden=\"true\">\n            :\n          </span>\n          <button type=\"button\" className=\"hb-xg9-seg\" aria-pressed={mode === \"minute\"} aria-label={`Minute ${m}, edit`} onClick={() => switchMode(\"minute\")}>\n            {pad(m)}\n          </button>\n        </div>\n        {hourCycle === 12 && (\n          <div className=\"hb-xg9-mer\" role=\"group\" aria-label=\"AM or PM\">\n            <button type=\"button\" aria-pressed={h < 12} onClick={() => h >= 12 && emit(h - 12, m)}>\n              AM\n            </button>\n            <button type=\"button\" aria-pressed={h >= 12} onClick={() => h < 12 && emit(h + 12, m)}>\n              PM\n            </button>\n          </div>\n        )}\n        <p className=\"hb-xg9-cap\">\n          {mode === \"hour\" ? (\n            <>\n              Drag to set the <b>hour</b>\n            </>\n          ) : (\n            <>\n              Snaps to <b>{step} min</b>, arrows for 1\n            </>\n          )}\n        </p>\n      </div>\n      <div\n        ref={dialRef}\n        className=\"hb-xg9-dial\"\n        role=\"slider\"\n        tabIndex={0}\n        aria-label={mode === \"hour\" ? \"Hour\" : \"Minute\"}\n        aria-valuemin={mode === \"hour\" ? (hourCycle === 12 ? 1 : 0) : 0}\n        aria-valuemax={mode === \"hour\" ? (hourCycle === 12 ? 12 : 23) : 59}\n        aria-valuenow={mode === \"hour\" ? shownHour : m}\n        aria-valuetext={`${pad(shownHour)}:${pad(m)}${hourCycle === 12 ? (h < 12 ? \" AM\" : \" PM\") : \"\"}`}\n        onKeyDown={onKey}\n        onPointerDown={(e) => {\n          if (e.button !== 0) return;\n          e.currentTarget.setPointerCapture(e.pointerId);\n          e.currentTarget.focus();\n          setDrag(true);\n          fromPointer(e, true);\n        }}\n        onPointerMove={(e) => {\n          if (drag) fromPointer(e, true);\n        }}\n        onPointerUp={() => {\n          if (!drag) return;\n          setDrag(false);\n          if (mode === \"hour\") switchMode(\"minute\");\n        }}\n        onPointerCancel={() => setDrag(false)}\n      >\n        <svg className=\"hb-xg9-ticks\" viewBox={`0 0 ${size} ${size}`} aria-hidden=\"true\">\n          {Array.from({ length: 60 }, (_, i) => {\n            const a = (i * 6 * Math.PI) / 180;\n            const major = i % 5 === 0;\n            const r1 = half - 4;\n            const r2 = half - (major ? 9 : 7);\n            return (\n              <line\n                key={i}\n                data-major={major}\n                x1={(half + Math.sin(a) * r1).toFixed(2)}\n                y1={(half - Math.cos(a) * r1).toFixed(2)}\n                x2={(half + Math.sin(a) * r2).toFixed(2)}\n                y2={(half - Math.cos(a) * r2).toFixed(2)}\n              />\n            );\n          })}\n        </svg>\n        <span className=\"hb-xg9-hand\" aria-hidden=\"true\">\n          <span className=\"hb-xg9-knob\" data-off={offStep} />\n        </span>\n        <span className=\"hb-xg9-hub\" aria-hidden=\"true\" />\n        <div className=\"hb-xg9-nums\" key={mode} aria-hidden=\"true\">\n          {nums.map((n, i) => {\n            const a = ((i % 12) * 30 * Math.PI) / 180;\n            const on = mode === \"hour\" ? (hourCycle === 12 ? n.n === h12 : n.n === h) : n.n === m;\n            return (\n              <span\n                key={`${n.n}-${n.inner}`}\n                className=\"hb-xg9-num\"\n                data-inner={n.inner}\n                data-on={on}\n                style={{ left: `${(half + Math.sin(a) * n.r).toFixed(2)}px`, top: `${(half - Math.cos(a) * n.r).toFixed(2)}px` }}\n              >\n                {mode === \"minute\" ? pad(n.n) : n.n}\n              </span>\n            );\n          })}\n        </div>\n      </div>\n      <span className=\"hb-xg9-sr\" aria-live=\"polite\">\n        {`${pad(shownHour)}:${pad(m)}${hourCycle === 12 ? (h < 12 ? \" AM\" : \" PM\") : \"\"}`}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}