{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"mood-slider","type":"registry:ui","title":"Mood slider","description":"A satisfaction rating as a face that changes with the slider: the mouth bends from a frown to a smile, the eyes soften and the colour warms from red through amber to green, with the word for each step beneath.","dependencies":["clsx","tailwind-merge"],"registryDependencies":["https://caliperui.site/r/styles.json"],"files":[{"path":"ui/lib/cn.ts","type":"registry:ui","target":"components/ui/lib/cn.ts","content":"import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({\n  extend: { theme: { radius: [\"control\", \"surface\", \"overlay\"], shadow: [\"overlay\"] } },\n});\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n"},{"path":"ui/mood-slider.tsx","type":"registry:ui","target":"components/ui/mood-slider.tsx","content":"\"use client\";\nimport { useId, useState, type ComponentProps, type CSSProperties, type KeyboardEvent } from \"react\";\nimport { cn } from \"./lib/cn\";\nimport \"./mood-slider.css\";\n\nexport type MoodSliderProps = Omit<ComponentProps<\"div\">, \"defaultValue\" | \"onChange\"> & {\n  /** The question, e.g. \"How was your onboarding?\". */\n  label: string;\n  /** One word per step, worst first. */\n  moods?: string[];\n  value?: number;\n  defaultValue?: number;\n  onValueChange?: (value: number) => void;\n};\n\n/**\n * A satisfaction rating as a face that changes with the slider: the mouth bends from a frown to a smile, the eyes\n * soften, and the colour warms from red through amber to green, with the word for each step beneath. Dragging is\n * continuous and lands on the nearest step; arrow keys move a step at a time. Under reduced motion the face changes\n * without easing between steps.\n */\nexport function MoodSlider({ label, moods = [\"Awful\", \"Poor\", \"Okay\", \"Good\", \"Great\"], value, defaultValue = 2, onValueChange, className, style, ...props }: MoodSliderProps) {\n  const id = useId();\n  const [own, setOwn] = useState(defaultValue);\n  const [drag, setDrag] = useState<number | null>(null);\n  const step = value ?? own;\n  const at = drag ?? step; // continuous while dragging\n  const last = moods.length - 1;\n  const t = last ? at / last : 0; // 0 worst, 1 best\n\n  const commit = (next: number) => {\n    const snapped = Math.max(0, Math.min(last, Math.round(next)));\n    setDrag(null);\n    if (value === undefined) setOwn(snapped);\n    if (snapped !== step) onValueChange?.(snapped);\n  };\n  const key = (event: KeyboardEvent<HTMLInputElement>) => {\n    const move = { ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1, Home: -last, End: last }[event.key];\n    if (move === undefined) return;\n    event.preventDefault();\n    commit(step + move);\n  };\n\n  // The mouth is one curve: its middle drops below the corners for a frown and rises above for a smile.\n  const bend = (t - 0.5) * 22;\n  const mouth = `M30 ${66 - bend * 0.3} Q50 ${66 + bend} 70 ${66 - bend * 0.3}`;\n  const eye = 6 - Math.max(0, t - 0.6) * 6; // happier eyes narrow into a smile\n\n  return (\n    <div data-slot=\"mood-slider\" className={cn(\"grid justify-items-center gap-4\", className)} style={{ \"--mo-h\": 25 + t * 120, ...style } as CSSProperties} {...props}>\n      <label htmlFor={id} className=\"text-sm font-medium\">\n        {label}\n      </label>\n      <svg data-slot=\"mo-face\" viewBox=\"0 0 100 100\" aria-hidden=\"true\">\n        <circle cx={50} cy={50} r={46} data-slot=\"mo-skin\" />\n        <ellipse cx={36} cy={42} rx={5} ry={eye} data-slot=\"mo-feature\" />\n        <ellipse cx={64} cy={42} rx={5} ry={eye} data-slot=\"mo-feature\" />\n        <path d={mouth} data-slot=\"mo-mouth\" />\n      </svg>\n      <p data-slot=\"mo-word\" aria-hidden=\"true\">\n        <span key={Math.round(at)}>{moods[Math.round(at)]}</span>\n      </p>\n      <input\n        id={id}\n        type=\"range\"\n        data-slot=\"mo-range\"\n        min={0}\n        max={last}\n        step=\"any\"\n        value={at}\n        aria-valuetext={moods[Math.round(at)]}\n        onChange={(event) => setDrag(Number(event.target.value))}\n        onPointerUp={() => drag !== null && commit(drag)}\n        onKeyDown={key}\n        onBlur={() => drag !== null && commit(drag)}\n      />\n    </div>\n  );\n}\n"},{"path":"ui/mood-slider.css","type":"registry:file","target":"components/ui/mood-slider.css","content":"/* mood-slider.tsx's styles; it imports this file. Edit freely. */\n@layer theme, base, components, utilities;\n\n@layer components {\n  /* Mood slider: the face's colour and mouth follow the slider; the word swaps with a small lift. */\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-face\"] { width: 112px; height: 112px; }\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-skin\"] { fill: oklch(0.86 0.12 var(--mo-h)); transition: fill var(--duration-normal) var(--ease-out); }\n  [data-theme=\"dark\"] [data-slot=\"mood-slider\"] [data-slot=\"mo-skin\"] { fill: oklch(0.74 0.13 var(--mo-h)); }\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-feature\"] { fill: oklch(0.24 0.03 var(--mo-h)); transition: ry var(--duration-normal) var(--ease-settle); }\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-mouth\"] { fill: none; stroke: oklch(0.24 0.03 var(--mo-h)); stroke-width: 5; stroke-linecap: round; transition: d var(--duration-normal) var(--ease-settle); }\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-word\"] { min-height: 24px; margin: 0; font-weight: 500; }\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-word\"] > span { display: inline-block; animation: mo-word 0.3s var(--ease-out); }\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-range\"] { width: min(280px, 100%); accent-color: oklch(0.6 0.15 var(--mo-h)); cursor: pointer; }\n  [data-slot=\"mood-slider\"] [data-slot=\"mo-range\"]:focus-visible { outline: 2px solid var(--ring); outline-offset: 4px; border-radius: 4px; }\n  @media (prefers-reduced-motion: reduce) {\n    [data-slot=\"mood-slider\"] :is([data-slot=\"mo-feature\"], [data-slot=\"mo-mouth\"], [data-slot=\"mo-skin\"]) { transition: none; }\n    [data-slot=\"mood-slider\"] [data-slot=\"mo-word\"] > span { animation: none; }\n  }\n  @keyframes mo-word { from { opacity: 0; translate: 0 5px; } }\n}\n"}],"categories":["motion"],"meta":{"tier":"free","license":"MIT","family":"changing-values","docs":"/docs/components/mood-slider"}}