{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "testimonials-02",
  "title": "Quote carousel",
  "description": "One sample quote at a time: the bar under the current quote fills while it waits and the next one slides in from the side it comes from, held under the pointer, by keyboard focus and off screen, with Pause, arrows and keyed dots.",
  "dependencies": [
    ",\n      },\n      { kind: ",
    "@base-ui/react",
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/testimonials/testimonials-02/index.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  useInView,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useId, useRef, useState } from 'react';\n\nimport { useDocumentVisible } from '@/registry/ndeko/hooks/use-agent-run';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { QuoteIcon } from '@/registry/ndeko/lib/icons';\nimport { EASE_OUT_STRONG } from '@/registry/ndeko/lib/motion-presets';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { CarouselControls, tabIdOf } from './carousel-controls';\nimport { SECTION, SLIDES } from './data';\nimport { QuoteSlide } from './quote-slide';\nimport { useSlideClock } from './use-slide-clock';\n\ntype Direction = 1 | -1;\n\n/** `auto` turns unless the system asks for reduced motion; a person's Play or Pause decides from then on. */\ntype Rotation = 'auto' | 'on' | 'off';\n\nconst SLIDE_MS = 7000;\n\nconst TRAVEL_PX = 24;\n\nconst BLURRED = 'blur(4px)';\n\nconst ENTER: Transition = { duration: 0.4, ease: EASE_OUT_STRONG };\n\nconst EXIT: Transition = { duration: 0.2, ease: EASE_OUT_STRONG };\n\nfunction enteringOf(direction: Direction) {\n  const x = direction * TRAVEL_PX;\n  return { opacity: 0, x, filter: BLURRED };\n}\n\nfunction leavingOf(direction: Direction) {\n  const x = direction * -TRAVEL_PX;\n  return { opacity: 0, x, filter: BLURRED, transition: EXIT };\n}\n\nconst SLIDE_VARIANTS: Variants = {\n  enter: enteringOf,\n  shown: { opacity: 1, x: 0, filter: 'blur(0px)', transition: ENTER },\n  gone: leavingOf,\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  shown: { opacity: 1, transition: ENTER },\n  gone: { opacity: 0, transition: EXIT },\n};\n\nfunction variantsOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SLIDE_VARIANTS;\n}\n\nfunction isRotationOn(rotation: Rotation, shouldReduceMotion: boolean) {\n  if (rotation === 'auto') {\n    return !shouldReduceMotion;\n  }\n  return rotation === 'on';\n}\n\nfunction indexAfter(index: number) {\n  const next = index + 1;\n  return next % SLIDES.length;\n}\n\nfunction indexBefore(index: number) {\n  const shifted = index + SLIDES.length;\n  const previous = shifted - 1;\n  return previous % SLIDES.length;\n}\n\nfunction directionBetween(from: number, to: number): Direction {\n  if (to < from) {\n    return -1;\n  }\n  return 1;\n}\n\nfunction spokenSlideOf(index: number) {\n  const { person } = SLIDES[index];\n  const position = index + 1;\n  return `Quote ${position} of ${SLIDES.length}, ${person.name}, ${person.role} at ${person.company}`;\n}\n\nconst SLIDE_SECONDS = SLIDE_MS / 1000;\n\nconst PLAYING_LINE = `Quotes play again, a new one every ${SLIDE_SECONDS} seconds`;\n\nexport default function Testimonials02() {\n  const [activeIndex, setActiveIndex] = useState(0);\n  const [direction, setDirection] = useState<Direction>(1);\n  const [rotation, setRotation] = useState<Rotation>('auto');\n  const [isHovered, setIsHovered] = useState(false);\n  const [isFocusHeld, setIsFocusHeld] = useState(false);\n  const [message, setMessage] = useState('');\n  const stageRef = useRef<HTMLDivElement>(null);\n  const fillRef = useRef<HTMLSpanElement>(null);\n  const idBase = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const isInView = useInView(stageRef, { amount: 0.3 });\n  const isTabVisible = useDocumentVisible();\n  const isRotating = isRotationOn(rotation, shouldReduceMotion);\n  const isOnScreen = isInView && isTabVisible;\n  const isHeld = isHovered || isFocusHeld;\n  const canTurn = isRotating && isOnScreen;\n  const isClockRunning = canTurn && !isHeld;\n  const activeSlide = SLIDES[activeIndex];\n  const panelId = `${idBase}-panel`;\n  const activeTabId = tabIdOf(idBase, activeSlide.id);\n  const variants = variantsOf(shouldReduceMotion);\n\n  function show(index: number, nextDirection: Direction) {\n    setDirection(nextDirection);\n    setActiveIndex(index);\n  }\n\n  function turn() {\n    show(indexAfter(activeIndex), 1);\n  }\n\n  useSlideClock(fillRef, {\n    slideKey: activeSlide.id,\n    isRotating,\n    isRunning: isClockRunning,\n    durationMs: SLIDE_MS,\n    onEnd: turn,\n  });\n\n  function showByPerson(index: number, nextDirection: Direction) {\n    setRotation('off');\n    show(index, nextDirection);\n    setMessage(spokenSlideOf(index));\n  }\n\n  function showPrevious() {\n    showByPerson(indexBefore(activeIndex), -1);\n  }\n\n  function showNext() {\n    showByPerson(indexAfter(activeIndex), 1);\n  }\n\n  function pick(slideId: string) {\n    const index = SLIDES.findIndex((slide) => slide.id === slideId);\n    const isCurrent = index === activeIndex;\n    if (isCurrent) {\n      return;\n    }\n    showByPerson(index, directionBetween(activeIndex, index));\n  }\n\n  /** Play while the keyboard is inside would otherwise wait for the focus to leave. */\n  function toggleRotation() {\n    if (isRotating) {\n      setRotation('off');\n      setMessage('Quotes paused');\n      return;\n    }\n    setRotation('on');\n    setIsFocusHeld(false);\n    setMessage(PLAYING_LINE);\n  }\n\n  function holdOnKeyboardFocus(event: React.FocusEvent<HTMLElement>) {\n    const isKeyboardFocus = event.target.matches(':focus-visible');\n    if (isKeyboardFocus) {\n      setIsFocusHeld(true);\n    }\n  }\n\n  function releaseWhenFocusLeaves(event: React.FocusEvent<HTMLElement>) {\n    const next = event.relatedTarget;\n    const staysInside = next !== null && event.currentTarget.contains(next);\n    if (!staysInside) {\n      setIsFocusHeld(false);\n    }\n  }\n\n  function holdUnderPointer(event: React.PointerEvent<HTMLDivElement>) {\n    if (event.pointerType === 'mouse') {\n      setIsHovered(true);\n    }\n  }\n\n  function releasePointer() {\n    setIsHovered(false);\n  }\n\n  function stopRotation() {\n    setRotation('off');\n  }\n\n  return (\n    <section\n      aria-roledescription='carousel'\n      aria-label='Sample quotes from Fieldnote customers'\n      onFocus={holdOnKeyboardFocus}\n      onBlur={releaseWhenFocusLeaves}\n      className='@container'\n    >\n      <div className='mx-auto flex max-w-4xl flex-col gap-10 px-4 py-16 @2xl:px-6 @2xl:py-24 @5xl:px-8'>\n        <header className='flex max-w-2xl flex-col gap-3'>\n          <p className='text-primary-ink flex items-center gap-1.5 text-[13px] font-medium'>\n            <QuoteIcon className='size-4' />\n            {SECTION.label}\n          </p>\n          <h2 className='text-2xl font-semibold text-balance @2xl:text-3xl'>\n            {SECTION.title}\n          </h2>\n          <p className='text-muted-foreground text-base text-pretty'>\n            {SECTION.lead}\n          </p>\n        </header>\n        <div className='flex flex-col gap-4'>\n          <div\n            ref={stageRef}\n            onPointerEnter={holdUnderPointer}\n            onPointerLeave={releasePointer}\n            onPointerDown={stopRotation}\n            className='bg-card hairline-ring ring-border dark:bg-foreground/[0.04] rounded-2xl p-6 shadow-[0_1px_2px_rgb(0_0_0/0.04)] @2xl:p-10'\n          >\n            <div\n              id={panelId}\n              role='tabpanel'\n              aria-roledescription='slide'\n              aria-labelledby={activeTabId}\n              className='grid *:col-start-1 *:row-start-1'\n            >\n              {SLIDES.map((slide) => (\n                <div key={slide.id} aria-hidden='true' className='invisible'>\n                  <QuoteSlide slide={slide} />\n                </div>\n              ))}\n              <AnimatePresence initial={false} custom={direction}>\n                <motion.div\n                  key={activeSlide.id}\n                  custom={direction}\n                  variants={variants}\n                  initial='enter'\n                  animate='shown'\n                  exit='gone'\n                >\n                  <QuoteSlide slide={activeSlide} />\n                </motion.div>\n              </AnimatePresence>\n            </div>\n          </div>\n          <div className='flex flex-wrap items-center justify-between gap-3'>\n            <CarouselControls\n              slides={SLIDES}\n              activeId={activeSlide.id}\n              isRotating={isRotating}\n              fillRef={fillRef}\n              tabIdBase={idBase}\n              panelId={panelId}\n              onPick={pick}\n              onPrevious={showPrevious}\n              onNext={showNext}\n              onToggleRotation={toggleRotation}\n            />\n            <Badge variant='secondary'>Sample quotes</Badge>\n          </div>\n        </div>\n      </div>\n      <LiveRegion message={message} />\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/testimonials-02/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/testimonials/testimonials-02/carousel-controls.tsx",
      "content": "'use client';\n\nimport { Tabs as TabsPrimitive } from '@base-ui/react/tabs';\nimport type { RefObject } from 'react';\n\nimport {\n  ChevronLeftIcon,\n  ChevronRightIcon,\n  PauseIcon,\n  PlayIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\n\nimport type { Slide } from './data';\n\nexport function tabIdOf(base: string, slideId: string) {\n  return `${base}-tab-${slideId}`;\n}\n\nfunction rotationLabelOf(isRotating: boolean) {\n  if (isRotating) {\n    return 'Pause the quotes';\n  }\n  return 'Play the quotes';\n}\n\n/** While the quotes turn, the bar of the current one fills from empty; at rest it is full. */\nfunction fillTransformOf(isRotating: boolean) {\n  if (isRotating) {\n    return 'scaleX(0)';\n  }\n  return 'scaleX(1)';\n}\n\nfunction isSlideId(value: unknown, slides: readonly Slide[]) {\n  return slides.some((slide) => slide.id === value);\n}\n\ntype CarouselControlsProps = {\n  slides: readonly Slide[];\n  activeId: string;\n  isRotating: boolean;\n  fillRef: RefObject<HTMLSpanElement | null>;\n  tabIdBase: string;\n  panelId: string;\n  onPick: (slideId: string) => void;\n  onPrevious: () => void;\n  onNext: () => void;\n  onToggleRotation: () => void;\n};\n\nexport function CarouselControls({\n  slides,\n  activeId,\n  isRotating,\n  fillRef,\n  tabIdBase,\n  panelId,\n  onPick,\n  onPrevious,\n  onNext,\n  onToggleRotation,\n}: CarouselControlsProps) {\n  const count = slides.length;\n  const fillStyle = { transform: fillTransformOf(isRotating) };\n\n  function pickTab(value: unknown) {\n    if (isSlideId(value, slides)) {\n      onPick(String(value));\n    }\n  }\n\n  return (\n    <div className='flex items-center gap-1'>\n      <Button\n        type='button'\n        variant='ghost'\n        size='icon-sm'\n        aria-label={rotationLabelOf(isRotating)}\n        onClick={onToggleRotation}\n        className='text-muted-foreground'\n      >\n        <Swap swapKey={String(isRotating)}>\n          {isRotating && <PauseIcon />}\n          {!isRotating && <PlayIcon />}\n        </Swap>\n      </Button>\n      <Button\n        type='button'\n        variant='outline'\n        size='icon-sm'\n        aria-label='Show the previous quote'\n        onClick={onPrevious}\n      >\n        <ChevronLeftIcon />\n      </Button>\n      <TabsPrimitive.Root value={activeId} onValueChange={pickTab}>\n        <TabsPrimitive.List\n          activateOnFocus\n          aria-label='Choose a quote'\n          className='flex items-center px-1'\n        >\n          {slides.map((slide, index) => {\n            const isActive = slide.id === activeId;\n            const position = index + 1;\n\n            return (\n              <TabsPrimitive.Tab\n                key={slide.id}\n                value={slide.id}\n                id={tabIdOf(tabIdBase, slide.id)}\n                aria-controls={panelId}\n                aria-label={`Quote ${position} of ${count}, ${slide.person.name}`}\n                className='group/dot focus-visible:ring-ring focus-visible:ring-offset-background flex h-8 cursor-pointer items-center rounded-full px-1 outline-none focus-visible:ring-2 focus-visible:ring-offset-2'\n              >\n                <span className='bg-foreground/15 group-hover/dot:bg-foreground/25 group-data-active/dot:bg-foreground/20 relative h-1 w-6 overflow-hidden rounded-full transition-colors duration-150'>\n                  {isActive && (\n                    <span\n                      ref={fillRef}\n                      style={fillStyle}\n                      className='bg-foreground absolute inset-0 origin-left rounded-full'\n                    />\n                  )}\n                </span>\n              </TabsPrimitive.Tab>\n            );\n          })}\n        </TabsPrimitive.List>\n      </TabsPrimitive.Root>\n      <Button\n        type='button'\n        variant='outline'\n        size='icon-sm'\n        aria-label='Show the next quote'\n        onClick={onNext}\n      >\n        <ChevronRightIcon />\n      </Button>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/testimonials-02/carousel-controls.tsx"
    },
    {
      "path": "registry/ndeko/blocks/testimonials/testimonials-02/quote-slide.tsx",
      "content": "import { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\n\nimport type { QuotePart, Slide } from './data';\n\nfunction QuotePartView({ part }: { part: QuotePart }) {\n  if (part.kind === 'brand') {\n    return (\n      <span className='whitespace-nowrap'>\n        <BrandTile\n          brand={part.brand}\n          size='md'\n          className='me-1.5 align-[-0.15em]'\n        />\n        {part.text}\n      </span>\n    );\n  }\n  return part.text;\n}\n\n/** The person sits at the foot of the tallest slide, so their line stays put from one quote to the next. */\nexport function QuoteSlide({ slide }: { slide: Slide }) {\n  const { person } = slide;\n\n  return (\n    <figure className='flex h-full flex-col justify-between gap-8'>\n      <blockquote className='text-lg leading-8 font-medium text-pretty @2xl:text-2xl @2xl:leading-9'>\n        <p>\n          {slide.parts.map((part, index) => (\n            <QuotePartView key={index} part={part} />\n          ))}\n        </p>\n      </blockquote>\n      <figcaption className='flex items-center gap-3'>\n        <Avatar seed={person.name} className='size-10' />\n        <span className='flex min-w-0 flex-1 flex-col'>\n          <span className='truncate text-sm font-medium'>{person.name}</span>\n          <span className='text-muted-foreground truncate text-[13px]'>\n            {person.role}, {person.company}\n          </span>\n        </span>\n        <CompanyMark seed={person.company} size='lg' />\n      </figcaption>\n    </figure>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/testimonials-02/quote-slide.tsx"
    },
    {
      "path": "registry/ndeko/blocks/testimonials/testimonials-02/use-slide-clock.ts",
      "content": "'use client';\n\nimport { useEffect, useEffectEvent, useRef, type RefObject } from 'react';\n\nconst FILL: Keyframe[] = [\n  { transform: 'scaleX(0)' },\n  { transform: 'scaleX(1)' },\n];\n\ntype SlideClockOptions = {\n  /** A new key starts a new fill: the slide changed. */\n  slideKey: string;\n  isRotating: boolean;\n  /** False while the rotation is held: the fill stops where it is and goes on from there. */\n  isRunning: boolean;\n  durationMs: number;\n  onEnd: () => void;\n};\n\n/**\n * The time a slide has left is the fill of its bar: a Web Animation on the compositor, so a slide\n * that waits costs no script at all, and a held one costs nothing. Its end moves the carousel on.\n */\nexport function useSlideClock<Fill extends HTMLElement>(\n  fillRef: RefObject<Fill | null>,\n  { slideKey, isRotating, isRunning, durationMs, onEnd }: SlideClockOptions\n) {\n  const animationRef = useRef<Animation | null>(null);\n  const end = useEffectEvent(onEnd);\n\n  useEffect(() => {\n    const fill = fillRef.current;\n    if (!fill || !isRotating) {\n      return;\n    }\n    const animation = fill.animate(FILL, {\n      duration: durationMs,\n      easing: 'linear',\n      fill: 'forwards',\n    });\n    animation.pause();\n    animation.onfinish = () => end();\n    animationRef.current = animation;\n    return () => {\n      animation.onfinish = null;\n      animation.cancel();\n      animationRef.current = null;\n    };\n  }, [fillRef, slideKey, isRotating, durationMs]);\n\n  useEffect(() => {\n    const animation = animationRef.current;\n    if (!animation) {\n      return;\n    }\n    const isPaused = animation.playState === 'paused';\n    const isPlaying = animation.playState === 'running';\n    if (isRunning && isPaused) {\n      animation.play();\n      return;\n    }\n    if (!isRunning && isPlaying) {\n      animation.pause();\n    }\n  }, [isRunning, slideKey, isRotating]);\n}\n",
      "type": "registry:component",
      "target": "components/blocks/testimonials-02/use-slide-clock.ts"
    },
    {
      "path": "registry/ndeko/blocks/testimonials/testimonials-02/data.ts",
      "content": "import type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport type QuotePart =\n  | { kind: 'text'; text: string }\n  | { kind: 'brand'; brand: BrandSlug; text: string };\n\nexport type Person = {\n  name: string;\n  role: string;\n  company: string;\n};\n\nexport type Slide = {\n  id: string;\n  parts: QuotePart[];\n  person: Person;\n};\n\nexport const SECTION = {\n  label: 'Customer quotes',\n  title: 'Teams that stopped taking meeting notes',\n  lead: 'Fieldnote writes the summary while you talk and files each follow-up where it belongs.',\n};\n\n/** Invented people and companies. The quotes are samples written for this block. */\nexport const SLIDES: Slide[] = [\n  {\n    id: 'ines',\n    parts: [\n      {\n        kind: 'text',\n        text: 'I stopped typing during client calls. Fieldnote joins from ',\n      },\n      { kind: 'brand', brand: 'googlecalendar', text: 'Google Calendar' },\n      {\n        kind: 'text',\n        text: ', writes the summary while we talk and has the follow-ups in ',\n      },\n      { kind: 'brand', brand: 'hubspot', text: 'HubSpot' },\n      { kind: 'text', text: ' before I close the tab.' },\n    ],\n    person: {\n      name: 'Ines Carvalho',\n      role: 'Account director',\n      company: 'Harbourline Logistics',\n    },\n  },\n  {\n    id: 'rafael',\n    parts: [\n      {\n        kind: 'text',\n        text: 'Our standups used to repeat themselves. Now the notes land in ',\n      },\n      { kind: 'brand', brand: 'linear', text: 'Linear' },\n      {\n        kind: 'text',\n        text: ' as issues with an owner, and the next standup starts from what moved.',\n      },\n    ],\n    person: {\n      name: 'Rafael Moreno',\n      role: 'Engineering manager',\n      company: 'Mossgrove Labs',\n    },\n  },\n  {\n    id: 'hannah',\n    parts: [\n      {\n        kind: 'text',\n        text: 'The summaries read as if a colleague wrote them: short, in our words, and they never record a decision we did not make.',\n      },\n    ],\n    person: {\n      name: 'Hannah Kowalczyk',\n      role: 'Chief of staff',\n      company: 'Ostrava Labs',\n    },\n  },\n  {\n    id: 'amara',\n    parts: [\n      {\n        kind: 'text',\n        text: 'We run interviews in five languages. Every transcript comes back in English with the quotes kept in the original, which is exactly what our researchers asked for.',\n      },\n    ],\n    person: {\n      name: 'Amara Nwosu',\n      role: 'Research lead',\n      company: 'Tallgrass Health',\n    },\n  },\n  {\n    id: 'mateo',\n    parts: [\n      { kind: 'text', text: 'Every decision goes into ' },\n      { kind: 'brand', brand: 'notion', text: 'Notion' },\n      {\n        kind: 'text',\n        text: ' under the project it belongs to. Six months in, our wiki finally knows why things are the way they are.',\n      },\n    ],\n    person: {\n      name: 'Mateo Silva',\n      role: 'Product lead',\n      company: 'Windrose Travel',\n    },\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/testimonials-02/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "testimonials"
  ],
  "type": "registry:block"
}