{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"animated-testimonials","type":"registry:ui","title":"AnimatedTestimonials","description":"Testimonial carousel with smooth slide animations and optional autoplay","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["data-display"],"registryDependencies":["https://fancy-ui.rama.app/r/internals.json","https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/internals-motion.json","https://fancy-ui.rama.app/r/sound.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/animated-testimonials/AnimatedTestimonials.tsx","content":"\"use client\";\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"../../utils\";\nimport { useLiveRef } from \"../../internals/dom/use-live-ref\";\nimport { useReducedMotion } from \"../../internals/motion/media-query\";\nimport { useSoundCue } from \"../../sound/use-sound\";\n\n/**\n * AnimatedTestimonials - Animated testimonial carousel\n *\n * Cycles through testimonials with smooth slide animations.\n * Supports manual navigation and optional autoplay.\n */\nexport interface Testimonial {\n\t/** The testimonial quote */\n\tquote: string;\n\t/** Author's full name */\n\tname: string;\n\t/** Author's title or role */\n\tdesignation: string;\n\t/** URL to author's avatar image */\n\tsrc: string;\n}\n\nexport interface AnimatedTestimonialsProps {\n\t/** Array of testimonials to display */\n\ttestimonials: Testimonial[];\n\t/** Auto-advance testimonials */\n\tautoplay?: boolean;\n\t/** Interval between auto-advances (ms) */\n\tinterval?: number;\n\t/** Additional CSS classes */\n\tclassName?: string;\n\t/**\n\t * Plays the matching interface cue through the sound controller. Off by\n\t * default; only audible once the user has enabled sound.\n\t */\n\tsound?: boolean;\n}\n\n/** Duration must match the CSS transition duration below */\nconst TRANSITION_DURATION = 300;\n\nexport function AnimatedTestimonials({\n\ttestimonials,\n\tautoplay = false,\n\tinterval = 5000,\n\tclassName,\n\tsound = false,\n}: AnimatedTestimonialsProps) {\n\tconst [activeIndex, setActiveIndex] = useState(0);\n\tconst [direction, setDirection] = useState<\"next\" | \"prev\">(\"next\");\n\tconst [isAnimating, setIsAnimating] = useState(false);\n\tconst [isHovered, setIsHovered] = useState(false);\n\tconst [isFocused, setIsFocused] = useState(false);\n\n\tconst playCue = useSoundCue(sound);\n\tconst reducedMotion = useReducedMotion();\n\n\t// Mirrors `isAnimating` for the guard inside timer callbacks, where the\n\t// state value captured by the closure may be stale.\n\tconst isAnimatingRef = useRef(false);\n\tconst navigateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n\tconst testimonialCount = testimonials.length;\n\n\t// The timeout below outlives the render that scheduled it, so the count it\n\t// wraps around has to be read when it FIRES, not when it was captured: a\n\t// collection that shrank during the 300ms transition would otherwise land\n\t// `activeIndex` past the end of the new list. The Svelte source reads\n\t// `testimonials.length` through a reactive prop getter inside the same\n\t// callback and gets the live value for free; a React closure captures.\n\tconst testimonialCountRef = useLiveRef(testimonialCount);\n\n\tconst navigate = useCallback(\n\t\t(dir: \"next\" | \"prev\", fromUser = false) => {\n\t\t\tif (isAnimatingRef.current || testimonialCount === 0) return;\n\t\t\t// Only a gesture is audible. The autoplay interval calls this too —\n\t\t\t// cueing that turns the carousel into a metronome — and a\n\t\t\t// single-entry list wraps back onto the testimonial already shown,\n\t\t\t// so neither one plays.\n\t\t\tif (fromUser && testimonialCount > 1) playCue(\"select\");\n\t\t\tsetDirection(dir);\n\t\t\tisAnimatingRef.current = true;\n\t\t\tsetIsAnimating(true);\n\t\t\tnavigateTimerRef.current = setTimeout(() => {\n\t\t\t\tconst count = testimonialCountRef.current;\n\t\t\t\tsetActiveIndex((current) => {\n\t\t\t\t\tif (count === 0) return 0;\n\t\t\t\t\treturn dir === \"next\" ? (current + 1) % count : (current - 1 + count) % count;\n\t\t\t\t});\n\t\t\t\tisAnimatingRef.current = false;\n\t\t\t\tsetIsAnimating(false);\n\t\t\t\tnavigateTimerRef.current = null;\n\t\t\t}, TRANSITION_DURATION);\n\t\t},\n\t\t[testimonialCount, testimonialCountRef, playCue]\n\t);\n\n\t// Reactive autoplay: restarts whenever autoplay, interval, hover state, focus\n\t// state or the motion preference changes. Pointer hover and keyboard focus\n\t// both hold the rotation, so the auto-updating live region can be stopped\n\t// without a pointer, and a reduced-motion preference keeps it from starting.\n\tuseEffect(() => {\n\t\tif (!autoplay || isHovered || isFocused || reducedMotion || testimonialCount === 0) return;\n\n\t\tconst timer = setInterval(() => navigate(\"next\"), interval);\n\t\treturn () => clearInterval(timer);\n\t}, [autoplay, isHovered, isFocused, reducedMotion, interval, testimonialCount, navigate]);\n\n\t// Cleanup navigate timeout on destroy\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tif (navigateTimerRef.current) clearTimeout(navigateTimerRef.current);\n\t\t};\n\t}, []);\n\n\tconst activeTestimonial = testimonials.length > 0 ? testimonials[activeIndex] : null;\n\n\treturn (\n\t\t<div\n\t\t\tclassName={cn(\n\t\t\t\t\"relative mx-auto max-w-sm px-4 py-20 font-sans antialiased md:max-w-4xl md:px-8 lg:px-12\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tonMouseEnter={() => setIsHovered(true)}\n\t\t\tonMouseLeave={() => setIsHovered(false)}\n\t\t\tonFocus={() => setIsFocused(true)}\n\t\t\tonBlur={() => setIsFocused(false)}\n\t\t\trole=\"region\"\n\t\t\taria-label=\"Testimonials\"\n\t\t>\n\t\t\t{testimonials.length === 0 ? (\n\t\t\t\t<p className=\"text-muted-foreground text-center\">No testimonials available.</p>\n\t\t\t) : (\n\t\t\t\t<div className=\"relative grid grid-cols-1 gap-20 md:grid-cols-2\">\n\t\t\t\t\t{/* Image column */}\n\t\t\t\t\t<div className=\"relative h-80 w-full\">\n\t\t\t\t\t\t{testimonials.map((testimonial, index) => (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\t\"absolute inset-0 h-full w-full origin-bottom rounded-3xl ease-in-out motion-safe:transition-all\",\n\t\t\t\t\t\t\t\t\tindex === activeIndex\n\t\t\t\t\t\t\t\t\t\t? \"z-20 translate-y-0 scale-100 rotate-0 opacity-100\"\n\t\t\t\t\t\t\t\t\t\t: \"z-10 translate-y-4 scale-95 opacity-0\",\n\t\t\t\t\t\t\t\t\tindex !== activeIndex && direction === \"next\"\n\t\t\t\t\t\t\t\t\t\t? \"-translate-y-4\"\n\t\t\t\t\t\t\t\t\t\t: index !== activeIndex\n\t\t\t\t\t\t\t\t\t\t\t? \"translate-y-4\"\n\t\t\t\t\t\t\t\t\t\t\t: \"\"\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\tstyle={{ transitionDuration: `${TRANSITION_DURATION}ms` }}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\tsrc={testimonial.src}\n\t\t\t\t\t\t\t\t\talt={testimonial.name}\n\t\t\t\t\t\t\t\t\tclassName=\"h-full w-full rounded-3xl object-cover object-center\"\n\t\t\t\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\n\t\t\t\t\t{/* Content column */}\n\t\t\t\t\t<div className=\"flex flex-col justify-between py-4\">\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\"ease-in-out\",\n\t\t\t\t\t\t\t\tisAnimating\n\t\t\t\t\t\t\t\t\t? direction === \"next\"\n\t\t\t\t\t\t\t\t\t\t? \"translate-y-4 opacity-0\"\n\t\t\t\t\t\t\t\t\t\t: \"-translate-y-4 opacity-0\"\n\t\t\t\t\t\t\t\t\t: \"translate-y-0 opacity-100\"\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\ttransition: `opacity ${TRANSITION_DURATION}ms, transform ${TRANSITION_DURATION}ms`,\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<p className=\"text-lg text-gray-500 dark:text-neutral-300\" aria-live=\"polite\">\n\t\t\t\t\t\t\t\t{activeTestimonial?.quote}\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t<div className=\"mt-8\">\n\t\t\t\t\t\t\t\t<p className=\"text-base font-bold text-gray-900 dark:text-white\">\n\t\t\t\t\t\t\t\t\t{activeTestimonial?.name}\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t<p className=\"text-sm text-gray-500 dark:text-neutral-400\">\n\t\t\t\t\t\t\t\t\t{activeTestimonial?.designation}\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t{/* Navigation */}\n\t\t\t\t\t\t<div className=\"mt-8 flex gap-4\">\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tonClick={() => navigate(\"prev\", true)}\n\t\t\t\t\t\t\t\tclassName=\"group/button flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 transition-colors hover:bg-gray-200 dark:bg-neutral-800 dark:hover:bg-neutral-700\"\n\t\t\t\t\t\t\t\taria-label=\"Previous testimonial\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\t\t\t\t\t\twidth=\"20\"\n\t\t\t\t\t\t\t\t\theight=\"20\"\n\t\t\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\t\t\t\tstrokeWidth=\"2\"\n\t\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\t\t\t\t\tclassName=\"text-gray-800 group-hover/button:-translate-x-0.5 motion-safe:transition-transform dark:text-neutral-200\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<path d=\"m15 18-6-6 6-6\" />\n\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tonClick={() => navigate(\"next\", true)}\n\t\t\t\t\t\t\t\tclassName=\"group/button flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 transition-colors hover:bg-gray-200 dark:bg-neutral-800 dark:hover:bg-neutral-700\"\n\t\t\t\t\t\t\t\taria-label=\"Next testimonial\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\t\t\t\t\t\twidth=\"20\"\n\t\t\t\t\t\t\t\t\theight=\"20\"\n\t\t\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\t\t\t\tstrokeWidth=\"2\"\n\t\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\t\t\t\t\tclassName=\"text-gray-800 group-hover/button:translate-x-0.5 motion-safe:transition-transform dark:text-neutral-200\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<path d=\"m9 18 6-6-6-6\" />\n\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n","type":"registry:ui","target":"@ui/fancy/components/animated-testimonials/AnimatedTestimonials.tsx"},{"path":"react/src/components/animated-testimonials/index.ts","content":"\"use client\";\n\nexport { AnimatedTestimonials } from \"./AnimatedTestimonials\";\nexport type { AnimatedTestimonialsProps, Testimonial } from \"./AnimatedTestimonials\";\n","type":"registry:ui","target":"@ui/fancy/components/animated-testimonials/index.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/animated-testimonials?framework=react"}}