{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"slider","type":"registry:block","title":"Slider","description":"A seat-pricing slider with a native range under a custom track, a lens thumb, tick marks and a live monthly total.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/slider/slider.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useRef, useState } from \"react\";\nimport {\n  AnimatePresence,\n  MotionConfig,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type SliderProps = {\n  className?: string;\n  label?: string;\n  description?: string;\n  min?: number;\n  max?: number;\n  step?: number;\n  defaultValue?: number;\n  /** Render the current value in the header. */\n  formatValue?: (value: number) => string;\n  /** Small line under the track. */\n  formatHint?: (value: number) => string;\n  /** Extra tick marks between the min and max. */\n  marks?: number[];\n  onValueChange?: (value: number) => void;\n};\n\n/* ------------------------------------------------------------------ */\n/* demo data                                                           */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_MARKS = [10, 20, 30];\n\nfunction clamp(value: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, value));\n}\n\nfunction seatPrice(seats: number) {\n  const perSeat = seats >= 30 ? 15 : seats >= 20 ? 17 : 19;\n  return { perSeat, total: seats * perSeat };\n}\n\nconst formatSeats = (value: number) => `${value} ${value === 1 ? \"seat\" : \"seats\"}`;\n\nconst formatSeatHint = (value: number) => {\n  const { perSeat, total } = seatPrice(value);\n  return `$${total.toLocaleString(\"en-US\")} / month · $${perSeat} per seat`;\n};\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function Slider({\n  className,\n  label = \"Team seats\",\n  description = \"How many people need a seat on the Studio plan?\",\n  min = 1,\n  max = 40,\n  step = 1,\n  defaultValue = 12,\n  formatValue = formatSeats,\n  formatHint = formatSeatHint,\n  marks = DEFAULT_MARKS,\n  onValueChange,\n}: SliderProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n\n  const [value, setValue] = useState(() => clamp(defaultValue, min, max));\n  const percent = max > min ? ((value - min) / (max - min)) * 100 : 0;\n  const discounted = value >= 20;\n\n  const handleChange = (nextValue: number) => {\n    const next = clamp(nextValue, min, max);\n    setValue(next);\n    onValueChange?.(next);\n  };\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div ref={ref} className={cn(\"w-full\", className)}>\n        <motion.div\n          initial={{ opacity: 0, y: reduce ? 0 : 16 }}\n          animate={{ opacity: inView ? 1 : 0, y: 0 }}\n          transition={{ duration: reduce ? 0 : 0.55, ease: EASE }}\n          className=\"rounded-xl border border-border bg-card p-5 text-card-foreground shadow-sm sm:p-6\"\n        >\n          <div className=\"flex flex-wrap items-start justify-between gap-x-4 gap-y-2\">\n            <div className=\"min-w-0\">\n              <div className=\"flex flex-wrap items-center gap-2\">\n                <h2 className=\"text-[15px] font-semibold tracking-tight\">{label}</h2>\n                <AnimatePresence initial={false}>\n                  {discounted ? (\n                    <motion.span\n                      key=\"volume\"\n                      initial={reduce ? false : { opacity: 0, x: -4 }}\n                      animate={{ opacity: 1, x: 0 }}\n                      exit={{ opacity: 0, x: -4 }}\n                      transition={{ duration: reduce ? 0 : 0.25, ease: EASE }}\n                      className=\"inline-flex items-center gap-1 rounded-full border border-success/25 bg-success/10 px-2 py-0.5 text-[10.5px] font-medium text-success\"\n                    >\n                      Volume price\n                    </motion.span>\n                  ) : null}\n                </AnimatePresence>\n              </div>\n              <p className=\"mt-0.5 text-[12.5px] leading-5 text-muted-foreground\">{description}</p>\n            </div>\n\n            <p className=\"text-[26px] font-semibold leading-none tracking-tight tabular-nums sm:text-[30px]\">\n              {formatValue(value)}\n            </p>\n          </div>\n\n          <div className=\"mt-6 px-2\">\n            <div className=\"group relative h-9\">\n              <div className=\"absolute inset-x-0 top-1/2 h-1.5 -translate-y-1/2 rounded-full bg-muted\" />\n\n              {marks\n                .filter((mark) => mark > min && mark < max)\n                .map((mark) => (\n                  <span\n                    key={mark}\n                    aria-hidden=\"true\"\n                    className=\"absolute top-1/2 h-4 w-px -translate-y-1/2 bg-border\"\n                    style={{ left: `${((mark - min) / (max - min)) * 100}%` }}\n                  />\n                ))}\n\n              <motion.div\n                aria-hidden=\"true\"\n                initial={{ scaleX: reduce ? percent / 100 : 0 }}\n                animate={{ scaleX: inView ? percent / 100 : 0 }}\n                transition={{ duration: reduce ? 0 : 0.2, ease: EASE }}\n                style={{ transformOrigin: \"left center\" }}\n                className=\"absolute inset-x-0 top-1/2 h-1.5 -translate-y-1/2 rounded-full bg-foreground\"\n              />\n\n              <div\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute top-1/2 z-10 -translate-x-1/2 -translate-y-1/2\"\n                style={{ left: `${percent}%` }}\n              >\n                <div className=\"relative flex h-[22px] w-[22px] items-center justify-center rounded-full border border-border bg-background shadow-sm transition-transform duration-200 motion-reduce:transition-none group-hover:scale-105 group-focus-within:scale-105 group-focus-within:ring-2 group-focus-within:ring-ring group-focus-within:ring-offset-2 group-focus-within:ring-offset-card\">\n                  <span className=\"h-[7px] w-[7px] rounded-full bg-foreground\" />\n                  <span className=\"absolute right-[4px] top-[4px] h-[3px] w-[3px] rounded-full bg-muted-foreground/70\" />\n                </div>\n              </div>\n\n              <input\n                type=\"range\"\n                min={min}\n                max={max}\n                step={step}\n                value={value}\n                aria-label={label}\n                aria-valuetext={formatValue(value)}\n                onChange={(event) => handleChange(Number(event.target.value))}\n                className=\"absolute inset-0 z-20 h-full w-full cursor-pointer appearance-none bg-transparent opacity-0 focus-visible:outline-none\"\n              />\n            </div>\n\n            <div className=\"mt-1 flex items-center justify-between text-[11px] tabular-nums text-muted-foreground\">\n              <span>{formatValue(min)}</span>\n              <span>{formatValue(max)}</span>\n            </div>\n          </div>\n\n          <div className=\"mt-4 flex flex-wrap items-center justify-between gap-2 border-t border-border pt-3\">\n            <p className=\"text-[12px] tabular-nums text-muted-foreground\">{formatHint(value)}</p>\n            <p className=\"text-[11px] text-muted-foreground\">\n              {discounted ? \"Volume pricing applied\" : \"Volume pricing from 20 seats\"}\n            </p>\n          </div>\n        </motion.div>\n      </div>\n    </MotionConfig>\n  );\n}\n\nexport default Slider;\n"}]}