{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stagger-list",
  "type": "registry:ui",
  "title": "Stagger List",
  "description": "A list whose items arrive one after another the first time it scrolls into view: steps of a process, recent updates, the points of an argument. The arrival gives the eye an order to read in; the list itself is ordinary.",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "decorative",
    "effect"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/stagger-list.tsx",
      "target": "components/ui/effects/stagger-list.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/stagger-list v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/stagger-list\n// What changed since: https://ds.interlace.tools/c/stagger-list#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — StaggerList\n *\n * A list whose items arrive one after another the first time it scrolls into\n * view: steps of a process, recent updates, the points of an argument. The\n * arrival gives the eye an order to read in; the list itself is ordinary.\n *\n * ## Content first\n *\n * Every item is in the HTML from the server, in a real `ul` or `ol`, so a\n * screen reader, a crawler and a reader without scripts get the whole list.\n * The motion only decides when each item becomes visible, once, and never\n * moves, removes or repeats an item. There is no loop and nothing to pause.\n *\n * ## Motion\n *\n * Before the first paint, items below the fold are set to transparent; when\n * the list enters the viewport each one fades and rises a few pixels, `step`\n * milliseconds after the one before. It runs on the Web Animations API, so\n * there are no keyframes to add. Under `prefers-reduced-motion: reduce` the\n * items are simply there. An item that receives focus before its turn shows\n * at once, so focus never lands on something invisible.\n *\n * ## Composition\n *\n *   StaggerList                        (ul or ol — data-slot=\"stagger-list\")\n *     └─ li × n                        (one per child — data-slot=\"stagger-list-item\")\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `ul` / `ol` props                                     |\n * | R6   | data-slot per part      | stagger-list / -item                                  |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                     |\n * | R8   | Enums, not booleans     | `as`, `gap`                                           |\n * | R25  | Client component        | the reveal runs in the browser                        |\n * | R26  | A11y from native el     | list semantics; focus reveals at once                 |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\n\nconst GAP = { none: 'gap-0', sm: 'gap-2', md: 'gap-4', lg: 'gap-6' } as const;\n\nexport interface StaggerListProps extends React.ComponentPropsWithoutRef<'ul'> {\n  /** A bulleted list, or a numbered one when the order is the point. @default 'ul' */\n  as?: 'ul' | 'ol';\n  /** Milliseconds between one item and the next. @default 90 */\n  step?: number;\n  /** Milliseconds each item takes to arrive. @default 420 */\n  duration?: number;\n  /** Space between items. @default 'md' */\n  gap?: keyof typeof GAP;\n}\n\nexport function StaggerList({\n  as: List = 'ul',\n  step = 90,\n  duration = 420,\n  gap = 'md',\n  className,\n  children,\n  ...props\n}: StaggerListProps) {\n  const reduced = useReducedMotion();\n  const listRef = React.useRef<HTMLUListElement & HTMLOListElement>(null);\n\n  // Before paint: hide the items, so they can arrive instead of flashing.\n  React.useLayoutEffect(() => {\n    const list = listRef.current;\n    if (!list || reduced || typeof list.animate !== 'function') return;\n    if (typeof IntersectionObserver === 'undefined') return;\n    const items = Array.from(list.children) as HTMLElement[];\n    for (const item of items) item.style.opacity = '0';\n\n    const reveal = (item: HTMLElement, delay: number) => {\n      if (item.dataset.revealed) return;\n      item.dataset.revealed = 'true';\n      item.style.opacity = '';\n      item.animate(\n        [\n          { opacity: 0, transform: 'translateY(0.5rem)' },\n          { opacity: 1, transform: 'none' },\n        ],\n        { duration, delay, easing: 'cubic-bezier(0.2, 0, 0, 1)', fill: 'backwards' },\n      );\n    };\n    const onFocus = (event: FocusEvent) => {\n      const item = (event.target as HTMLElement).closest<HTMLElement>('[data-slot=stagger-list-item]');\n      if (item) reveal(item, 0);\n    };\n    list.addEventListener('focusin', onFocus);\n\n    const io = new IntersectionObserver(\n      (entries) => {\n        if (!entries.some((e) => e.isIntersecting)) return;\n        io.disconnect();\n        items.forEach((item, i) => reveal(item, i * step));\n      },\n      { threshold: 0.15 },\n    );\n    io.observe(list);\n\n    return () => {\n      io.disconnect();\n      list.removeEventListener('focusin', onFocus);\n      for (const item of items) {\n        item.style.opacity = '';\n        delete item.dataset.revealed;\n        for (const a of item.getAnimations?.() ?? []) a.cancel();\n      }\n    };\n  }, [reduced, step, duration, React.Children.count(children)]);\n\n  return (\n    <List\n      ref={listRef}\n      data-slot=\"stagger-list\"\n      className={cn('grid', List === 'ol' ? 'list-decimal ps-6' : 'list-none p-0', GAP[gap], className)}\n      {...props}\n    >\n      {React.Children.map(children, (child) =>\n        child === null || child === undefined || child === false ? null : (\n          <li data-slot=\"stagger-list-item\">{child}</li>\n        ),\n      )}\n    </List>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.0",
    "since": null
  },
  "docs": "## @interlace/stagger-list\n\nInstalled to `components/ui/effects/stagger-list.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/stagger-list';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/stagger-list\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
