{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "star-and-emoji-rating",
  "type": "registry:component",
  "title": "Star & Emoji Rating",
  "description": "Two ways to ask how it went: stars with half steps that pop when you pick, and a little face that morphs from grumpy to delighted as you slide across the scale.",
  "categories": [
    "component",
    "Forms"
  ],
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/devl/star-and-emoji-rating.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { AnimatePresence, motion, useMotionValue, useReducedMotion, useSpring, useTransform } from \"motion/react\";\nimport { type KeyboardEvent, type PointerEvent, useEffect, useId, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nconst STAR = (() => {\n  const pts: string[] = [];\n  for (let i = 0; i < 10; i++) {\n    const r = i % 2 === 0 ? 10 : 4.4;\n    const a = -Math.PI / 2 + (i * Math.PI) / 5;\n    pts.push(`${(12 + r * Math.cos(a)).toFixed(2)},${(12.6 + r * Math.sin(a)).toFixed(2)}`);\n  }\n  return pts.join(\" \");\n})();\n\nconst STAR_WORDS = [\"Not rated\", \"Awful\", \"Poor\", \"Okay\", \"Good\", \"Excellent\"];\n\nexport interface StarRatingProps {\n  value?: number;\n  defaultValue?: number;\n  onValueChange?: (value: number) => void;\n  max?: number;\n  half?: boolean;\n  size?: number;\n  readOnly?: boolean;\n  words?: string[] | false;\n  className?: string;\n  \"aria-label\"?: string;\n}\n\nexport function StarRating({\n  value: valueProp,\n  defaultValue = 0,\n  onValueChange,\n  max = 5,\n  half = true,\n  size = 28,\n  readOnly = false,\n  words = STAR_WORDS,\n  className,\n  \"aria-label\": ariaLabel = \"Rating\",\n}: StarRatingProps) {\n  const [inner, setInner] = useState(defaultValue);\n  const value = valueProp ?? inner;\n  const [hover, setHover] = useState<number | null>(null);\n  const [pop, setPop] = useState(0);\n  const reduce = useReducedMotion();\n  const step = half ? 0.5 : 1;\n  const shown = hover ?? value;\n\n  const commit = (next: number) => {\n    const v = next === value ? 0 : next;\n    if (valueProp === undefined) setInner(v);\n    onValueChange?.(v);\n    if (v > 0) setPop((p) => p + 1);\n  };\n\n  const valueAt = (event: PointerEvent<HTMLDivElement>) => {\n    const rect = event.currentTarget.getBoundingClientRect();\n    const raw = ((event.clientX - rect.left) / rect.width) * max;\n    return Math.min(max, Math.max(step, Math.ceil(raw / step) * step));\n  };\n\n  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    if (readOnly) return;\n    const keys: Record<string, number> = {\n      ArrowRight: value + step,\n      ArrowUp: value + step,\n      ArrowLeft: value - step,\n      ArrowDown: value - step,\n      Home: 0,\n      End: max,\n    };\n    if (!(event.key in keys)) return;\n    event.preventDefault();\n    const next = Math.min(max, Math.max(0, keys[event.key]));\n    if (valueProp === undefined) setInner(next);\n    onValueChange?.(next);\n    if (next > value) setPop((p) => p + 1);\n  };\n\n  const word = words ? words[Math.ceil(shown)] : null;\n\n  return (\n    <div className={cn(\"flex items-center gap-3\", className)}>\n      <div\n        aria-label={ariaLabel}\n        aria-readonly={readOnly || undefined}\n        aria-valuemax={max}\n        aria-valuemin={0}\n        aria-valuenow={value}\n        aria-valuetext={`${value} of ${max} stars`}\n        className={cn(\n          \"-m-1 flex touch-none rounded-lg p-1 outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n          !readOnly && \"cursor-pointer\",\n        )}\n        onKeyDown={onKeyDown}\n        onPointerLeave={() => setHover(null)}\n        onPointerMove={(event) => !readOnly && setHover(valueAt(event))}\n        onPointerUp={(event) => !readOnly && commit(valueAt(event))}\n        role=\"slider\"\n        tabIndex={readOnly ? -1 : 0}\n      >\n        {Array.from({ length: max }, (_, i) => {\n          const fill = Math.min(Math.max(shown - i, 0), 1);\n          const popping = !reduce && pop > 0 && hover === null && i < value;\n          return (\n            <motion.span\n              animate={popping ? { scale: [1, 1.15, 0.97, 1] } : { scale: 1 }}\n              className=\"relative block\"\n              key={popping ? `${i}-${pop}` : i}\n              style={{ width: size, height: size }}\n              transition={{ duration: 0.36, delay: i * 0.03, times: [0, 0.35, 0.7, 1], ease: \"easeOut\" }}\n            >\n              <svg aria-hidden className=\"absolute inset-0 size-full\" viewBox=\"0 0 24 24\">\n                <polygon className=\"fill-muted stroke-border\" points={STAR} strokeLinejoin=\"round\" strokeWidth={1.4} />\n              </svg>\n              <span\n                className=\"absolute inset-0 transition-[clip-path] duration-150 ease-out\"\n                style={{ clipPath: `inset(0 ${(1 - fill) * 100}% 0 0)` }}\n              >\n                <svg aria-hidden className=\"size-full\" viewBox=\"0 0 24 24\">\n                  <polygon\n                    className={cn(\n                      \"transition-colors duration-150\",\n                      hover !== null ? \"fill-amber-300 stroke-amber-300\" : \"fill-amber-400 stroke-amber-400\",\n                    )}\n                    points={STAR}\n                    strokeLinejoin=\"round\"\n                    strokeWidth={1.4}\n                  />\n                </svg>\n              </span>\n            </motion.span>\n          );\n        })}\n      </div>\n      {word && (\n        <span className=\"min-w-16 text-sm\">\n          <span className=\"font-medium tabular-nums\">{shown ? shown.toFixed(half ? 1 : 0) : \"–\"}</span>\n          <span className=\"text-muted-foreground\"> · {word}</span>\n        </span>\n      )}\n    </div>\n  );\n}\n\nconst MOODS = [\"Awful\", \"Not great\", \"Okay\", \"Good\", \"Love it\"];\n\nconst FACE = {\n  smile: [-7, -3, 0, 5, 9],\n  mouthW: [14, 13, 12, 16, 18],\n  open: [0, 0, 0, 0, 5],\n  eyeH: [2.6, 2.4, 2.6, 2.6, 0.9],\n  eyeY: [24, 24, 24, 23.5, 24],\n  brow: [16, 7, 0, -5, -9],\n  browY: [16.5, 17.5, 17, 16, 15],\n  hue: [28, 50, 80, 115, 145],\n  browOn: [1, 0.85, 0, 0, 0],\n};\n\nconst lerp = (arr: number[], t: number) => {\n  const i = Math.min(Math.max(Math.floor(t), 0), arr.length - 2);\n  const f = Math.min(Math.max(t - i, 0), 1);\n  return arr[i] + (arr[i + 1] - arr[i]) * f;\n};\n\nexport interface EmojiRatingProps {\n  value?: number | null;\n  defaultValue?: number | null;\n  onValueChange?: (value: number) => void;\n  labels?: string[];\n  className?: string;\n  \"aria-label\"?: string;\n}\n\nexport function EmojiRating({\n  value: valueProp,\n  defaultValue = null,\n  onValueChange,\n  labels = MOODS,\n  className,\n  \"aria-label\": ariaLabel = \"How did it go?\",\n}: EmojiRatingProps) {\n  const [inner, setInner] = useState<number | null>(defaultValue);\n  const value = valueProp === undefined ? inner : valueProp;\n  const reduce = useReducedMotion();\n  const id = useId();\n  const target = useMotionValue(value ?? 2);\n  const mood = useSpring(target, { stiffness: 260, damping: 22 });\n\n  useEffect(() => {\n    const next = value ?? 2;\n    if (reduce) {\n      target.jump(next);\n      mood.jump(next);\n    } else target.set(next);\n  }, [value, reduce, target, mood]);\n\n  const mouth = useTransform(mood, (m) => {\n    const w = lerp(FACE.mouthW, m);\n    const s = lerp(FACE.smile, m);\n    const o = lerp(FACE.open, m);\n    const y = 33.5 - s * 0.25;\n    return `M ${24 - w / 2} ${y} Q 24 ${y + s} ${24 + w / 2} ${y} Q 24 ${y + s + o * 1.6} ${24 - w / 2} ${y} Z`;\n  });\n  const eyeRy = useTransform(mood, (m) => lerp(FACE.eyeH, m));\n  const eyeY = useTransform(mood, (m) => lerp(FACE.eyeY, m));\n  const browL = useTransform(mood, (m) => `rotate(${lerp(FACE.brow, m)} 17 ${lerp(FACE.browY, m)})`);\n  const browR = useTransform(mood, (m) => `rotate(${-lerp(FACE.brow, m)} 31 ${lerp(FACE.browY, m)})`);\n  const browY = useTransform(mood, (m) => lerp(FACE.browY, m));\n  const fill = useTransform(mood, (m) => `oklch(0.86 0.12 ${lerp(FACE.hue, m)})`);\n  const cheeks = useTransform(mood, [2.6, 4], [0, 0.45]);\n  const brows = useTransform(mood, (m) => lerp(FACE.browOn, m));\n\n  const set = (next: number) => {\n    if (valueProp === undefined) setInner(next);\n    onValueChange?.(next);\n  };\n\n  return (\n    <div className={cn(\"grid justify-items-center gap-3\", className)}>\n      <svg aria-hidden className={cn(\"size-16 transition-opacity duration-200\", value === null && \"opacity-60\")} viewBox=\"0 0 48 48\">\n        <motion.circle cx={24} cy={24} r={22} style={{ fill }} />\n        <motion.ellipse className=\"fill-rose-400\" cx={11.5} cy={29} rx={2.8} ry={1.7} style={{ opacity: cheeks }} />\n        <motion.ellipse className=\"fill-rose-400\" cx={36.5} cy={29} rx={2.8} ry={1.7} style={{ opacity: cheeks }} />\n        <motion.line className=\"stroke-neutral-800\" strokeLinecap=\"round\" strokeWidth={2} style={{ opacity: brows }} transform={browL} x1={13.5} x2={20.5} y1={browY} y2={browY} />\n        <motion.line className=\"stroke-neutral-800\" strokeLinecap=\"round\" strokeWidth={2} style={{ opacity: brows }} transform={browR} x1={27.5} x2={34.5} y1={browY} y2={browY} />\n        <motion.ellipse className=\"fill-neutral-800\" cx={17} cy={eyeY} rx={2.2} ry={eyeRy} />\n        <motion.ellipse className=\"fill-neutral-800\" cx={31} cy={eyeY} rx={2.2} ry={eyeRy} />\n        <motion.path className=\"fill-neutral-800 stroke-neutral-800\" d={mouth} strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth={2} />\n      </svg>\n      <div aria-label={ariaLabel} className=\"flex gap-1 rounded-full bg-muted p-1\" role=\"radiogroup\">\n        {labels.map((label, i) => {\n          const checked = value === i;\n          return (\n            <button\n              aria-checked={checked}\n              aria-label={label}\n              className=\"relative flex size-8 cursor-pointer items-center justify-center rounded-full outline-none transition-[scale] duration-150 ease-out focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.94]\"\n              key={label}\n              onClick={() => set(i)}\n              onKeyDown={(event) => {\n                const d = event.key === \"ArrowRight\" || event.key === \"ArrowDown\" ? 1 : event.key === \"ArrowLeft\" || event.key === \"ArrowUp\" ? -1 : 0;\n                if (!d) return;\n                event.preventDefault();\n                const next = Math.min(labels.length - 1, Math.max(0, (value ?? 2) + d));\n                set(next);\n                (event.currentTarget.parentElement?.children[next] as HTMLElement | undefined)?.focus();\n              }}\n              role=\"radio\"\n              tabIndex={checked || (value === null && i === 2) ? 0 : -1}\n              type=\"button\"\n            >\n              {checked && (\n                <motion.span\n                  className=\"absolute inset-0 rounded-full bg-background shadow-xs/5 ring-1 ring-border dark:bg-input\"\n                  layoutId={`${id}-pick`}\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 36 }}\n                />\n              )}\n              <span\n                className={cn(\n                  \"relative size-2 rounded-full transition-[background-color,scale] duration-150\",\n                  checked ? \"scale-125 bg-primary\" : \"bg-muted-foreground/48\",\n                )}\n              />\n            </button>\n          );\n        })}\n      </div>\n      <div className=\"relative h-5 w-full overflow-hidden text-center text-sm\">\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          <motion.span\n            animate={{ opacity: 1, y: 0 }}\n            className={cn(\"absolute inset-x-0\", value === null ? \"text-muted-foreground\" : \"font-medium\")}\n            exit={{ opacity: 0, y: -8 }}\n            initial={reduce ? { opacity: 0 } : { opacity: 0, y: 8 }}\n            key={value ?? \"none\"}\n            transition={{ duration: 0.16, ease: [0.23, 1, 0.32, 1] }}\n          >\n            {value === null ? \"Pick one\" : labels[value]}\n          </motion.span>\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}