{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "star-rating",
  "title": "Star Rating",
  "description": "A 1–5 star input you tap, sweep across, or arrow through, with a tick per star, half stars, and a pop when a pick lands.",
  "dependencies": [
    "@rexa-developer/tiks",
    "lucide-react",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/star-rating/star-rating.tsx",
      "content": "\"use client\";\n\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport { Star } from \"lucide-react\";\nimport {\n\tAnimatePresence,\n\ttype AnimationPlaybackControlsWithThen,\n\tanimate,\n\tmotion,\n\ttype Transition,\n\tuseReducedMotion,\n} from \"motion/react\";\nimport {\n\ttype KeyboardEvent,\n\ttype MouseEvent,\n\ttype PointerEvent,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst riseSpring = { type: \"spring\", stiffness: 500, damping: 18 } as const;\nconst pressSpring = { type: \"spring\", stiffness: 600, damping: 30 } as const;\n\n/** Ms the fill takes to slide to the pointer. */\nconst FILL_MS = 150;\n/** Ms between stars rising on a higher pick. */\nconst RISE_STAGGER_MS = 35;\n/** Ms between stars draining on a clear. */\nconst DRAIN_STAGGER_MS = 25;\n/** Minimum ms between star sounds and haptics. */\nconst CUE_THROTTLE_MS = 35;\n/** Px a touch travels before it counts as a sweep or a scroll. */\nconst TOUCH_SLOP = 8;\n/** Most stars a row can hold. */\nconst MAX_STARS = 10;\n\nconst sizes = {\n\tsm: { cell: \"w-6\", star: \"size-5\", caption: \"text-xs\" },\n\tmd: { cell: \"w-8\", star: \"size-7\", caption: \"text-sm\" },\n\tlg: { cell: \"w-10\", star: \"size-9\", caption: \"text-base\" },\n} as const;\n\ntype Gesture = {\n\tpointerId: number;\n\ttouch: boolean;\n\tstartX: number;\n\tstartY: number;\n\t/** Value when the press began. */\n\tstart: number;\n\t/** Value under the pointer when it went down. */\n\tpressed: number;\n\t/** Value the drag currently shows. */\n\tcurrent: number;\n\t/** Touch waits for `TOUCH_SLOP` px of travel to tell a sweep from a scroll. */\n\tintent: \"pending\" | \"rate\";\n\tsweeping: boolean;\n\tstar: number;\n};\n\nexport interface StarRatingProps {\n\t/** Controlled value, from 0 (empty) to `max`. */\n\tvalue?: number;\n\t/** Initial value when uncontrolled. */\n\tdefaultValue?: number;\n\t/** Called on every change, including each step of a sweep. */\n\tonValueChange?: (value: number) => void;\n\t/** Called once a pick lands: on release, a key press, or a clear. */\n\tonValueCommit?: (value: number) => void;\n\t/** Number of stars, up to 10. */\n\tmax?: number;\n\t/** Let the left half of a star rate x.5. */\n\tallowHalf?: boolean;\n\t/** Tapping the current value again, `Backspace` or `Delete` clears it. */\n\tclearable?: boolean;\n\t/** Show the value as a single image without interaction. */\n\treadOnly?: boolean;\n\tdisabled?: boolean;\n\t/** Caption per star, e.g. \"Poor\" to \"Excellent\". With `allowHalf`, pass one per half step to label halves too. */\n\tlabels?: string[];\n\tsize?: keyof typeof sizes;\n\t/** Play a click per star crossed and a pop when a pick lands. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n\t/** Submits the value with a native form through a hidden input. */\n\tname?: string;\n\t/** Accessible name for the group. */\n\t\"aria-label\"?: 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/** Snaps to the step on a whole-number grid so halves never drift. */\nfunction snapTo(value: number, step: number, max: number) {\n\tif (!Number.isFinite(value)) return 0;\n\tconst steps = Math.round(value / step);\n\treturn clamp(steps * step, 0, max);\n}\n\nfunction formatCount(value: number) {\n\treturn String(Number(value.toFixed(2)));\n}\n\nfunction starsLabel(value: number) {\n\treturn `${formatCount(value)} ${value === 1 ? \"star\" : \"stars\"}`;\n}\n\n/** How much of star `index` (0-based) a value fills, from 0 to 1. */\nfunction fillOf(value: number, index: number) {\n\treturn clamp(value - index, 0, 1);\n}\n\nexport function StarRating({\n\tvalue: valueProp,\n\tdefaultValue = 0,\n\tonValueChange,\n\tonValueCommit,\n\tmax: maxProp = 5,\n\tallowHalf = false,\n\tclearable = true,\n\treadOnly = false,\n\tdisabled = false,\n\tlabels,\n\tsize = \"md\",\n\tsound = true,\n\thaptics = true,\n\tname,\n\t\"aria-label\": ariaLabel = \"Rating\",\n\tclassName,\n}: StarRatingProps) {\n\tconst max = clamp(Math.round(maxProp), 1, MAX_STARS);\n\tconst step = allowHalf ? 0.5 : 1;\n\tconst steps = Math.round(max / step);\n\tconst interactive = !readOnly && !disabled;\n\n\t// Read-only shows any fraction; inputs snap to whole or half stars.\n\tconst snap = (raw: number) =>\n\t\treadOnly ? clamp(Number(raw.toFixed(2)), 0, max) : snapTo(raw, step, max);\n\n\tconst controlled = valueProp !== undefined;\n\tconst [internalValue, setInternalValue] = useState(() => snap(defaultValue));\n\tconst value = controlled ? snap(valueProp) : internalValue;\n\n\tconst [drag, setDrag] = useState<number | null>(null);\n\tconst [hover, setHover] = useState<number | null>(null);\n\tconst [phase, setPhase] = useState<\"idle\" | \"pressed\" | \"sweeping\">(\"idle\");\n\tconst [drainFrom, setDrainFrom] = useState(0);\n\n\t// The drag wins over the value prop while sweeping.\n\tconst display = drag ?? hover ?? value;\n\tconst previewing = drag === null && hover !== null && hover !== value;\n\tconst draining = display === 0 && drainFrom > 0;\n\n\tconst shouldReduceMotion = useReducedMotion() ?? false;\n\tconst { trigger: haptic } = useWebHaptics();\n\tconst {\n\t\tclick: playClick,\n\t\tpop: playPop,\n\t\tsuccess: playSuccess,\n\t\ttoggle: playToggle,\n\t} = useTiks({\n\t\t// Sound stays on under reduced motion; only movement is reduced.\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst rowRef = useRef<HTMLDivElement>(null);\n\tconst starRefs = useRef<(HTMLSpanElement | null)[]>([]);\n\tconst radioRefs = useRef<(HTMLSpanElement | null)[]>([]);\n\tconst starAnimations = useRef<(AnimationPlaybackControlsWithThen | null)[]>(\n\t\t[],\n\t);\n\tconst mountedRef = useRef(true);\n\tconst valueRef = useRef(value);\n\tconst gestureRef = useRef<Gesture | null>(null);\n\tconst lastCueAtRef = useRef(Number.NEGATIVE_INFINITY);\n\t// After a click, hold the hover preview until the pointer reaches another value.\n\tconst hoverHoldRef = useRef<number | null>(null);\n\n\tuseLayoutEffect(() => {\n\t\tif (!gestureRef.current) valueRef.current = value;\n\t});\n\n\tuseEffect(() => {\n\t\tmountedRef.current = true;\n\t\tconst animations = starAnimations.current;\n\t\treturn () => {\n\t\t\tmountedRef.current = false;\n\t\t\tfor (const animation of animations) animation?.stop();\n\t\t};\n\t}, []);\n\n\tconst crossCue = () => {\n\t\tconst now = performance.now();\n\t\tif (now - lastCueAtRef.current < CUE_THROTTLE_MS) return;\n\t\tlastCueAtRef.current = now;\n\t\tif (sound) playClick();\n\t\tif (haptics) void haptic(\"selection\");\n\t};\n\n\tconst commitCue = (next: number) => {\n\t\tlastCueAtRef.current = performance.now();\n\t\tif (next === 0) {\n\t\t\tif (sound) playToggle(false);\n\t\t\tif (haptics) void haptic(\"soft\");\n\t\t} else if (next === max) {\n\t\t\tif (sound) playSuccess();\n\t\t\tif (haptics) void haptic(\"success\");\n\t\t} else {\n\t\t\tif (sound) playPop();\n\t\t\tif (haptics) void haptic(\"success\");\n\t\t}\n\t};\n\n\tconst scaleStar = (index: number, scale: number, transition: Transition) => {\n\t\tconst star = starRefs.current[index];\n\t\tif (!star) return null;\n\t\tconst animation = animate(star, { scale }, transition);\n\t\tstarAnimations.current[index] = animation;\n\t\treturn animation;\n\t};\n\n\tconst dip = (index: number) => {\n\t\tif (!shouldReduceMotion) scaleStar(index, 0.9, pressSpring);\n\t};\n\n\tconst undip = (index: number) => {\n\t\tif (!shouldReduceMotion) scaleStar(index, 1, pressSpring);\n\t};\n\n\t// Rise to 1.2, then let the spring settle it back.\n\tconst rise = (index: number, delay: number) => {\n\t\tconst up = scaleStar(index, 1.2, {\n\t\t\tduration: 0.09,\n\t\t\tdelay,\n\t\t\tease: \"easeOut\",\n\t\t});\n\t\tvoid up?.then(() => {\n\t\t\t// Skip the settle if a newer animation took the star over.\n\t\t\tif (!mountedRef.current || starAnimations.current[index] !== up) return;\n\t\t\tscaleStar(index, 1, riseSpring);\n\t\t});\n\t};\n\n\tconst nudge = (index: number) => {\n\t\tconst out = scaleStar(index, 1.08, { duration: 0.07, ease: \"easeOut\" });\n\t\tvoid out?.then(() => {\n\t\t\tif (!mountedRef.current || starAnimations.current[index] !== out) return;\n\t\t\tscaleStar(index, 1, pressSpring);\n\t\t});\n\t};\n\n\t/** Animates the stars for a pick that moved the value from `prev` to `next`. */\n\tconst celebrate = (prev: number, next: number) => {\n\t\tif (shouldReduceMotion) return;\n\t\tif (next === 0) {\n\t\t\tsetDrainFrom(Math.ceil(prev));\n\t\t\treturn;\n\t\t}\n\t\tif (next > prev) {\n\t\t\tlet order = 0;\n\t\t\tfor (let index = 0; index < Math.ceil(next); index++) {\n\t\t\t\tif (fillOf(next, index) <= fillOf(prev, index)) continue;\n\t\t\t\trise(index, (order * RISE_STAGGER_MS) / 1000);\n\t\t\t\torder += 1;\n\t\t\t}\n\t\t} else if (next < prev) {\n\t\t\tnudge(Math.ceil(next) - 1);\n\t\t}\n\t};\n\n\tconst emit = (next: number) => {\n\t\tif (next > 0 && drainFrom !== 0) setDrainFrom(0);\n\t\tif (next === valueRef.current) return;\n\t\tvalueRef.current = next;\n\t\tif (!controlled) setInternalValue(next);\n\t\tonValueChange?.(next);\n\t};\n\n\tconst focusValue = (next: number) => {\n\t\tconst index = Math.max(Math.round(next / step) - 1, 0);\n\t\tradioRefs.current[index]?.focus({ preventScroll: true });\n\t};\n\n\t/** A pick from a tap, release, `Space`, or assistive tech. */\n\tconst pick = (next: number, start: number) => {\n\t\temit(next);\n\t\tif (next === start) return;\n\t\tcommitCue(next);\n\t\tcelebrate(start, next);\n\t\tonValueCommit?.(next);\n\t};\n\n\t/** A step from the keyboard: a click per star, no commit cue. */\n\tconst moveTo = (next: number) => {\n\t\tconst current = valueRef.current;\n\t\tif (next === current) return;\n\t\temit(next);\n\t\tif (next === 0) commitCue(0);\n\t\telse crossCue();\n\t\tcelebrate(current, next);\n\t\tonValueCommit?.(next);\n\t\tfocusValue(next);\n\t};\n\n\tconst isRtl = () =>\n\t\trowRef.current\n\t\t\t? getComputedStyle(rowRef.current).direction === \"rtl\"\n\t\t\t: false;\n\n\t/** Stars from the row's start edge to `clientX`, from 0 to `max`. */\n\tconst positionAt = (clientX: number) => {\n\t\tconst row = rowRef.current;\n\t\tif (!row) return 0;\n\t\tconst rect = row.getBoundingClientRect();\n\t\tconst offset = isRtl() ? rect.right - clientX : clientX - rect.left;\n\t\treturn clamp((offset / rect.width) * max, 0, max);\n\t};\n\n\tconst valueAt = (clientX: number) => {\n\t\t// The left half of a star rates x.5; anywhere on a star rates at least one step.\n\t\tconst position = positionAt(clientX);\n\t\treturn clamp(Math.ceil(position / step - 1e-9) * step, step, max);\n\t};\n\n\tconst starAt = (clientX: number) =>\n\t\tclamp(Math.floor(positionAt(clientX)), 0, max - 1);\n\n\tconst endGesture = (gesture: Gesture) => {\n\t\tgestureRef.current = null;\n\t\tundip(gesture.star);\n\t\tsetDrag(null);\n\t\tsetPhase(\"idle\");\n\t};\n\n\tconst startRating = (gesture: Gesture, target: HTMLElement, next: number) => {\n\t\tgesture.intent = \"rate\";\n\t\tif (!target.hasPointerCapture(gesture.pointerId)) {\n\t\t\ttarget.setPointerCapture(gesture.pointerId);\n\t\t}\n\t\tgesture.current = next;\n\t\tsetDrag(next);\n\t\temit(next);\n\t};\n\n\tconst handlePointerDown = (event: PointerEvent<HTMLDivElement>) => {\n\t\tif (!interactive || gestureRef.current) return;\n\t\tif (event.pointerType === \"mouse\" && event.button !== 0) return;\n\t\tconst touch = event.pointerType === \"touch\";\n\t\tconst pressed = valueAt(event.clientX);\n\t\tconst gesture: Gesture = {\n\t\t\tpointerId: event.pointerId,\n\t\t\ttouch,\n\t\t\tstartX: event.clientX,\n\t\t\tstartY: event.clientY,\n\t\t\tstart: valueRef.current,\n\t\t\tpressed,\n\t\t\tcurrent: valueRef.current,\n\t\t\tintent: \"pending\",\n\t\t\tsweeping: false,\n\t\t\tstar: starAt(event.clientX),\n\t\t};\n\t\tgestureRef.current = gesture;\n\t\thoverHoldRef.current = null;\n\t\tsetHover(null);\n\t\tsetPhase(\"pressed\");\n\t\tdip(gesture.star);\n\t\t// Touch waits to see if the page should scroll instead.\n\t\tif (!touch) startRating(gesture, event.currentTarget, pressed);\n\t};\n\n\tconst handlePointerMove = (event: PointerEvent<HTMLDivElement>) => {\n\t\tconst gesture = gestureRef.current;\n\t\tif (!gesture) {\n\t\t\tif (!interactive || event.pointerType !== \"mouse\") return;\n\t\t\tconst next = valueAt(event.clientX);\n\t\t\tif (hoverHoldRef.current !== null) {\n\t\t\t\tif (next === hoverHoldRef.current) return;\n\t\t\t\thoverHoldRef.current = null;\n\t\t\t}\n\t\t\tsetHover(next);\n\t\t\treturn;\n\t\t}\n\t\tif (event.pointerId !== gesture.pointerId) return;\n\t\tconst dx = event.clientX - gesture.startX;\n\t\tconst dy = event.clientY - gesture.startY;\n\t\tif (gesture.intent === \"pending\") {\n\t\t\t// A vertical swipe belongs to the page.\n\t\t\tif (Math.abs(dy) > TOUCH_SLOP && Math.abs(dy) > Math.abs(dx)) {\n\t\t\t\tendGesture(gesture);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (Math.abs(dx) <= TOUCH_SLOP) return;\n\t\t\tstartRating(gesture, event.currentTarget, gesture.pressed);\n\t\t}\n\t\tconst next = valueAt(event.clientX);\n\t\tif (next !== gesture.current) {\n\t\t\tif (Math.ceil(next) !== Math.ceil(gesture.current)) crossCue();\n\t\t\tgesture.current = next;\n\t\t\tgesture.sweeping = true;\n\t\t\tsetDrag(next);\n\t\t\tsetPhase(\"sweeping\");\n\t\t\temit(next);\n\t\t}\n\t\tconst star = starAt(event.clientX);\n\t\tif (star !== gesture.star) {\n\t\t\tundip(gesture.star);\n\t\t\tgesture.star = star;\n\t\t\tdip(star);\n\t\t}\n\t};\n\n\tconst handlePointerUp = (event: PointerEvent<HTMLDivElement>) => {\n\t\tconst gesture = gestureRef.current;\n\t\tif (!gesture || event.pointerId !== gesture.pointerId) return;\n\t\tendGesture(gesture);\n\t\tlet next = gesture.intent === \"pending\" ? gesture.pressed : gesture.current;\n\t\t// Tapping the current value again clears it.\n\t\tif (\n\t\t\tclearable &&\n\t\t\t!gesture.sweeping &&\n\t\t\tgesture.start > 0 &&\n\t\t\tgesture.pressed === gesture.start\n\t\t) {\n\t\t\tnext = 0;\n\t\t}\n\t\tif (!gesture.touch) hoverHoldRef.current = valueAt(event.clientX);\n\t\tpick(next, gesture.start);\n\t\tfocusValue(next);\n\t};\n\n\tconst handlePointerCancel = (event: PointerEvent<HTMLDivElement>) => {\n\t\tconst gesture = gestureRef.current;\n\t\tif (!gesture || event.pointerId !== gesture.pointerId) return;\n\t\tendGesture(gesture);\n\t\t// The browser took over, so the press never landed.\n\t\temit(gesture.start);\n\t};\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n\t\tif (!interactive || gestureRef.current) return;\n\t\tconst current = valueRef.current;\n\t\tconst forward = isRtl() ? -1 : 1;\n\t\tconst stepTo = (delta: number) => clamp(current + delta, step, max);\n\t\tlet next: number;\n\t\tswitch (event.key) {\n\t\t\tcase \"ArrowRight\":\n\t\t\t\tnext = stepTo(step * forward);\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowLeft\":\n\t\t\t\tnext = stepTo(-step * forward);\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowUp\":\n\t\t\t\tnext = stepTo(step);\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowDown\":\n\t\t\t\tnext = stepTo(-step);\n\t\t\t\tbreak;\n\t\t\tcase \"Home\":\n\t\t\t\tnext = step;\n\t\t\t\tbreak;\n\t\t\tcase \"End\":\n\t\t\t\tnext = max;\n\t\t\t\tbreak;\n\t\t\tcase \"Backspace\":\n\t\t\tcase \"Delete\":\n\t\t\t\tif (!clearable || current === 0) return;\n\t\t\t\tnext = 0;\n\t\t\t\tbreak;\n\t\t\tcase \" \": {\n\t\t\t\tconst target = event.target as HTMLElement;\n\t\t\t\tconst radioValue = Number(target.dataset.value);\n\t\t\t\tif (!Number.isFinite(radioValue)) return;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tpick(radioValue, current);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tevent.preventDefault();\n\t\tmoveTo(snapTo(next, step, max));\n\t};\n\n\t// Screen readers activate radios with a click of detail 0.\n\tconst handleRadioClick = (\n\t\tradioValue: number,\n\t\tevent: MouseEvent<HTMLSpanElement>,\n\t) => {\n\t\tif (!interactive || event.detail !== 0) return;\n\t\tpick(radioValue, valueRef.current);\n\t};\n\n\t// Disabling mid-press drops the press.\n\tuseEffect(() => {\n\t\tif (interactive) return;\n\t\tconst gesture = gestureRef.current;\n\t\tif (!gesture) return;\n\t\tgestureRef.current = null;\n\t\tsetDrag(null);\n\t\tsetPhase(\"idle\");\n\t}, [interactive]);\n\n\tconst sizeStyle = sizes[size];\n\tconst fillMs = shouldReduceMotion ? 0 : FILL_MS;\n\tconst litBeforeDrain = draining ? drainFrom : 0;\n\n\tconst caption = (() => {\n\t\tif (!labels?.length || display <= 0) return \"\";\n\t\tconst index =\n\t\t\tallowHalf && labels.length >= steps\n\t\t\t\t? Math.round(display / step) - 1\n\t\t\t\t: Math.ceil(display) - 1;\n\t\treturn labels[clamp(index, 0, labels.length - 1)] ?? \"\";\n\t})();\n\n\tconst renderStar = (index: number) => {\n\t\tconst fill = fillOf(display, index);\n\t\tconst delay =\n\t\t\tindex < litBeforeDrain\n\t\t\t\t? ((litBeforeDrain - 1 - index) * DRAIN_STAGGER_MS) / 1000\n\t\t\t\t: 0;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tref={(node) => {\n\t\t\t\t\tstarRefs.current[index] = node;\n\t\t\t\t}}\n\t\t\t\taria-hidden\n\t\t\t\tdata-slot=\"star-rating-icon\"\n\t\t\t\tdata-fill={fill === 1 ? \"full\" : fill > 0 ? \"half\" : \"empty\"}\n\t\t\t\tclassName={cn(\"relative block\", sizeStyle.star)}\n\t\t\t>\n\t\t\t\t<Star\n\t\t\t\t\tstrokeWidth={1.5}\n\t\t\t\t\tclassName=\"absolute inset-0 size-full fill-current text-muted-foreground/25\"\n\t\t\t\t/>\n\t\t\t\t<motion.span\n\t\t\t\t\tinitial={false}\n\t\t\t\t\tanimate={{ \"--star-rating-empty\": `${(1 - fill) * 100}%` }}\n\t\t\t\t\ttransition={{\n\t\t\t\t\t\tduration: fillMs / 1000,\n\t\t\t\t\t\tdelay: shouldReduceMotion ? 0 : delay,\n\t\t\t\t\t\tease: \"easeOut\",\n\t\t\t\t\t}}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\"absolute inset-0 text-amber-400 transition-opacity duration-150 [clip-path:inset(0_var(--star-rating-empty)_0_0)] rtl:[clip-path:inset(0_0_0_var(--star-rating-empty))]\",\n\t\t\t\t\t\tpreviewing && \"opacity-70\",\n\t\t\t\t\t)}\n\t\t\t\t>\n\t\t\t\t\t<Star strokeWidth={1.5} className=\"size-full fill-current\" />\n\t\t\t\t</motion.span>\n\t\t\t</span>\n\t\t);\n\t};\n\n\tconst renderRadio = (radioValue: number, half: \"start\" | \"end\" | null) => {\n\t\tconst index = Math.round(radioValue / step) - 1;\n\t\tconst checked = value === radioValue;\n\t\tconst tabbable = interactive && (checked || (value === 0 && index === 0));\n\t\treturn (\n\t\t\t<span\n\t\t\t\tkey={radioValue}\n\t\t\t\tref={(node) => {\n\t\t\t\t\tradioRefs.current[index] = node;\n\t\t\t\t}}\n\t\t\t\trole=\"radio\"\n\t\t\t\taria-checked={checked}\n\t\t\t\taria-label={starsLabel(radioValue)}\n\t\t\t\taria-disabled={disabled || undefined}\n\t\t\t\ttabIndex={tabbable ? 0 : -1}\n\t\t\t\tdata-value={radioValue}\n\t\t\t\tdata-slot=\"star-rating-radio\"\n\t\t\t\tonClick={(event) => handleRadioClick(radioValue, event)}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"absolute inset-y-0 outline-none\",\n\t\t\t\t\thalf === null && \"inset-x-0\",\n\t\t\t\t\thalf === \"start\" && \"start-0 w-1/2\",\n\t\t\t\t\thalf === \"end\" && \"end-0 w-1/2\",\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n\n\tconst stars = Array.from({ length: max }, (_, index) => index);\n\tconst captionNode = labels?.length ? (\n\t\t<div\n\t\t\tdata-slot=\"star-rating-caption\"\n\t\t\tclassName={cn(\"grid min-h-5 text-muted-foreground\", sizeStyle.caption)}\n\t\t>\n\t\t\t<AnimatePresence initial={false} mode=\"popLayout\">\n\t\t\t\t<motion.span\n\t\t\t\t\tkey={caption}\n\t\t\t\t\tinitial={{ opacity: 0 }}\n\t\t\t\t\tanimate={{ opacity: 1 }}\n\t\t\t\t\texit={{ opacity: 0 }}\n\t\t\t\t\ttransition={{ duration: 0.15, ease: \"easeOut\" }}\n\t\t\t\t\tclassName=\"col-start-1 row-start-1\"\n\t\t\t\t>\n\t\t\t\t\t{caption || \"\\u00A0\"}\n\t\t\t\t</motion.span>\n\t\t\t</AnimatePresence>\n\t\t</div>\n\t) : null;\n\tconst hiddenInput = name ? (\n\t\t<input\n\t\t\ttype=\"hidden\"\n\t\t\tname={name}\n\t\t\tvalue={value > 0 ? value : \"\"}\n\t\t\tdisabled={disabled}\n\t\t/>\n\t) : null;\n\n\tif (readOnly) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"star-rating\"\n\t\t\t\tdata-state=\"read-only\"\n\t\t\t\tdata-size={size}\n\t\t\t\tclassName={cn(\"inline-flex flex-col items-start gap-1\", className)}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label={`Rated ${formatCount(value)} out of ${max}`}\n\t\t\t\t\tclassName=\"flex\"\n\t\t\t\t>\n\t\t\t\t\t{stars.map((index) => (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\tclassName={cn(\"grid place-items-center\", sizeStyle.cell)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{renderStar(index)}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t\t{captionNode}\n\t\t\t\t{hiddenInput}\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst state =\n\t\tphase !== \"idle\"\n\t\t\t? phase\n\t\t\t: previewing\n\t\t\t\t? \"hover-preview\"\n\t\t\t\t: disabled\n\t\t\t\t\t? \"disabled\"\n\t\t\t\t\t: value > 0\n\t\t\t\t\t\t? \"selected\"\n\t\t\t\t\t\t: \"empty\";\n\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"star-rating\"\n\t\t\tdata-state={state}\n\t\t\tdata-size={size}\n\t\t\tdata-half={(value % 1 !== 0 && value > 0) || undefined}\n\t\t\tdata-disabled={disabled || undefined}\n\t\t\tclassName={cn(\n\t\t\t\t\"inline-flex flex-col items-start gap-1 data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={rowRef}\n\t\t\t\trole=\"radiogroup\"\n\t\t\t\taria-label={ariaLabel}\n\t\t\t\taria-disabled={disabled || undefined}\n\t\t\t\tdata-slot=\"star-rating-stars\"\n\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\tonPointerMove={handlePointerMove}\n\t\t\t\tonPointerUp={handlePointerUp}\n\t\t\t\tonPointerCancel={handlePointerCancel}\n\t\t\t\tonPointerLeave={() => {\n\t\t\t\t\thoverHoldRef.current = null;\n\t\t\t\t\tsetHover(null);\n\t\t\t\t}}\n\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\tonContextMenu={(event) => event.preventDefault()}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"flex touch-pan-y select-none [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none]\",\n\t\t\t\t\tinteractive && \"cursor-pointer\",\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{stars.map((index) => (\n\t\t\t\t\t<span\n\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\tdata-slot=\"star-rating-star\"\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"relative grid h-11 place-items-center rounded-md has-[[role=radio]:focus-visible]:ring-3 has-[[role=radio]:focus-visible]:ring-ring/50\",\n\t\t\t\t\t\t\tsizeStyle.cell,\n\t\t\t\t\t\t)}\n\t\t\t\t\t>\n\t\t\t\t\t\t{renderStar(index)}\n\t\t\t\t\t\t{allowHalf ? (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t{renderRadio(index + 0.5, \"start\")}\n\t\t\t\t\t\t\t\t{renderRadio(index + 1, \"end\")}\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\trenderRadio(index + 1, null)\n\t\t\t\t\t\t)}\n\t\t\t\t\t</span>\n\t\t\t\t))}\n\t\t\t</div>\n\t\t\t{captionNode}\n\t\t\t{hiddenInput}\n\t\t</div>\n\t);\n}\n\nexport default StarRating;\n",
      "type": "registry:component",
      "target": "@components/star-rating.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-10-25",
    "image": "https://cdn.tentui.com/images/components/star-rating",
    "video": "https://cdn.tentui.com/videos/components/star-rating"
  },
  "docs": "https://tentui.com/components/star-rating",
  "categories": [
    "inputs"
  ],
  "type": "registry:component"
}