{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"testimonial-carousel","type":"registry:ui","title":"Testimonial Carousel","description":"One testimonial at a time with avatar, star rating and quote. Swipe, arrows, dots, and auto-play that pauses on hover.","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/ui/testimonial-carousel.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useState, type KeyboardEvent } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion, type PanInfo } from \"motion/react\";\nimport { ChevronLeft, ChevronRight, Quote, Star } from \"lucide-react\";\n\nexport interface Testimonial {\n  quote: string;\n  name: string;\n  role: string;\n  avatar: string;\n  /** 0-5 stars. */\n  rating?: number;\n}\n\nexport interface TestimonialCarouselProps {\n  testimonials: Testimonial[];\n  /** Advance automatically. Pauses while hovered or focused. */\n  autoPlay?: boolean;\n  /** Ms each testimonial stays on screen. */\n  interval?: number;\n  /** Px of horizontal swipe needed to change slide. */\n  swipeThreshold?: number;\n  /** Star color. */\n  starColor?: string;\n  className?: string;\n}\n\nconst css = `@keyframes testimonial-progress{from{transform:scaleX(0)}to{transform:scaleX(1)}}`;\n\nexport function TestimonialCarousel({\n  testimonials,\n  autoPlay = true,\n  interval = 5000,\n  swipeThreshold = 60,\n  starColor = \"#facc15\",\n  className,\n}: TestimonialCarouselProps) {\n  const [[index, dir], setState] = useState<[number, number]>([0, 1]);\n  const [hovered, setHovered] = useState(false);\n  const [focused, setFocused] = useState(false);\n  const reduced = useReducedMotion();\n  const n = testimonials.length;\n  const current = n ? ((index % n) + n) % n : 0;\n  const t = testimonials[current];\n  const playing = autoPlay && !reduced && n > 1;\n  const paused = hovered || focused;\n\n  const go = (next: number, d = next > current ? 1 : -1) => setState([((next % n) + n) % n, d]);\n  const step = (d: number) => go(current + d, d);\n\n  const onDragEnd = (_: unknown, info: PanInfo) => {\n    const swipe = info.offset.x + info.velocity.x * 0.15;\n    if (swipe < -swipeThreshold) step(1);\n    else if (swipe > swipeThreshold) step(-1);\n  };\n\n  const onKey = (e: KeyboardEvent) => {\n    if (e.key === \"ArrowRight\") step(1);\n    else if (e.key === \"ArrowLeft\") step(-1);\n    else return;\n    e.preventDefault();\n  };\n\n  if (!t) return null;\n\n  return (\n    <section\n      aria-roledescription=\"carousel\"\n      aria-label=\"Testimonials\"\n      onPointerEnter={() => setHovered(true)}\n      onPointerLeave={() => setHovered(false)}\n      onFocus={() => setFocused(true)}\n      onBlur={(e) => !e.currentTarget.contains(e.relatedTarget) && setFocused(false)}\n      onKeyDown={onKey}\n      className={`relative w-full max-w-2xl ${className ?? \"\"}`}\n    >\n      <style href=\"testimonial-carousel\" precedence=\"default\">\n        {css}\n      </style>\n      <div className=\"relative overflow-hidden rounded-3xl border border-border bg-card shadow-2xl\">\n        <Quote\n          aria-hidden\n          className=\"pointer-events-none absolute -right-4 -top-6 size-40 rotate-180 text-foreground/[0.04]\"\n          strokeWidth={1}\n        />\n        <div aria-live={playing && !paused ? \"off\" : \"polite\"} className=\"relative\">\n          <AnimatePresence initial={false} mode=\"popLayout\" custom={dir}>\n            <motion.figure\n              key={current}\n              role=\"group\"\n              aria-roledescription=\"slide\"\n              aria-label={`${current + 1} of ${n}`}\n              custom={dir}\n              variants={{\n                enter: (d: number) => (reduced ? { opacity: 0 } : { opacity: 0, x: d * 80, filter: \"blur(6px)\" }),\n                center: { opacity: 1, x: 0, filter: \"blur(0px)\" },\n                exit: (d: number) => (reduced ? { opacity: 0 } : { opacity: 0, x: d * -80, filter: \"blur(6px)\" }),\n              }}\n              initial=\"enter\"\n              animate=\"center\"\n              exit=\"exit\"\n              transition={{ x: { type: \"spring\", stiffness: 260, damping: 30 }, opacity: { duration: 0.3 }, filter: { duration: 0.3 } }}\n              drag={n > 1 ? \"x\" : false}\n              dragConstraints={{ left: 0, right: 0 }}\n              dragElastic={0.6}\n              onDragEnd={onDragEnd}\n              className=\"m-0 cursor-grab touch-pan-y select-none p-8 active:cursor-grabbing sm:p-10\"\n            >\n              {t.rating !== undefined && (\n                <div className=\"flex gap-1\" role=\"img\" aria-label={`Rated ${t.rating} out of 5`}>\n                  {Array.from({ length: 5 }, (_, i) => {\n                    const on = i < (t.rating ?? 0);\n                    return (\n                      <Star\n                        key={i}\n                        aria-hidden\n                        className=\"size-4\"\n                        strokeWidth={1.5}\n                        style={{\n                          color: on ? starColor : \"var(--muted-foreground)\",\n                          fill: on ? starColor : \"transparent\",\n                          opacity: on ? 1 : 0.35,\n                        }}\n                      />\n                    );\n                  })}\n                </div>\n              )}\n              <blockquote className=\"mt-6 min-h-[7.5rem] text-pretty text-xl font-medium leading-relaxed tracking-tight text-foreground sm:text-2xl\">\n                “{t.quote}”\n              </blockquote>\n              <figcaption className=\"mt-8 flex items-center gap-4\">\n                {/* eslint-disable-next-line @next/next/no-img-element */}\n                <img\n                  src={t.avatar}\n                  alt=\"\"\n                  draggable={false}\n                  className=\"size-12 rounded-full object-cover ring-2 ring-border ring-offset-2 ring-offset-card\"\n                />\n                <div>\n                  <p className=\"font-semibold text-foreground\">{t.name}</p>\n                  <p className=\"text-sm text-muted-foreground\">{t.role}</p>\n                </div>\n              </figcaption>\n            </motion.figure>\n          </AnimatePresence>\n        </div>\n      </div>\n\n      {n > 1 && (\n        <div className=\"mt-6 flex items-center justify-between gap-4\">\n          <div className=\"flex items-center gap-2\">\n            {testimonials.map((item, i) => {\n              const active = i === current;\n              return (\n                <button\n                  key={i}\n                  type=\"button\"\n                  aria-label={`Show testimonial from ${item.name}`}\n                  aria-current={active}\n                  onClick={() => go(i)}\n                  className=\"relative h-1.5 overflow-hidden rounded-full bg-foreground/15 transition-[width,background-color] duration-500 hover:bg-foreground/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n                  style={{ width: active ? 40 : 8 }}\n                >\n                  {active && (\n                    <span\n                      key={current}\n                      aria-hidden\n                      className=\"absolute inset-0 origin-left rounded-full bg-foreground\"\n                      style={\n                        playing\n                          ? {\n                              animation: `testimonial-progress ${interval}ms linear forwards`,\n                              animationPlayState: paused ? \"paused\" : \"running\",\n                            }\n                          : undefined\n                      }\n                      onAnimationEnd={() => step(1)}\n                    />\n                  )}\n                </button>\n              );\n            })}\n          </div>\n          <div className=\"flex gap-2\">\n            {[\n              { d: -1, label: \"Previous testimonial\", Icon: ChevronLeft },\n              { d: 1, label: \"Next testimonial\", Icon: ChevronRight },\n            ].map(({ d, label, Icon }) => (\n              <button\n                key={d}\n                type=\"button\"\n                aria-label={label}\n                onClick={() => step(d)}\n                className=\"grid size-10 place-items-center rounded-full border border-border bg-card text-foreground transition hover:bg-muted active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n              >\n                <Icon className=\"size-4\" aria-hidden />\n              </button>\n            ))}\n          </div>\n        </div>\n      )}\n    </section>\n  );\n}\n"}]}