{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "emoji-rating-scale",
  "title": "Emoji Rating Scale",
  "description": "A five-face satisfaction rating for quick feedback: hand-drawn faces from a frown to a wide smile that wobble on hover, fill with their own colour and pop when picked, a label that rolls in underneath, and full keyboard support as a radio group.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/emoji-rating-scale/emoji-rating-scale.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface EmojiRatingOption {\n  label: string;\n  /** Colour the face takes when it's picked. */\n  color: string;\n}\n\nexport interface EmojiRatingScaleProps {\n  value?: number | null;\n  defaultValue?: number | null;\n  /** 1 to 5; null when cleared. */\n  onValueChange?: (value: number | null) => void;\n  /** Override the five labels and colours, worst first. */\n  options?: EmojiRatingOption[];\n  size?: \"sm\" | \"md\" | \"lg\";\n  /** Show the picked label under the faces. */\n  showLabel?: boolean;\n  /** Clicking the picked face again clears the rating. */\n  allowClear?: boolean;\n  label?: string;\n  disabled?: boolean;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst DEFAULT_OPTIONS: EmojiRatingOption[] = [\n  { label: \"Terrible\", color: \"#FF5A4E\" },\n  { label: \"Bad\", color: \"#FF8A3D\" },\n  { label: \"Okay\", color: \"#F5C443\" },\n  { label: \"Good\", color: \"#8BD450\" },\n  { label: \"Great\", color: \"#3FBF7F\" },\n];\n\n// Mouths from a frown to a wide smile; the last two eyes turn into happy arcs.\nconst MOUTHS = [\"M8 17c1.2-1.7 2.5-2.3 4-2.3s2.8.6 4 2.3\", \"M8.5 16.4c1-.9 2.2-1.3 3.5-1.3s2.5.4 3.5 1.3\", \"M8.5 15.6h7\", \"M8.5 14.8c1 .9 2.2 1.4 3.5 1.4s2.5-.5 3.5-1.4\", \"M8 14.2c1.2 1.9 2.5 2.7 4 2.7s2.8-.8 4-2.7\"];\nconst BROWS = [\"M7.5 8.2 9.8 9.2M16.5 8.2 14.2 9.2\", \"\", \"\", \"\", \"\"];\n\nfunction Face({ level, color, active, faceColor }: { level: number; color: string; active: boolean; faceColor: string }) {\n  const happy = level >= 3;\n  return (\n    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"h-full w-full\">\n      <circle cx=\"12\" cy=\"12\" r=\"9.5\" fill={active ? color : \"none\"} stroke={active ? color : \"currentColor\"} style={{ transition: \"fill 0.2s ease, stroke 0.2s ease\" }} />\n      <g stroke={active ? faceColor : \"currentColor\"} style={{ transition: \"stroke 0.2s ease\" }}>\n        {happy ? (\n          <path d=\"M8.3 10.4c.4-.8 1.6-.8 2 0M13.7 10.4c.4-.8 1.6-.8 2 0\" />\n        ) : (\n          <path d=\"M9.3 10.6h.01M14.7 10.6h.01\" strokeWidth={2.4} />\n        )}\n        {BROWS[level] && <path d={BROWS[level]} />}\n        <path d={MOUTHS[level]} />\n      </g>\n    </svg>\n  );\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.45)\", face: \"rgba(245,244,241,0.55)\", hover: \"rgba(245,244,241,0.9)\", onColor: \"#0A0A0A\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.45)\", face: \"rgba(10,10,10,0.45)\", hover: \"rgba(10,10,10,0.85)\", onColor: \"#0A0A0A\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst SIZES = { sm: 30, md: 40, lg: 52 };\n\nexport function EmojiRatingScale({ value, defaultValue = null, onValueChange, options = DEFAULT_OPTIONS, size = \"md\", showLabel = true, allowClear = true, label = \"Rate your experience\", disabled = false, theme = \"dark\", className }: EmojiRatingScaleProps) {\n  const p = PALETTES[theme];\n  const px = SIZES[size];\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState<number | null>(defaultValue);\n  const current = value !== undefined ? value : internal;\n  const [hovered, setHovered] = React.useState<number | null>(null);\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const labelId = React.useId();\n\n  const pick = (n: number | null) => {\n    if (disabled) return;\n    if (value === undefined) setInternal(n);\n    onValueChange?.(n);\n  };\n\n  const onKey = (e: React.KeyboardEvent, i: number) => {\n    const last = options.length - 1;\n    const map: Record<string, number> = { ArrowRight: Math.min(last, i + 1), ArrowDown: Math.min(last, i + 1), ArrowLeft: Math.max(0, i - 1), ArrowUp: Math.max(0, i - 1), Home: 0, End: last };\n    if (!(e.key in map)) return;\n    e.preventDefault();\n    refs.current[map[e.key]]?.focus();\n    pick(map[e.key] + 1);\n  };\n\n  const shown = hovered ?? (current ? current - 1 : null);\n\n  return (\n    <div className={cn(\"inline-flex flex-col items-center\", className)} style={{ gap: 10, fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      <span id={labelId} className=\"sr-only\">\n        {label}\n      </span>\n      <div role=\"radiogroup\" aria-labelledby={labelId} className=\"flex items-center\" style={{ gap: px * 0.3 }} onPointerLeave={() => setHovered(null)}>\n        {options.map((o, i) => {\n          const active = current === i + 1;\n          // Roving tabindex: the picked face (or the first one) is the single tab stop.\n          const tabbable = current ? active : i === 0;\n          return (\n            <motion.button\n              key={o.label}\n              ref={(el) => {\n                refs.current[i] = el;\n              }}\n              type=\"button\"\n              role=\"radio\"\n              aria-checked={active}\n              aria-label={o.label}\n              tabIndex={tabbable ? 0 : -1}\n              disabled={disabled}\n              onClick={() => pick(active && allowClear ? null : i + 1)}\n              onKeyDown={(e) => onKey(e, i)}\n              onPointerEnter={() => setHovered(i)}\n              className=\"cursor-pointer rounded-full outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed\"\n              style={{ width: px, height: px, color: hovered === i ? p.hover : p.face, transition: \"color 0.15s ease\", [\"--tw-ring-color\" as string]: p.focus, [\"--tw-ring-offset-color\" as string]: \"transparent\" }}\n              initial={false}\n              animate={active && !reduce ? { scale: [1, 1.28, 1.08] } : { scale: hovered === i && !reduce ? 1.12 : 1, rotate: hovered === i && !reduce ? [0, -8, 6, 0] : 0 }}\n              whileTap={reduce ? undefined : { scale: 0.9, transition: { type: \"spring\", stiffness: 600, damping: 20 } }}\n              // Keyframed pop and wobble need a timed transition (springs only take two keyframes).\n              transition={{ duration: 0.42, ease: \"easeOut\" }}\n            >\n              <Face level={i} color={o.color} active={active} faceColor={p.onColor} />\n            </motion.button>\n          );\n        })}\n      </div>\n      {showLabel && (\n        <div className=\"relative flex h-5 items-center justify-center overflow-hidden\" style={{ minWidth: 120 }} aria-live=\"polite\">\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            <motion.span\n              key={shown ?? \"none\"}\n              className=\"text-[13px] font-medium\"\n              style={{ color: shown !== null ? (current === shown + 1 ? options[shown].color : p.text) : p.muted }}\n              initial={reduce ? false : { y: 8, opacity: 0 }}\n              animate={{ y: 0, opacity: 1 }}\n              exit={reduce ? undefined : { y: -8, opacity: 0 }}\n              transition={{ duration: 0.18 }}\n            >\n              {shown !== null ? options[shown].label : \"Tap a face\"}\n            </motion.span>\n          </AnimatePresence>\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport function EmojiRatingScaleDemo({ theme = \"dark\" }: { theme?: \"dark\" | \"light\" }) {\n  const [rating, setRating] = React.useState<number | null>(null);\n  const [sent, setSent] = React.useState(false);\n  const t = theme === \"dark\" ? { bg: \"#0E0E0E\", border: \"rgba(255,255,255,0.1)\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", btn: \"#F5F4F1\", onBtn: \"#0A0A0A\" } : { bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", btn: \"#0A0A0A\", onBtn: \"#FFFFFF\" };\n  return (\n    <div className=\"flex w-[340px] max-w-full flex-col items-center\" style={{ gap: 16, padding: 22, borderRadius: 18, background: t.bg, border: `1px solid ${t.border}`, fontFamily: \"Inter, sans-serif\" }}>\n      <div className=\"text-center\">\n        <p className=\"text-[15px] font-semibold\" style={{ color: t.text }}>\n          How was your checkout?\n        </p>\n        <p className=\"mt-1 text-[13px]\" style={{ color: t.muted }}>\n          One tap helps us improve.\n        </p>\n      </div>\n      <EmojiRatingScale\n        theme={theme}\n        label=\"How was your checkout?\"\n        value={rating}\n        onValueChange={(v) => {\n          setRating(v);\n          setSent(false);\n        }}\n      />\n      <button\n        type=\"button\"\n        disabled={!rating}\n        onClick={() => setSent(true)}\n        className=\"h-9 w-full cursor-pointer rounded-xl text-[13.5px] font-semibold transition-opacity disabled:cursor-not-allowed disabled:opacity-35\"\n        style={{ background: t.btn, color: t.onBtn }}\n      >\n        {sent ? \"Thanks for the feedback\" : \"Send feedback\"}\n      </button>\n    </div>\n  );\n}\n\nexport default EmojiRatingScale;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}