{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"testimonial-marquee","type":"registry:block","title":"Testimonial Marquee","description":"Two rows of testimonial cards drift in opposite directions with soft edge fades, pausing on hover or focus. Star ratings, initials avatars and a calm static grid for reduced motion keep it readable.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/testimonial-marquee/testimonial-marquee.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  MotionConfig,\n  motion,\n  useAnimationFrame,\n  useInView,\n  useMotionValue,\n  useReducedMotion,\n} from \"motion/react\";\nimport { Pause, Play, Star } from \"lucide-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 Testimonial = {\n  id: string;\n  name: string;\n  role: string;\n  quote: string;\n  /** Rating from 0 to 5. */\n  rating: number;\n};\n\nexport type TestimonialMarqueeProps = {\n  className?: string;\n  eyebrow?: string;\n  title?: string;\n  description?: string;\n  testimonials?: Testimonial[];\n  /** Drift speed in pixels per second. Defaults to 26. */\n  speed?: number;\n};\n\n/* ------------------------------------------------------------------ */\n/* deterministic demo data                                             */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_TESTIMONIALS: Testimonial[] = [\n  {\n    id: \"t01\",\n    name: \"Maya Chen\",\n    role: \"Head of Product · B2B SaaS\",\n    quote:\n      \"We replaced three dashboards with one screen. The team finally looks at the same numbers.\",\n    rating: 5,\n  },\n  {\n    id: \"t02\",\n    name: \"Jonas Weber\",\n    role: \"Design Director · Fintech\",\n    quote:\n      \"The motion is quiet enough to use in production. Nothing shouts for attention.\",\n    rating: 5,\n  },\n  {\n    id: \"t03\",\n    name: \"Priya Raman\",\n    role: \"Engineering Lead · Infrastructure\",\n    quote:\n      \"Setup took an afternoon. It reads like code we would have written ourselves.\",\n    rating: 5,\n  },\n  {\n    id: \"t04\",\n    name: \"Elias Moreau\",\n    role: \"Founder · Analytics\",\n    quote:\n      \"Our weekly review went from forty minutes of screenshots to a single glance.\",\n    rating: 5,\n  },\n  {\n    id: \"t05\",\n    name: \"Nora Kim\",\n    role: \"Product Designer · Health\",\n    quote:\n      \"Every block is legible in dark mode, which is rarer than it should be.\",\n    rating: 4,\n  },\n  {\n    id: \"t06\",\n    name: \"Tomás Silva\",\n    role: \"Frontend Lead · Logistics\",\n    quote:\n      \"The charts feel considered. Small details, but they add up across the product.\",\n    rating: 5,\n  },\n  {\n    id: \"t07\",\n    name: \"Hannah Brooks\",\n    role: \"Head of Data · Retail\",\n    quote:\n      \"We shipped the first dashboard before lunch and have not touched the layout since.\",\n    rating: 5,\n  },\n  {\n    id: \"t08\",\n    name: \"Aiko Tanaka\",\n    role: \"Design Systems Lead · Media\",\n    quote:\n      \"Clear defaults, tidy tokens, no surprises when we themed it for our brand.\",\n    rating: 4,\n  },\n  {\n    id: \"t09\",\n    name: \"Sam Okafor\",\n    role: \"Product Manager · Education\",\n    quote:\n      \"It gave our metrics a calm home. The numbers finally have room to breathe.\",\n    rating: 5,\n  },\n  {\n    id: \"t10\",\n    name: \"Lea Fischer\",\n    role: \"Co-founder · Productivity\",\n    quote:\n      \"A rare UI kit that our designers and engineers both want to keep using.\",\n    rating: 5,\n  },\n];\n\n/* ------------------------------------------------------------------ */\n/* helpers                                                             */\n/* ------------------------------------------------------------------ */\n\nfunction getInitials(name: string) {\n  const initials = name\n    .trim()\n    .split(/\\s+/)\n    .slice(0, 2)\n    .map((part) => part.charAt(0).toUpperCase())\n    .join(\"\");\n  return initials || \"—\";\n}\n\n/* ------------------------------------------------------------------ */\n/* card                                                                */\n/* ------------------------------------------------------------------ */\n\ntype TestimonialCardProps = {\n  item: Testimonial;\n  /** Marquee cards join the tab order so keyboard focus can pause the row. */\n  focusable: boolean;\n  className?: string;\n};\n\nfunction TestimonialCard({ item, focusable, className }: TestimonialCardProps) {\n  const rating = Math.max(0, Math.min(5, Math.round(item.rating)));\n\n  return (\n    <article\n      tabIndex={focusable ? 0 : -1}\n      className={cn(\n        \"flex flex-col justify-between gap-4 rounded-xl border border-border bg-card p-5 text-card-foreground shadow-sm transition-colors hover:border-muted-foreground/30\",\n        focusable &&\n          \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n        className\n      )}\n    >\n      <div>\n        <div\n          className=\"flex items-center gap-0.5\"\n          role=\"img\"\n          aria-label={`${rating} out of 5 stars`}\n        >\n          {Array.from({ length: 5 }, (_, index) => (\n            <Star\n              key={index}\n              aria-hidden=\"true\"\n              strokeWidth={1.5}\n              fill={index < rating ? \"currentColor\" : \"none\"}\n              className={cn(\n                \"h-3.5 w-3.5\",\n                index < rating\n                  ? \"text-foreground\"\n                  : \"text-muted-foreground/35\"\n              )}\n            />\n          ))}\n        </div>\n\n        <blockquote className=\"mt-3 text-[13.5px] leading-relaxed text-muted-foreground\">\n          &ldquo;{item.quote}&rdquo;\n        </blockquote>\n      </div>\n\n      <div className=\"flex items-center gap-3 border-t border-border pt-4\">\n        <span\n          aria-hidden=\"true\"\n          className=\"flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-border bg-muted text-[11px] font-semibold tracking-wide text-foreground\"\n        >\n          {getInitials(item.name)}\n        </span>\n        <div className=\"min-w-0\">\n          <div className=\"truncate text-[13px] font-medium text-foreground\">\n            {item.name}\n          </div>\n          <div className=\"truncate text-[11.5px] text-muted-foreground\">\n            {item.role}\n          </div>\n        </div>\n      </div>\n    </article>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* marquee row                                                         */\n/* ------------------------------------------------------------------ */\n\ntype MarqueeRowProps = {\n  items: Testimonial[];\n  direction: \"left\" | \"right\";\n  speed: number;\n  paused: boolean;\n  active: boolean;\n};\n\nfunction MarqueeRow({\n  items,\n  direction,\n  speed,\n  paused,\n  active,\n}: MarqueeRowProps) {\n  const x = useMotionValue(0);\n  const trackRef = useRef<HTMLDivElement>(null);\n  const halfRef = useRef(0);\n  const lastRef = useRef<number | null>(null);\n  const primedRef = useRef(false);\n  const pausedRef = useRef(paused);\n  const activeRef = useRef(active);\n\n  useEffect(() => {\n    pausedRef.current = paused;\n  }, [paused]);\n\n  useEffect(() => {\n    activeRef.current = active;\n  }, [active]);\n\n  useEffect(() => {\n    primedRef.current = false;\n    lastRef.current = null;\n  }, [direction, items.length]);\n\n  /* Each copy is identical, so one copy width is the seamless loop length. */\n  useEffect(() => {\n    const el = trackRef.current;\n    if (!el) return;\n\n    const measure = () => {\n      halfRef.current = el.scrollWidth / 2;\n    };\n    measure();\n\n    if (typeof ResizeObserver === \"undefined\") return;\n    const observer = new ResizeObserver(measure);\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [items.length]);\n\n  useAnimationFrame((time) => {\n    const half = halfRef.current;\n    if (half <= 0) return;\n\n    if (!primedRef.current) {\n      primedRef.current = true;\n      if (direction === \"right\") x.set(-half);\n      lastRef.current = time;\n      return;\n    }\n\n    const last = lastRef.current ?? time;\n    lastRef.current = time;\n\n    if (!activeRef.current || pausedRef.current) return;\n\n    const dt = Math.min(64, time - last) / 1000;\n    let next = x.get() + (direction === \"left\" ? -speed : speed) * dt;\n\n    /* Snap at the seam: copy two is pixel-identical to copy one. */\n    if (direction === \"left\") {\n      if (next <= -half) next = 0;\n    } else if (next >= 0) {\n      next = -half;\n    }\n\n    x.set(next);\n  });\n\n  return (\n    <div className=\"relative overflow-hidden py-1.5\">\n      <motion.div\n        ref={trackRef}\n        style={{ x }}\n        className=\"flex w-max will-change-transform\"\n      >\n        {[0, 1].map((copy) => (\n          <div\n            key={copy}\n            className=\"flex shrink-0 gap-4 pr-4\"\n            aria-hidden={copy === 1 ? true : undefined}\n          >\n            {items.map((item) => (\n              <TestimonialCard\n                key={`${copy}-${item.id}`}\n                item={item}\n                focusable={copy === 0}\n                className=\"w-[264px] shrink-0 sm:w-[304px]\"\n              />\n            ))}\n          </div>\n        ))}\n      </motion.div>\n\n      <div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-y-0 left-0 w-10 bg-gradient-to-r from-background to-transparent sm:w-16\"\n      />\n      <div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-y-0 right-0 w-10 bg-gradient-to-l from-background to-transparent sm:w-16\"\n      />\n    </div>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* the one lens accent                                                 */\n/* ------------------------------------------------------------------ */\n\nfunction LensMark({ show, reduce }: { show: boolean; reduce: boolean }) {\n  return (\n    <motion.span\n      aria-hidden=\"true\"\n      initial={{ rotate: -40, opacity: 0 }}\n      animate={\n        show || reduce\n          ? { rotate: 28, opacity: 1 }\n          : { rotate: -40, opacity: 0 }\n      }\n      transition={\n        reduce\n          ? { duration: 0 }\n          : { duration: 0.9, ease: EASE, delay: 0.1 }\n      }\n      className=\"relative inline-flex h-4 w-4 shrink-0 items-center justify-center\"\n    >\n      <span className=\"absolute inset-0 rounded-full border border-border\" />\n      <span className=\"absolute left-1/2 top-1/2 h-1.5 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full border border-foreground/40\" />\n      <span className=\"absolute left-[1.5px] top-[1.5px] h-1 w-1 rounded-full bg-foreground\" />\n    </motion.span>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function TestimonialMarquee({\n  className,\n  eyebrow = \"Testimonials\",\n  title = \"Teams who build calm dashboards\",\n  description = \"A few words from people using these blocks in production.\",\n  testimonials = DEFAULT_TESTIMONIALS,\n  speed = 26,\n}: TestimonialMarqueeProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n  const [hovering, setHovering] = useState(false);\n  const [focusWithin, setFocusWithin] = useState(false);\n  const [manualPaused, setManualPaused] = useState(false);\n\n  const safeSpeed = Math.max(8, speed);\n  const split = Math.max(1, Math.ceil(testimonials.length / 2));\n  const rowOne = testimonials.slice(0, split);\n  const rowTwo = testimonials.slice(split);\n  const paused = hovering || focusWithin || manualPaused;\n\n  const header = (\n    <div className=\"flex flex-wrap items-end justify-between gap-3 pb-5\">\n      <div className=\"min-w-0\">\n        <div className=\"flex items-center gap-2\">\n          <LensMark show={inView} reduce={reduce} />\n          <span className=\"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground\">\n            {eyebrow}\n          </span>\n        </div>\n        <h2 className=\"mt-2 text-lg font-semibold tracking-tight text-foreground sm:text-xl\">\n          {title}\n        </h2>\n        {description ? (\n          <p className=\"mt-1 max-w-md text-sm text-muted-foreground\">\n            {description}\n          </p>\n        ) : null}\n      </div>\n\n      {reduce ? null : (\n        <button\n          type=\"button\"\n          onClick={() => setManualPaused((value) => !value)}\n          aria-pressed={manualPaused}\n          aria-label={manualPaused ? \"Resume testimonials\" : \"Pause testimonials\"}\n          className=\"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border bg-card text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n        >\n          {manualPaused ? (\n            <Play className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n          ) : (\n            <Pause className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n          )}\n        </button>\n      )}\n    </div>\n  );\n\n  if (reduce) {\n    return (\n      <MotionConfig reducedMotion=\"user\">\n        <div\n          ref={ref}\n          className={cn(\"w-full bg-background text-foreground\", className)}\n        >\n          {header}\n          <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3\">\n            {testimonials.map((item) => (\n              <TestimonialCard\n                key={item.id}\n                item={item}\n                focusable={false}\n              />\n            ))}\n          </div>\n        </div>\n      </MotionConfig>\n    );\n  }\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={ref}\n        initial={{ opacity: 0, y: 16 }}\n        animate={inView ? { opacity: 1, y: 0 } : { opacity: 0, y: 16 }}\n        transition={{ duration: 0.6, ease: EASE }}\n        onPointerEnter={() => setHovering(true)}\n        onPointerLeave={() => setHovering(false)}\n        onFocusCapture={() => setFocusWithin(true)}\n        onBlurCapture={(event) => {\n          const next = event.relatedTarget as Node | null;\n          if (!next || !event.currentTarget.contains(next)) {\n            setFocusWithin(false);\n          }\n        }}\n        className={cn(\"w-full bg-background text-foreground\", className)}\n      >\n        {header}\n        <div className=\"flex flex-col gap-3\">\n          <MarqueeRow\n            items={rowOne}\n            direction=\"left\"\n            speed={safeSpeed}\n            paused={paused}\n            active={inView}\n          />\n          {rowTwo.length > 0 ? (\n            <MarqueeRow\n              items={rowTwo}\n              direction=\"right\"\n              speed={safeSpeed}\n              paused={paused}\n              active={inView}\n            />\n          ) : null}\n        </div>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n\nexport default TestimonialMarquee;\n"}]}