{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "time-ring",
  "title": "Time Ring",
  "description": "A 24-hour dial for picking a time range, like a bedtime and wake-up schedule, with rolling digits, a tick per step, a deeper click per hour, and a thunk at the limits.",
  "dependencies": [
    "@number-flow/react",
    "@rexa-developer/tiks",
    "lucide-react",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/time-ring/time-ring.tsx",
      "content": "\"use client\";\n\nimport NumberFlow, { NumberFlowGroup } from \"@number-flow/react\";\nimport { defineTheme } from \"@rexa-developer/tiks\";\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport { Moon, Sun } from \"lucide-react\";\nimport {\n\ttype AnimationPlaybackControls,\n\tanimate,\n\ttype MotionValue,\n\tmotion,\n\tuseMotionValue,\n\tuseReducedMotion,\n\tuseTransform,\n} from \"motion/react\";\nimport {\n\ttype KeyboardEvent,\n\ttype PointerEvent,\n\ttype ReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst DAY = 1440;\nconst HOUR = 60;\n\nconst snapSpring = { type: \"spring\", stiffness: 600, damping: 40 } as const;\nconst digitTiming = {\n\tduration: 450,\n\teasing: \"cubic-bezier(.2,.8,.2,1)\",\n} as const;\n\n/** Hour clicks and limit thunks: the same tiks sounds, a little lower. */\nconst deepTheme = defineTheme({\n\tname: \"time-ring-deep\",\n\tbaseFreq: 300,\n\tfilterFreq: 1400,\n\tfilterQ: 1.4,\n\tdecay: 1.5,\n});\n\n/** The dial is drawn on a 200 x 200 grid and scales to its container. */\nconst VIEW = 200;\nconst CENTER = VIEW / 2;\nconst TRACK_WIDTH = 24;\nconst TRACK_RADIUS = CENTER - TRACK_WIDTH / 2 - 1;\nconst ARC_WIDTH = TRACK_WIDTH - 3;\nconst HANDLE_SIZE = ARC_WIDTH - 3;\nconst TICK_OUTER = TRACK_RADIUS - TRACK_WIDTH / 2 - 4;\nconst LABEL_RADIUS = TICK_OUTER - 18;\n/** Extra reach, in grid units, around the track and handles for presses. */\nconst HIT_SLOP = 8;\nconst HANDLE_HIT = HANDLE_SIZE / 2 + HIT_SLOP;\n/** Pointer travel, in px, before a press becomes a drag. */\nconst DRAG_SLOP = 3;\n/** Extra travel, in steps, before a drag leaves its current step. */\nconst HYSTERESIS = 0.08;\n/** Minimum ms between step sounds and haptics. */\nconst CUE_THROTTLE_MS = 35;\n\nconst sizes = {\n\tsm: 240,\n\tmd: 288,\n\tlg: 336,\n} as const;\n\nconst steps = [5, 15, 30] as const;\n\ntype Part = \"start\" | \"end\";\ntype DragPart = Part | \"arc\";\n\nexport interface TimeRingValue {\n\t/** Minutes from midnight, 0 to 1439. */\n\tstart: number;\n\t/** Minutes from midnight, 0 to 1439. Before `start` means the next day. */\n\tend: number;\n}\n\nexport interface TimeRingProps {\n\t/** Controlled range, in minutes from midnight. */\n\tvalue?: TimeRingValue;\n\t/** Initial range when uncontrolled. */\n\tdefaultValue?: TimeRingValue;\n\t/** Called every time either end lands on a new step. */\n\tonValueChange?: (value: TimeRingValue) => void;\n\t/** Minutes each end snaps to. */\n\tstep?: (typeof steps)[number];\n\t/** Shortest range in minutes. Defaults to one `step`. */\n\tminDuration?: number;\n\t/** Longest range in minutes. Defaults to a day less one `step`. */\n\tmaxDuration?: number;\n\t/** Clock used for the times, labels, and `aria-valuetext`. */\n\tformat?: \"12h\" | \"24h\";\n\t/** Icon on the start handle. */\n\tstartIcon?: ReactNode;\n\t/** Icon on the end handle. */\n\tendIcon?: ReactNode;\n\t/** Accessible name of the start handle, also used in its `aria-valuetext`. */\n\tstartLabel?: string;\n\t/** Accessible name of the end handle, also used in its `aria-valuetext`. */\n\tendLabel?: string;\n\t/** Play a tick per step, a deeper click per hour, and a thunk at the limits. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n\t/** Largest diameter. The ring shrinks to fit narrower containers. */\n\tsize?: keyof typeof sizes;\n\tdisabled?: boolean;\n\t/** Submits `start` and `end` with a native form as `name[start]` and `name[end]`. */\n\tname?: string;\n\t\"aria-label\"?: string;\n\t\"aria-labelledby\"?: string;\n\tclassName?: string;\n}\n\nfunction clamp(value: number, min: number, max: number) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\n/** Wraps minutes into 0..1439. */\nfunction wrapDay(minutes: number) {\n\treturn ((minutes % DAY) + DAY) % DAY;\n}\n\n/** Wraps a minute difference into -720..719. */\nfunction wrapDelta(minutes: number) {\n\treturn wrapDay(minutes + DAY / 2) - DAY / 2;\n}\n\nfunction durationOf({ start, end }: TimeRingValue) {\n\treturn wrapDay(end - start);\n}\n\n/** A point on a circle around the center, clockwise from midnight at the top. */\nfunction pointAt(minutes: number, radius: number) {\n\tconst angle = (minutes / DAY) * Math.PI * 2;\n\t// Rounded so server and client render the same attributes.\n\treturn [\n\t\tNumber((CENTER + radius * Math.sin(angle)).toFixed(3)),\n\t\tNumber((CENTER - radius * Math.cos(angle)).toFixed(3)),\n\t];\n}\n\nfunction formatTime(minutes: number, format: \"12h\" | \"24h\") {\n\tconst hours = Math.floor(minutes / HOUR);\n\tconst mins = String(minutes % HOUR).padStart(2, \"0\");\n\tif (format === \"24h\") return `${String(hours).padStart(2, \"0\")}:${mins}`;\n\treturn `${hours % 12 || 12}:${mins} ${hours < 12 ? \"AM\" : \"PM\"}`;\n}\n\nfunction formatDuration(minutes: number) {\n\tconst hours = Math.floor(minutes / HOUR);\n\tconst mins = minutes % HOUR;\n\tif (!hours) return `${mins} min`;\n\treturn mins ? `${hours} hr ${mins} min` : `${hours} hr`;\n}\n\nfunction hourLabel(hour: number, format: \"12h\" | \"24h\") {\n\tif (format === \"24h\") return String(hour).padStart(2, \"0\");\n\tconst short = hour % 12 || 12;\n\treturn hour % 6 === 0 ? `${short}${hour < 12 ? \"AM\" : \"PM\"}` : String(short);\n}\n\n/** True if moving `delta` minutes from `from` passes or lands on a whole hour. */\nfunction crossesHour(from: number, delta: number) {\n\tif (delta > 0) {\n\t\treturn Math.floor((from + delta) / HOUR) > Math.floor(from / HOUR);\n\t}\n\treturn Math.ceil((from + delta) / HOUR) < Math.ceil(from / HOUR);\n}\n\nfunction arcPath(start: number, end: number) {\n\tconst sweep = wrapDay(end - start);\n\tif (sweep < 0.5) return \"\";\n\tconst [x0, y0] = pointAt(start, TRACK_RADIUS);\n\tconst [x1, y1] = pointAt(start + sweep, TRACK_RADIUS);\n\tconst large = sweep > DAY / 2 ? 1 : 0;\n\treturn `M ${x0} ${y0} A ${TRACK_RADIUS} ${TRACK_RADIUS} 0 ${large} 1 ${x1} ${y1}`;\n}\n\nexport function TimeRing({\n\tvalue: valueProp,\n\tdefaultValue,\n\tonValueChange,\n\tstep: stepProp = 5,\n\tminDuration,\n\tmaxDuration,\n\tformat = \"12h\",\n\tstartIcon,\n\tendIcon,\n\tstartLabel = \"Bedtime\",\n\tendLabel = \"Wake up\",\n\tsound = true,\n\thaptics = true,\n\tsize = \"md\",\n\tdisabled = false,\n\tname,\n\t\"aria-label\": ariaLabel,\n\t\"aria-labelledby\": ariaLabelledBy,\n\tclassName,\n}: TimeRingProps) {\n\tconst step: number = steps.includes(stepProp) ? stepProp : 5;\n\t// Limits sit on whole steps, and a range never covers the whole day.\n\tconst minRange = clamp(\n\t\tMath.ceil((minDuration ?? step) / step) * step || step,\n\t\tstep,\n\t\tDAY - step,\n\t);\n\tconst maxRange = clamp(\n\t\tMath.floor((maxDuration ?? DAY - step) / step) * step,\n\t\tminRange,\n\t\tDAY - step,\n\t);\n\n\tconst normalize = (range: TimeRingValue): TimeRingValue => {\n\t\tconst start = wrapDay(Math.round(range.start / step) * step || 0);\n\t\tconst end = wrapDay(Math.round(range.end / step) * step || 0);\n\t\tconst duration = clamp(wrapDay(end - start), minRange, maxRange);\n\t\treturn { start, end: wrapDay(start + duration) };\n\t};\n\n\tconst controlled = valueProp !== undefined;\n\tconst [internalValue, setInternalValue] = useState<TimeRingValue>(\n\t\t() => valueProp ?? defaultValue ?? { start: 23 * HOUR, end: 7 * HOUR },\n\t);\n\tconst value = normalize(controlled ? valueProp : internalValue);\n\tconst duration = durationOf(value);\n\tconst durationHours = Math.floor(duration / HOUR);\n\tconst durationMinutes = duration % HOUR;\n\tconst startText = formatTime(value.start, format);\n\tconst endText = formatTime(value.end, format);\n\n\tconst shouldReduceMotion = useReducedMotion() ?? false;\n\tconst { trigger: haptic } = useWebHaptics();\n\t// Sound stays on under reduced motion; only movement is reduced.\n\tconst { click: playTick } = useTiks({ respectReducedMotion: false });\n\tconst { click: playHour, toggle: playThunk } = useTiks({\n\t\ttheme: deepTheme,\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst durationId = useId();\n\tconst ringRef = useRef<HTMLDivElement>(null);\n\tconst handleRefs = useRef<Record<Part, HTMLDivElement | null>>({\n\t\tstart: null,\n\t\tend: null,\n\t});\n\tconst valueRef = useRef(value);\n\tconst lastCueAtRef = useRef(Number.NEGATIVE_INFINITY);\n\tconst [dragging, setDragging] = useState<DragPart | null>(null);\n\tconst dragRef = useRef<{\n\t\tpointerId: number;\n\t\tpart: DragPart;\n\t\tcenterX: number;\n\t\tcenterY: number;\n\t\tscale: number;\n\t\toriginX: number;\n\t\toriginY: number;\n\t\t/** Minutes between where the handle sits and where it was grabbed. */\n\t\toffset: number;\n\t\t/** Pointer minutes on the last move, for arc drags. */\n\t\tlastPointer: number;\n\t\t/** Unsnapped duration for handle drags, or unwrapped start for arc drags. */\n\t\traw: number;\n\t\t/** The arc's unwrapped start, snapped. */\n\t\tsnapped: number;\n\t\tmoved: boolean;\n\t} | null>(null);\n\n\tuseLayoutEffect(() => {\n\t\tvalueRef.current = value;\n\t});\n\n\t// Both ends are unwrapped minutes, so a spring across midnight takes the short way.\n\tconst startMinutes = useMotionValue(value.start);\n\tconst endMinutes = useMotionValue(value.start + duration);\n\tconst animationsRef = useRef<AnimationPlaybackControls[]>([]);\n\n\tconst springTo = useCallback(\n\t\t(target: MotionValue<number>, minutes: number) => {\n\t\t\tconst current = target.get();\n\t\t\tconst next = current + wrapDelta(minutes - current);\n\t\t\tif (shouldReduceMotion) {\n\t\t\t\ttarget.jump(next);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (next === current && target.getVelocity() === 0) return;\n\t\t\tanimationsRef.current.push(\n\t\t\t\tanimate(target, next, { ...snapSpring, restDelta: 0.01 }),\n\t\t\t);\n\t\t},\n\t\t[shouldReduceMotion],\n\t);\n\n\tuseEffect(() => {\n\t\tfor (const animation of animationsRef.current) animation.stop();\n\t\tanimationsRef.current = [];\n\t\tspringTo(startMinutes, value.start);\n\t\tspringTo(endMinutes, value.end);\n\t}, [value.start, value.end, springTo, startMinutes, endMinutes]);\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tfor (const animation of animationsRef.current) animation.stop();\n\t\t},\n\t\t[],\n\t);\n\n\tconst path = useTransform(() =>\n\t\tarcPath(startMinutes.get(), endMinutes.get()),\n\t);\n\tconst startRotate = useTransform(startMinutes, (m) => (m / DAY) * 360);\n\tconst endRotate = useTransform(endMinutes, (m) => (m / DAY) * 360);\n\tconst startCounter = useTransform(startRotate, (deg) => -deg);\n\tconst endCounter = useTransform(endRotate, (deg) => -deg);\n\n\tconst silent = () =>\n\t\ttypeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n\n\tconst thunk = () => {\n\t\tlastCueAtRef.current = performance.now();\n\t\tif (silent()) return;\n\t\tif (sound) playThunk(false);\n\t\tif (haptics) void haptic(\"medium\");\n\t};\n\n\t// Called only for user input, so first render and prop changes stay quiet.\n\tconst cue = (from: number, delta: number, atLimit: boolean) => {\n\t\tif (atLimit) {\n\t\t\tthunk();\n\t\t\treturn;\n\t\t}\n\t\tconst now = performance.now();\n\t\t// Whole hours always sound, so a fast drag still counts the hours.\n\t\tif (crossesHour(from, delta)) {\n\t\t\tlastCueAtRef.current = now;\n\t\t\tif (silent()) return;\n\t\t\tif (sound) playHour();\n\t\t\tif (haptics) void haptic(\"light\");\n\t\t\treturn;\n\t\t}\n\t\tif (now - lastCueAtRef.current < CUE_THROTTLE_MS) return;\n\t\tlastCueAtRef.current = now;\n\t\tif (silent()) return;\n\t\tif (sound) playTick();\n\t\tif (haptics) void haptic(\"selection\");\n\t};\n\n\tconst commit = (next: TimeRingValue) => {\n\t\tconst previous = valueRef.current;\n\t\tif (next.start === previous.start && next.end === previous.end) return;\n\t\tvalueRef.current = next;\n\t\tsetInternalValue(next);\n\t\tonValueChange?.(next);\n\t};\n\n\t/** Moves one handle so the range lasts `nextDuration`, with its cue. */\n\tconst resize = (part: Part, nextDuration: number) => {\n\t\tconst current = valueRef.current;\n\t\tconst currentDuration = durationOf(current);\n\t\tif (nextDuration === currentDuration) return false;\n\t\tconst atLimit = nextDuration === minRange || nextDuration === maxRange;\n\t\tif (part === \"end\") {\n\t\t\tcommit({ ...current, end: wrapDay(current.start + nextDuration) });\n\t\t\tcue(current.end, nextDuration - currentDuration, atLimit);\n\t\t} else {\n\t\t\tcommit({ ...current, start: wrapDay(current.end - nextDuration) });\n\t\t\tcue(current.start, currentDuration - nextDuration, atLimit);\n\t\t}\n\t\treturn true;\n\t};\n\n\t/** Snaps an unsnapped value, holding the current step until it's clearly left. */\n\tconst snap = (raw: number, current: number) =>\n\t\tMath.abs(raw - current) < step * (0.5 + HYSTERESIS)\n\t\t\t? current\n\t\t\t: Math.round(raw / step) * step;\n\n\tconst pointerMinutes = (\n\t\tevent: PointerEvent,\n\t\tdrag: { centerX: number; centerY: number; scale: number },\n\t) => {\n\t\tconst dx = (event.clientX - drag.centerX) / drag.scale;\n\t\tconst dy = (event.clientY - drag.centerY) / drag.scale;\n\t\t// Clockwise from midnight at the top.\n\t\tconst minutes = wrapDay((Math.atan2(dx, -dy) / (Math.PI * 2)) * DAY);\n\t\treturn { minutes, dx, dy };\n\t};\n\n\tconst handlePointerDown = (event: PointerEvent<HTMLDivElement>) => {\n\t\tif (disabled || event.button !== 0 || dragRef.current) return;\n\t\tconst ring = event.currentTarget;\n\t\tconst rect = ring.getBoundingClientRect();\n\t\tconst geometry = {\n\t\t\tcenterX: rect.left + rect.width / 2,\n\t\t\tcenterY: rect.top + rect.height / 2,\n\t\t\tscale: rect.width / VIEW || 1,\n\t\t};\n\t\tconst { minutes, dx, dy } = pointerMinutes(event, geometry);\n\t\tconst radius = Math.hypot(dx, dy);\n\t\tif (Math.abs(radius - TRACK_RADIUS) > TRACK_WIDTH / 2 + HIT_SLOP) return;\n\n\t\tconst current = valueRef.current;\n\t\tconst distanceTo = (handle: number) => {\n\t\t\tconst [x, y] = pointAt(handle, TRACK_RADIUS);\n\t\t\treturn Math.hypot(dx - (x - CENTER), dy - (y - CENTER));\n\t\t};\n\t\tconst toStart = distanceTo(current.start);\n\t\tconst toEnd = distanceTo(current.end);\n\t\tlet part: DragPart;\n\t\tif (Math.min(toStart, toEnd) <= HANDLE_HIT) {\n\t\t\tpart = toEnd < toStart ? \"end\" : \"start\";\n\t\t} else if (wrapDay(minutes - current.start) <= durationOf(current)) {\n\t\t\tpart = \"arc\";\n\t\t} else {\n\t\t\t// The bare track does nothing.\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\t\tring.setPointerCapture(event.pointerId);\n\t\thandleRefs.current[part === \"end\" ? \"end\" : \"start\"]?.focus({\n\t\t\tpreventScroll: true,\n\t\t});\n\t\tdragRef.current = {\n\t\t\tpointerId: event.pointerId,\n\t\t\tpart,\n\t\t\t...geometry,\n\t\t\toriginX: event.clientX,\n\t\t\toriginY: event.clientY,\n\t\t\toffset: part === \"arc\" ? 0 : wrapDelta(current[part] - minutes),\n\t\t\tlastPointer: minutes,\n\t\t\traw: part === \"arc\" ? current.start : durationOf(current),\n\t\t\tsnapped: current.start,\n\t\t\tmoved: false,\n\t\t};\n\t};\n\n\tconst handlePointerMove = (event: PointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\tif (!drag.moved) {\n\t\t\tconst travel = Math.hypot(\n\t\t\t\tevent.clientX - drag.originX,\n\t\t\t\tevent.clientY - drag.originY,\n\t\t\t);\n\t\t\tif (travel / drag.scale < DRAG_SLOP) return;\n\t\t\tdrag.moved = true;\n\t\t\tsetDragging(drag.part);\n\t\t}\n\n\t\tconst { minutes } = pointerMinutes(event, drag);\n\t\tconst current = valueRef.current;\n\n\t\tif (drag.part === \"arc\") {\n\t\t\t// The whole range follows the pointer around, keeping its length.\n\t\t\tdrag.raw += wrapDelta(minutes - drag.lastPointer);\n\t\t\tdrag.lastPointer = minutes;\n\t\t\tconst next = snap(drag.raw, drag.snapped);\n\t\t\tif (next === drag.snapped) return;\n\t\t\tconst delta = next - drag.snapped;\n\t\t\tdrag.snapped = next;\n\t\t\tconst length = durationOf(current);\n\t\t\tcommit({\n\t\t\t\tstart: wrapDay(next),\n\t\t\t\tend: wrapDay(next + length),\n\t\t\t});\n\t\t\tcue(current.start, delta, false);\n\t\t\treturn;\n\t\t}\n\n\t\t// The handle goes where the pointer is, read from the side it came from,\n\t\t// and waits at a limit until the pointer comes back around to it.\n\t\tconst target = wrapDay(minutes + drag.offset);\n\t\tconst candidate =\n\t\t\tdrag.part === \"end\"\n\t\t\t\t? wrapDay(target - current.start)\n\t\t\t\t: wrapDay(current.end - target);\n\t\tdrag.raw = clamp(\n\t\t\tdrag.raw + wrapDelta(candidate - drag.raw),\n\t\t\tminRange,\n\t\t\tmaxRange,\n\t\t);\n\t\tconst currentDuration = durationOf(current);\n\t\tresize(\n\t\t\tdrag.part,\n\t\t\tclamp(snap(drag.raw, currentDuration), minRange, maxRange),\n\t\t);\n\t};\n\n\tconst endDrag = (pointerId?: number) => {\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || (pointerId !== undefined && drag.pointerId !== pointerId)) {\n\t\t\treturn;\n\t\t}\n\t\tdragRef.current = null;\n\t\tconst ring = ringRef.current;\n\t\tif (ring?.hasPointerCapture(drag.pointerId)) {\n\t\t\tring.releasePointerCapture(drag.pointerId);\n\t\t}\n\t\tsetDragging(null);\n\t};\n\n\tconst handleKeyDown = (part: Part) => (event: KeyboardEvent) => {\n\t\tif (disabled) return;\n\t\t// Left and right follow the reading direction, like a native range input.\n\t\tconst rtl = getComputedStyle(event.currentTarget).direction === \"rtl\";\n\t\tconst amount = event.shiftKey ? HOUR : step;\n\t\tlet delta: number;\n\t\tswitch (event.key) {\n\t\t\tcase \"ArrowUp\":\n\t\t\t\tdelta = amount;\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowDown\":\n\t\t\t\tdelta = -amount;\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowRight\":\n\t\t\t\tdelta = rtl ? -amount : amount;\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowLeft\":\n\t\t\t\tdelta = rtl ? amount : -amount;\n\t\t\t\tbreak;\n\t\t\tcase \"PageUp\":\n\t\t\t\tdelta = HOUR;\n\t\t\t\tbreak;\n\t\t\tcase \"PageDown\":\n\t\t\t\tdelta = -HOUR;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tevent.preventDefault();\n\t\tconst currentDuration = durationOf(valueRef.current);\n\t\t// Moving the start later shortens the range; moving the end later lengthens it.\n\t\tconst nextDuration = clamp(\n\t\t\tpart === \"end\" ? currentDuration + delta : currentDuration - delta,\n\t\t\tminRange,\n\t\t\tmaxRange,\n\t\t);\n\t\tif (!resize(part, nextDuration) && !event.repeat) thunk();\n\t};\n\n\t// iOS can still scroll the page under a captured pointer; block it mid-drag.\n\tuseEffect(() => {\n\t\tconst ring = ringRef.current;\n\t\tif (!ring) return;\n\t\tconst onTouchMove = (event: TouchEvent) => {\n\t\t\tif (dragRef.current) event.preventDefault();\n\t\t};\n\t\tring.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n\t\treturn () => ring.removeEventListener(\"touchmove\", onTouchMove);\n\t}, []);\n\n\tconst endDragRef = useRef(endDrag);\n\tuseLayoutEffect(() => {\n\t\tendDragRef.current = endDrag;\n\t});\n\tuseEffect(() => {\n\t\tif (disabled) endDragRef.current();\n\t}, [disabled]);\n\n\t// Handles hang off a point at the center, sized in the dial's container\n\t// units, so turning them never grows the page's scroll area.\n\tconst handleSize = `${(HANDLE_SIZE / VIEW) * 100}cqw`;\n\tconst handleOffset = `${(-TRACK_RADIUS / VIEW) * 100}cqw`;\n\n\tconst renderHandle = (part: Part) => {\n\t\tconst minutes = value[part];\n\t\tconst label = part === \"start\" ? startLabel : endLabel;\n\t\tconst icon =\n\t\t\tpart === \"start\" ? (startIcon ?? <Moon />) : (endIcon ?? <Sun />);\n\t\treturn (\n\t\t\t<motion.div\n\t\t\t\tkey={part}\n\t\t\t\tclassName=\"pointer-events-none absolute top-1/2 left-1/2 size-0\"\n\t\t\t\tstyle={{ rotate: part === \"start\" ? startRotate : endRotate }}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={(node) => {\n\t\t\t\t\t\thandleRefs.current[part] = node;\n\t\t\t\t\t}}\n\t\t\t\t\trole=\"slider\"\n\t\t\t\t\ttabIndex={disabled ? -1 : 0}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\taria-valuemin={0}\n\t\t\t\t\taria-valuemax={DAY - step}\n\t\t\t\t\taria-valuenow={minutes}\n\t\t\t\t\taria-valuetext={`${label} ${formatTime(minutes, format)}`}\n\t\t\t\t\taria-describedby={durationId}\n\t\t\t\t\taria-disabled={disabled || undefined}\n\t\t\t\t\tdata-slot={`time-ring-${part}`}\n\t\t\t\t\tdata-state={dragging === part ? \"dragging\" : \"idle\"}\n\t\t\t\t\tonKeyDown={handleKeyDown(part)}\n\t\t\t\t\tclassName=\"-translate-1/2 pointer-events-auto absolute left-0 flex cursor-grab items-center justify-center rounded-full bg-background text-[var(--time-ring-accent)] shadow-[0_1px_2px_rgb(0_0_0/0.18),0_0_0_0.5px_rgb(0_0_0/0.04)] outline-none transition-transform duration-150 ease-out focus-visible:ring-3 focus-visible:ring-ring/50 data-[state=dragging]:scale-110 group-data-disabled/time-ring:pointer-events-none motion-reduce:transition-none dark:bg-zinc-950\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\ttop: handleOffset,\n\t\t\t\t\t\twidth: handleSize,\n\t\t\t\t\t\theight: handleSize,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<motion.span\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\tclassName=\"flex size-[58%] items-center justify-center [&_svg]:size-full\"\n\t\t\t\t\t\tstyle={{ rotate: part === \"start\" ? startCounter : endCounter }}\n\t\t\t\t\t>\n\t\t\t\t\t\t{icon}\n\t\t\t\t\t</motion.span>\n\t\t\t\t</div>\n\t\t\t</motion.div>\n\t\t);\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"group\"\n\t\t\taria-label={ariaLabelledBy ? ariaLabel : (ariaLabel ?? \"Time range\")}\n\t\t\taria-labelledby={ariaLabelledBy}\n\t\t\tdata-slot=\"time-ring\"\n\t\t\tdata-size={size}\n\t\t\tdata-state={dragging ? \"dragging\" : \"idle\"}\n\t\t\tdata-disabled={disabled || undefined}\n\t\t\tclassName={cn(\n\t\t\t\t\"group/time-ring w-full select-none [--time-ring-accent:var(--color-orange-500)] data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\tstyle={{ maxWidth: sizes[size] }}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={ringRef}\n\t\t\t\tdata-slot=\"time-ring-dial\"\n\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\tonPointerMove={handlePointerMove}\n\t\t\t\tonPointerUp={(event) => endDrag(event.pointerId)}\n\t\t\t\tonPointerCancel={(event) => endDrag(event.pointerId)}\n\t\t\t\tonLostPointerCapture={(event) => endDrag(event.pointerId)}\n\t\t\t\tonContextMenu={(event) => event.preventDefault()}\n\t\t\t\tclassName=\"relative aspect-square w-full touch-none [-webkit-touch-callout:none] [container-type:inline-size] group-data-disabled/time-ring:pointer-events-none group-data-[state=dragging]/time-ring:cursor-grabbing\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\taria-hidden\n\t\t\t\t\tviewBox={`0 0 ${VIEW} ${VIEW}`}\n\t\t\t\t\tclassName=\"absolute inset-0 size-full overflow-visible\"\n\t\t\t\t>\n\t\t\t\t\t<circle\n\t\t\t\t\t\tdata-slot=\"time-ring-track\"\n\t\t\t\t\t\tcx={CENTER}\n\t\t\t\t\t\tcy={CENTER}\n\t\t\t\t\t\tr={TRACK_RADIUS}\n\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\tstrokeWidth={TRACK_WIDTH}\n\t\t\t\t\t\tclassName=\"stroke-zinc-100 dark:stroke-zinc-800/70\"\n\t\t\t\t\t/>\n\t\t\t\t\t<g data-slot=\"time-ring-ticks\">\n\t\t\t\t\t\t{Array.from({ length: 24 }, (_, hour) => {\n\t\t\t\t\t\t\tconst major = hour % 3 === 0;\n\t\t\t\t\t\t\tconst [x0, y0] = pointAt(hour * HOUR, TICK_OUTER);\n\t\t\t\t\t\t\tconst [x1, y1] = pointAt(\n\t\t\t\t\t\t\t\thour * HOUR,\n\t\t\t\t\t\t\t\tTICK_OUTER - (major ? 4 : 2.5),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<line\n\t\t\t\t\t\t\t\t\tkey={hour}\n\t\t\t\t\t\t\t\t\tx1={x0}\n\t\t\t\t\t\t\t\t\ty1={y0}\n\t\t\t\t\t\t\t\t\tx2={x1}\n\t\t\t\t\t\t\t\t\ty2={y1}\n\t\t\t\t\t\t\t\t\tstrokeWidth={major ? 1.25 : 1}\n\t\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\tmajor ? \"stroke-foreground/35\" : \"stroke-foreground/15\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t})}\n\t\t\t\t\t</g>\n\t\t\t\t\t<g data-slot=\"time-ring-labels\">\n\t\t\t\t\t\t{Array.from({ length: 8 }, (_, index) => {\n\t\t\t\t\t\t\tconst hour = index * 3;\n\t\t\t\t\t\t\tconst [x, y] = pointAt(hour * HOUR, LABEL_RADIUS);\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<text\n\t\t\t\t\t\t\t\t\tkey={hour}\n\t\t\t\t\t\t\t\t\tx={x}\n\t\t\t\t\t\t\t\t\ty={y}\n\t\t\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\t\t\tdominantBaseline=\"central\"\n\t\t\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\t\t\"fill-muted-foreground font-medium text-[8px] tabular-nums\",\n\t\t\t\t\t\t\t\t\t\thour % 6 !== 0 && \"fill-muted-foreground/70\",\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{hourLabel(hour, format)}\n\t\t\t\t\t\t\t\t</text>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t})}\n\t\t\t\t\t</g>\n\t\t\t\t\t<motion.path\n\t\t\t\t\t\tdata-slot=\"time-ring-arc\"\n\t\t\t\t\t\td={path}\n\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\tstrokeWidth={ARC_WIDTH}\n\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\tclassName=\"cursor-grab stroke-[var(--time-ring-accent)] group-data-[state=dragging]/time-ring:cursor-grabbing\"\n\t\t\t\t\t/>\n\t\t\t\t</svg>\n\n\t\t\t\t{renderHandle(\"start\")}\n\t\t\t\t{renderHandle(\"end\")}\n\n\t\t\t\t<div\n\t\t\t\t\taria-hidden\n\t\t\t\t\tdata-slot=\"time-ring-readout\"\n\t\t\t\t\tclassName=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-[1.5cqw] text-center\"\n\t\t\t\t>\n\t\t\t\t\t<NumberFlowGroup>\n\t\t\t\t\t\t<div className=\"flex items-baseline gap-[1.2cqw] font-semibold text-[length:10cqw] text-foreground tabular-nums leading-none tracking-tight\">\n\t\t\t\t\t\t\t{durationHours ? (\n\t\t\t\t\t\t\t\t<span className=\"flex items-baseline gap-[0.8cqw]\">\n\t\t\t\t\t\t\t\t\t<NumberFlow\n\t\t\t\t\t\t\t\t\t\tvalue={durationHours}\n\t\t\t\t\t\t\t\t\t\tanimated={!shouldReduceMotion}\n\t\t\t\t\t\t\t\t\t\trespectMotionPreference={false}\n\t\t\t\t\t\t\t\t\t\ttransformTiming={digitTiming}\n\t\t\t\t\t\t\t\t\t\tspinTiming={digitTiming}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<span className=\"font-medium text-[length:4.6cqw] text-muted-foreground tracking-normal\">\n\t\t\t\t\t\t\t\t\t\thr\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t{durationMinutes || !durationHours ? (\n\t\t\t\t\t\t\t\t<span className=\"flex items-baseline gap-[0.8cqw]\">\n\t\t\t\t\t\t\t\t\t<NumberFlow\n\t\t\t\t\t\t\t\t\t\tvalue={durationMinutes}\n\t\t\t\t\t\t\t\t\t\tanimated={!shouldReduceMotion}\n\t\t\t\t\t\t\t\t\t\trespectMotionPreference={false}\n\t\t\t\t\t\t\t\t\t\ttransformTiming={digitTiming}\n\t\t\t\t\t\t\t\t\t\tspinTiming={digitTiming}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<span className=\"font-medium text-[length:4.6cqw] text-muted-foreground tracking-normal\">\n\t\t\t\t\t\t\t\t\t\tmin\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</NumberFlowGroup>\n\t\t\t\t\t<p className=\"whitespace-nowrap font-medium text-[length:3.9cqw] text-muted-foreground tabular-nums leading-none\">\n\t\t\t\t\t\t{startText} – {endText}\n\t\t\t\t\t</p>\n\t\t\t\t</div>\n\t\t\t\t<span id={durationId} className=\"sr-only\">\n\t\t\t\t\t{formatDuration(duration)}\n\t\t\t\t</span>\n\t\t\t</div>\n\n\t\t\t{name ? (\n\t\t\t\t<>\n\t\t\t\t\t<input\n\t\t\t\t\t\ttype=\"hidden\"\n\t\t\t\t\t\tname={`${name}[start]`}\n\t\t\t\t\t\tvalue={value.start}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t/>\n\t\t\t\t\t<input\n\t\t\t\t\t\ttype=\"hidden\"\n\t\t\t\t\t\tname={`${name}[end]`}\n\t\t\t\t\t\tvalue={value.end}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) : null}\n\t\t</div>\n\t);\n}\n\nexport default TimeRing;\n",
      "type": "registry:component",
      "target": "@components/time-ring.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-11-01",
    "image": "https://cdn.tentui.com/images/components/time-ring",
    "video": "https://cdn.tentui.com/videos/components/time-ring"
  },
  "docs": "https://tentui.com/components/time-ring",
  "categories": [
    "inputs"
  ],
  "type": "registry:component"
}