{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider-17",
  "title": "Rating slider",
  "description": "Five steps between two faces, with the rating in words.",
  "dependencies": [
    "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",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/slider/slider-17.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { Slider } from '@/registry/ndeko/ui/slider';\n\ntype SliderValue = number | readonly number[];\n\nconst RATINGS = ['Awful', 'Poor', 'Okay', 'Good', 'Amazing'];\nconst INITIAL_RATING = 3;\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst LABEL_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\nfunction labelVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return LABEL_VARIANTS;\n}\n\nfunction firstValueOf(value: SliderValue) {\n  if (typeof value === 'number') {\n    return value;\n  }\n  return value[0];\n}\n\nfunction ratingLabelOf(rating: number) {\n  const index = rating - 1;\n  return RATINGS[index];\n}\n\ntype FaceProps = {\n  className?: string;\n};\n\nfunction AwfulFace({ className }: FaceProps) {\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={cn('size-6 shrink-0', className)}\n    >\n      <circle cx='12' cy='12' r='9.25' />\n      <path d='M7.75 8.5 10 9.5M16.25 8.5 14 9.5' />\n      <path d='M9 11.5h.01M15 11.5h.01' strokeWidth='2.25' />\n      <path d='M8.75 16.75c.8-1 1.9-1.5 3.25-1.5s2.45.5 3.25 1.5' />\n    </svg>\n  );\n}\n\nfunction AmazingFace({ className }: FaceProps) {\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={cn('size-6 shrink-0', className)}\n    >\n      <circle cx='12' cy='12' r='9.25' />\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    </svg>\n  );\n}\n\nexport default function Slider17() {\n  const [rating, setRating] = useState(INITIAL_RATING);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const labelVariants = labelVariantsOf(shouldReduceMotion);\n  const ratingLabel = ratingLabelOf(rating);\n\n  function changeRating(value: SliderValue) {\n    const nextRating = firstValueOf(value);\n    setRating(nextRating);\n  }\n\n  return (\n    <div className='flex w-full max-w-xs flex-col gap-3'>\n      <div className='flex items-center justify-between gap-2'>\n        <Label>Rate your experience</Label>\n        <span className='relative flex text-[13px] font-medium'>\n          <AnimatePresence mode='popLayout' initial={false}>\n            <motion.span\n              key={ratingLabel}\n              className='flex'\n              variants={labelVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              {ratingLabel}\n            </motion.span>\n          </AnimatePresence>\n        </span>\n      </div>\n      <div className='flex items-center gap-2'>\n        <AwfulFace className='text-muted-foreground' />\n        <Slider\n          value={rating}\n          onValueChange={changeRating}\n          min={1}\n          max={RATINGS.length}\n          thumbLabels={['Rate your experience']}\n        />\n        <AmazingFace className='text-muted-foreground' />\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "slider"
  ],
  "type": "registry:component"
}