{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "logo-cloud-swap",
  "title": "Logo cloud swap",
  "description": "Customers’ logos in eight slots, one rolling to a customer still waiting every few seconds, never beside the last; held while the pointer is over it or a logo has focus.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/hold.json",
    "https://kinoui.com/r/logo-cloud-parts.json",
    "https://kinoui.com/r/swap.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/logo-cloud-swap/logo-cloud-swap.tsx",
      "content": "'use client'\n\nimport { useHold, useTurns } from '@/registry/lib/hold'\nimport {\n  type CustomerLogo,\n  logoCloudColumnClassName,\n  LogoCloudLink,\n  LogoCloudLogo,\n  type LogoCloudProps,\n  logoCloudSectionClassName,\n  LogoCloudTitle,\n} from '@/registry/lib/logo-cloud-parts'\nimport { Swap } from '@/registry/lib/swap'\nimport { useId, useRef, useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * Eight logos in eight slots, and every few seconds one slot rolls to a\n * customer still waiting, never the slot beside the last one, so more\n * logos fit in little room. It holds while the pointer is over it, while a\n * logo has focus and while it is out of view; under reduced motion the logos\n * change with a fade and nothing travels. A logo with a story is a link.\n *\n *   <LogoCloudSwap\n *     title='Trusted by teams that plan their week in Kino'\n *     logos={[{ name: 'Tessel', src: '/logos/tessel.svg', width: 560, height: 159 }]}\n *   />\n */\n\nfunction LogoCloudSwap({\n  title,\n  heading = 'h2',\n  logos,\n  className,\n  ...props\n}: LogoCloudProps) {\n  const titleId = useId()\n  const listRef = useRef<HTMLUListElement>(null)\n  const hold = useHold()\n  const [state, setState] = useState(() => swapStart(logos.length))\n  // A new set of logos starts again from the first eight.\n  const [lastCount, setLastCount] = useState(logos.length)\n  if (lastCount !== logos.length) {\n    setLastCount(logos.length)\n    setState(swapStart(logos.length))\n  }\n  useTurns(listRef, hold.running && state.waiting.length > 0, SWAP_EVERY, () =>\n    setState(swapNext),\n  )\n  return (\n    <section\n      data-slot='logo-cloud-swap'\n      aria-labelledby={titleId}\n      className={cn(logoCloudSectionClassName, className)}\n      {...props}\n    >\n      <div className={cn(logoCloudColumnClassName, 'flex flex-col gap-8')}>\n        <LogoCloudTitle id={titleId} title={title} heading={heading} />\n        {/* A short last row sits in the middle. */}\n        <ul\n          ref={listRef}\n          aria-labelledby={titleId}\n          className='flex flex-wrap justify-center'\n          {...hold.handlers}\n        >\n          {state.shown.map((index, slot) => (\n            // oxlint-disable-next-line react/no-array-index-key -- a slot stays where it is while its logo changes\n            <Slot key={slot} logo={logos[index]} />\n          ))}\n        </ul>\n      </div>\n    </section>\n  )\n}\n\nfunction Slot({ logo }: { logo: CustomerLogo | undefined }) {\n  return (\n    <li className='flex h-16 min-w-0 basis-1/2 items-center justify-center overflow-clip px-3 @3xl/logo-cloud:h-20 @3xl/logo-cloud:basis-1/4'>\n      {logo ? (\n        // A logo with a story is a link; the one leaving can't take focus.\n        <Swap id={logo.name} roll className='max-w-full [--swap-default-roll:2rem]'>\n          <SlotLogo logo={logo} />\n        </Swap>\n      ) : null}\n    </li>\n  )\n}\n\nfunction SlotLogo({ logo }: { logo: CustomerLogo }) {\n  const { href } = logo\n  return href ? (\n    <LogoCloudLink\n      logo={{ ...logo, href }}\n      className='text-muted-foreground hover:text-foreground flex max-w-full items-center rounded-(--control-radius-xs) p-2 transition-colors duration-(--motion-press-duration) ease-(--motion-press-fade-easing)'\n    >\n      <LogoCloudLogo logo={logo} />\n    </LogoCloudLink>\n  ) : (\n    <span className='text-muted-foreground flex max-w-full items-center p-2'>\n      <LogoCloudLogo logo={logo} />\n    </span>\n  )\n}\n\n/** How many slots show at once: two rows of four, or four rows of two on a phone. */\nconst SLOTS = 8\n\n/**\n * The order the slots change in: each one is never beside the last, across\n * or down, whether the slots stand in 2, 4 or 8 columns.\n */\nconst SLOT_ORDER = [0, 3, 6, 1, 4, 7, 2, 5]\n\n/** Which logos the slots show, which wait their turn, oldest first, and how many changes have played. */\ninterface SwapState {\n  shown: number[]\n  waiting: number[]\n  turn: number\n}\n\n/** The first logos in the slots, and the rest waiting in order. */\nfunction swapStart(count: number): SwapState {\n  const all = Array.from({ length: count }, (_, index) => index)\n  return { shown: all.slice(0, SLOTS), waiting: all.slice(SLOTS), turn: 0 }\n}\n\n/** The next change: the slot whose turn it is takes the logo that has waited longest, and its own logo waits at the back. */\nfunction swapNext(state: SwapState): SwapState {\n  const [incoming, ...rest] = state.waiting\n  if (incoming === undefined || state.shown.length < SLOTS) return state\n  const slot = SLOT_ORDER[state.turn % SLOT_ORDER.length]\n  const shown = state.shown.map((logo, index) => (index === slot ? incoming : logo))\n  return { shown, waiting: [...rest, state.shown[slot]], turn: state.turn + 1 }\n}\n\n/** How many `layout` durations a logo shows before the next slot changes: about three seconds in the default feel. */\nconst SWAP_EVERY = 5\n\nexport { LogoCloudSwap, swapNext, swapStart }\n",
      "type": "registry:component",
      "target": "@components/kino/logo-cloud-swap/logo-cloud-swap.tsx"
    }
  ],
  "type": "registry:block"
}