{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"drag-inertia-carousel","type":"registry:component","title":"Drag Inertia Carousel","description":"A rail you can throw — it projects the momentum and settles on the nearest slide.","dependencies":["framer-motion"],"registryDependencies":[],"files":[{"path":"components/viberdy/drag-inertia-carousel.tsx","content":"\"use client\";\n\nimport { useState } from \"react\";\nimport { motion } from \"framer-motion\";\n\ntype Slide = { id: string; label: string };\n\nexport function DragInertiaCarousel({\n  slides,\n  slideWidth = 132,\n  power = 0.22,\n  stiffness = 260,\n  showDots = true,\n}: {\n  slides: Slide[];\n  /** Card width + gap, in px. */\n  slideWidth?: number;\n  /** How far velocity carries the throw. Higher = flickier. */\n  power?: number;\n  stiffness?: number;\n  /** The pager dots under the rail, which also jump to a slide. */\n  showDots?: boolean;\n}) {\n  const [index, setIndex] = useState(0);\n  const maxIndex = slides.length - 1;\n\n  return (\n    <div className=\"flex flex-col gap-3\">\n      <div className=\"overflow-hidden\">\n        <motion.div\n          drag=\"x\"\n          dragConstraints={{ left: -slideWidth * maxIndex, right: 0 }}\n          dragElastic={0.12}\n          /*\n           * Framer's own momentum is OFF. We resolve the throw ourselves in\n           * onDragEnd; leaving both enabled makes the rail coast past the\n           * chosen slide and then spring back — the classic \"fighting the\n           * carousel\" feel.\n           */\n          dragMomentum={false}\n          onDragEnd={(_, info) => {\n            /*\n             * Project where the throw WOULD land using the gesture's velocity,\n             * then round to the nearest slide. Snapping from the release\n             * OFFSET alone ignores how hard it was thrown, so a hard flick and\n             * a gentle nudge of the same distance behave identically — which\n             * is exactly what feels wrong in most drag carousels.\n             */\n            const projected = info.offset.x + info.velocity.x * power;\n            const next = Math.round(index - projected / slideWidth);\n            setIndex(Math.max(0, Math.min(maxIndex, next)));\n          }}\n          animate={{ x: -index * slideWidth }}\n          transition={{ type: \"spring\", stiffness, damping: 32, mass: 0.8 }}\n          className=\"flex cursor-grab gap-3 active:cursor-grabbing\"\n        >\n          {slides.map((slide) => (\n            <div\n              key={slide.id}\n              className=\"flex h-28 w-[120px] shrink-0 select-none flex-col justify-between rounded-md bg-neutral-800 p-3\"\n            >\n              <span className=\"font-mono text-[9px] tracking-[0.16em] opacity-60\">\n                {slide.id}\n              </span>\n              <span className=\"text-sm font-bold text-white\">{slide.label}</span>\n            </div>\n          ))}\n        </motion.div>\n      </div>\n\n      {showDots && (\n        <div className=\"flex justify-center gap-1.5\">\n          {slides.map((s, i) => (\n            <button\n              key={s.id}\n              onClick={() => setIndex(i)}\n              aria-label={\"Go to \" + s.label}\n              aria-current={i === index}\n              className={\n                \"h-1.5 rounded-full transition-all \" +\n                (i === index ? \"w-5 bg-blue-500\" : \"w-1.5 bg-white/25\")\n              }\n            />\n          ))}\n        </div>\n      )}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/drag-inertia-carousel.tsx"}],"meta":{"tier":"free","tags":["drag","carousel","inertia","gesture"],"href":"https://viberdy.dev/library/drag-inertia-carousel","aiPrompt":"Create a React + Tailwind + Framer Motion component named DragInertiaCarousel — a draggable rail that you can throw and that settles on the nearest slide.\n\nBehavior:\n- A horizontal rail of fixed-width slides, draggable on the x axis with dragConstraints limiting it to the slide range and a small dragElastic for rubber-banding at the ends.\n- On release, the rail settles on a slide with a spring (stiffness configurable, damping 32, mass 0.8).\n- Dot indicators below; clicking one jumps to that slide.\n\nThe two decisions that make it feel right (do not skip either):\n1. Set dragMomentum={false}. You are resolving the throw yourself in onDragEnd — leaving Framer's momentum on as well makes the rail coast past the chosen slide and spring back, which is the classic \"fighting the carousel\" feel.\n2. In onDragEnd, PROJECT where the throw would land using the gesture's velocity before rounding:\n     const projected = info.offset.x + info.velocity.x * power;\n     const next = Math.round(index - projected / slideWidth);\n   then clamp to [0, slides.length - 1]. Snapping from info.offset alone ignores how hard the user threw it, so a hard flick and a gentle nudge covering the same distance behave identically — which is what feels wrong in most drag carousels.\n\nAccessibility: dots are real buttons with aria-label and aria-current.\n\nProps: slides (array of {id, label}), slideWidth (px, card + gap), power (velocity multiplier), stiffness (number).\n\nOutput a single self-contained \"use client\" component.","license":"https://viberdy.dev/license"}}