{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider-18",
  "title": "Rating slider with face",
  "description": "A rating whose face changes and whose bubble names the step.",
  "dependencies": [
    "@base-ui/react",
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/slider.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/slider/slider-18.tsx",
      "content": "'use client';\n\nimport { Slider as SliderPrimitive } from '@base-ui/react/slider';\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState, type ReactNode } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { SliderThumbValue } from '@/registry/ndeko/ui/slider';\n\nconst RATINGS = ['Awful', 'Poor', 'Okay', 'Good', 'Amazing'];\nconst INITIAL_RATING = 3;\n\nconst CONTROL =\n  'relative flex w-full touch-none items-center py-2 select-none data-disabled:opacity-50';\n\nconst TRACK = 'bg-foreground/10 relative h-1 w-full grow rounded-full';\n\nconst THUMB = [\n  'group/thumb block size-4 shrink-0 rounded-full bg-white shadow-[0_1px_3px_rgb(0_0_0/0.18)] hairline-ring ring-foreground/15 outline-none',\n  'transition-[scale,box-shadow] duration-150 ease-(--ease-out-strong) has-focus-visible:ring-[3px] has-focus-visible:ring-ring/30 data-dragging:scale-110',\n].join(' ');\n\nconst BUBBLE_LOOK = [\n  'mb-2.5 rounded-lg bg-transparent px-2 py-1 text-popover-foreground',\n  '[--bubble-top:var(--popover)] [--bubble-bottom:color-mix(in_oklab,var(--popover),var(--primary)_9%)]',\n  'bg-linear-to-b from-(--bubble-top) to-(--bubble-bottom) hairline-ring ring-border shadow-md shadow-black/6',\n].join(' ');\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst FACE_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nconst DOT_EYES = <path d='M9 10.5h.01M15 10.5h.01' strokeWidth='2.25' />;\n\nconst FACE_FEATURES: Record<number, ReactNode> = {\n  1: (\n    <>\n      <path d='M7.75 7.75 10 8.75M16.25 7.75 14 8.75' />\n      {DOT_EYES}\n      <path d='M8.75 16.75c.8-1 1.9-1.5 3.25-1.5s2.45.5 3.25 1.5' />\n    </>\n  ),\n  2: (\n    <>\n      {DOT_EYES}\n      <path d='M9 16.25c.75-.65 1.75-1 3-1s2.25.35 3 1' />\n    </>\n  ),\n  3: (\n    <>\n      {DOT_EYES}\n      <path d='M9 15.5h6' />\n    </>\n  ),\n  4: (\n    <>\n      {DOT_EYES}\n      <path d='M9 14.5c.75.85 1.75 1.25 3 1.25s2.25-.4 3-1.25' />\n    </>\n  ),\n  5: (\n    <>\n      <path d='M8 10.25c.5-.9 1.75-.9 2.25 0M13.75 10.25c.5-.9 1.75-.9 2.25 0' />\n      <path d='M8.25 13.5h7.5c-.4 2-1.9 3.25-3.75 3.25s-3.35-1.25-3.75-3.25Z' />\n    </>\n  ),\n};\n\nfunction faceVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return FACE_VARIANTS;\n}\n\nfunction ratingLabelOf(rating: number) {\n  const index = rating - 1;\n  return RATINGS[index];\n}\n\nfunction ratingTextOf(_formattedValue: string, rating: number) {\n  return ratingLabelOf(rating);\n}\n\nfunction RatingFace({ rating }: { rating: number }) {\n  return (\n    <svg\n      viewBox='0 0 24 24'\n      fill='none'\n      stroke='currentColor'\n      strokeWidth='1.75'\n      strokeLinecap='round'\n      strokeLinejoin='round'\n      aria-hidden='true'\n      className='size-6'\n    >\n      <circle cx='12' cy='12' r='9.25' />\n      {FACE_FEATURES[rating]}\n    </svg>\n  );\n}\n\nexport default function Slider18() {\n  const [rating, setRating] = useState(INITIAL_RATING);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const faceVariants = faceVariantsOf(shouldReduceMotion);\n\n  return (\n    <div className='flex w-full max-w-xs flex-col gap-3'>\n      <Label>Rate your experience</Label>\n      <div className='flex items-center gap-3'>\n        <SliderPrimitive.Root\n          value={rating}\n          onValueChange={setRating}\n          min={1}\n          max={RATINGS.length}\n          className='w-full'\n        >\n          <SliderPrimitive.Control className={CONTROL}>\n            <SliderPrimitive.Track className={TRACK}>\n              <SliderPrimitive.Indicator className='bg-primary rounded-full' />\n              <SliderPrimitive.Thumb\n                aria-label='Rate your experience'\n                getAriaValueText={ratingTextOf}\n                className={THUMB}\n              >\n                <SliderThumbValue className={BUBBLE_LOOK}>\n                  {ratingLabelOf(rating)}\n                </SliderThumbValue>\n              </SliderPrimitive.Thumb>\n            </SliderPrimitive.Track>\n          </SliderPrimitive.Control>\n        </SliderPrimitive.Root>\n        <span className='relative flex shrink-0'>\n          <AnimatePresence mode='popLayout' initial={false}>\n            <motion.span\n              key={rating}\n              className='flex'\n              variants={faceVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              <RatingFace rating={rating} />\n            </motion.span>\n          </AnimatePresence>\n        </span>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "slider"
  ],
  "type": "registry:component"
}