{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thread-steps",
  "type": "registry:ui",
  "title": "Thread Steps",
  "description": "An ordered sequence held together by Interlace's woven thread: a knot for each step, and two strands that cross between one knot and the next. The strands draw in as the reader reaches each step, so the motion says one thing only: this leads to that.",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "blog",
    "pattern"
  ],
  "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/patterns/thread-steps.tsx",
      "target": "components/ui/patterns/thread-steps.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/thread-steps v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/thread-steps\n// What changed since: https://ds.interlace.tools/c/thread-steps#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ThreadSteps\n *\n * An ordered sequence held together by Interlace's woven thread: a knot for\n * each step, and two strands that cross between one knot and the next. The\n * strands draw in as the reader reaches each step, so the motion says one\n * thing only: this leads to that.\n *\n * Built for \"how it works\", \"how we checked this\", a process, a short\n * history. Give steps a `state` and the same list becomes a progress\n * tracker: complete steps are woven, the current step's knot is ringed, and\n * the thread ahead of it is a loose, dotted strand that has not been woven\n * yet.\n *\n * ## Anatomy\n *\n *   ThreadSteps                       (ol — data-min-viewport=320)\n *     └─ ThreadStep × n               (li — aria-current=\"step\" when current)\n *         ├─ knot                     (span — the step's marker)\n *         ├─ strand                   (svg, aria-hidden — to the next knot; none after the last)\n *         ├─ title                    (p — font-medium)\n *         ├─ state text               (sr-only \"Complete\" / \"Current step\" / \"Not started\")\n *         └─ children                 (div — the step in words)\n *\n * ## States\n *\n * | `state`     | Knot                 | Strand to the next step          |\n * | ----------- | -------------------- | -------------------------------- |\n * | (none)      | filled               | woven (two strands crossing)     |\n * | `complete`  | filled               | woven                            |\n * | `current`   | ringed               | loose (one dotted strand)        |\n * | `upcoming`  | hollow               | loose                            |\n *\n * The state is also in words for assistive tech, so colour and shape only\n * repeat what the text says.\n *\n * ## Motion\n *\n * The woven strands are in the server HTML, fully drawn. On the client,\n * before paint, they are hidden and then drawn top to bottom when the step\n * scrolls into view: the draw verb's clip mechanism (600ms, a `clip-path`\n * inset opening downward, Web Animations API), as `weave-reveal` does for\n * TimeSeries. Not stroke-dashoffset: the strand box stretches with the step,\n * and Chromium measures dashes on a non-scaling stroke in screen pixels,\n * ignoring `pathLength` (see InterlaceWeave), so a tall step would draw as\n * dashes. Under `prefers-reduced-motion: reduce`, without\n * IntersectionObserver, or without JavaScript, the strands are simply there.\n * Loose strands never move: there is nothing to explain yet.\n *\n * ## MIN_VIEWPORT — 320\n *\n * A 1.5rem gutter and a text column that wraps; nothing has a fixed width.\n *\n * | Rule | Concept                          | Where in this file                                          |\n * | ---- | -------------------------------- | ----------------------------------------------------------- |\n * | R4   | Extends native el                | `ol` / `li` props                                           |\n * | R6   | data-slot per part               | thread-steps / thread-step / -knot / -strand                |\n * | R7   | cn + ...rest                     | `cn(…, className)` + `{...props}`                           |\n * | R8   | Enums, not booleans              | `state`                                                     |\n * | R14  | Declares min viewport            | `data-min-viewport` on the root + exported const            |\n * | R19  | Tokens only                      | `stroke-strand-a/-b`, `bg-primary`, `border-border`         |\n * | R25  | Client component                 | the draw-in needs IntersectionObserver + `Element.animate`  |\n * | R26  | A11y from native el              | A real ordered list; `aria-current=\"step\"`; state in words  |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\n\nexport const MIN_VIEWPORT = 320 as const;\n\nexport type ThreadStepState = 'complete' | 'current' | 'upcoming';\n\nconst STATE_TEXT: Record<ThreadStepState, string> = {\n  complete: 'Complete',\n  current: 'Current step',\n  upcoming: 'Not started',\n};\n\nconst KNOT: Record<ThreadStepState | 'none', string> = {\n  none: 'border-primary bg-primary',\n  complete: 'border-primary bg-primary',\n  current: 'border-primary bg-background ring-primary/30 ring-4',\n  upcoming: 'border-border bg-background',\n};\n\n/** Two strands that leave a knot together, cross, and meet at the next one. */\nconst WOVEN = ['M6 0 C0 33, 12 67, 6 100', 'M6 0 C12 33, 0 67, 6 100'] as const;\n\nconst HIDDEN = 'inset(0 0 100% 0)';\nconst SHOWN = 'inset(0 0 0 0)';\n\nfunction ThreadSteps({ className, ...props }: React.ComponentProps<'ol'>) {\n  return (\n    <ol\n      data-slot=\"thread-steps\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('m-0 list-none p-0', className)}\n      {...props}\n    />\n  );\n}\n\ntype ThreadStepProps = Omit<React.ComponentProps<'li'>, 'title'> & {\n  /** What happens in this step, in a few words. */\n  title: React.ReactNode;\n  /**\n   * Where the reader is in the sequence. Leave it out for a plain sequence\n   * (\"how it works\"); set it on every step for a progress tracker.\n   */\n  state?: ThreadStepState;\n};\n\nfunction ThreadStep({ title, state, className, children, ...props }: ThreadStepProps) {\n  const ref = React.useRef<HTMLLIElement>(null);\n  const reduced = useReducedMotion();\n  const woven = state === undefined || state === 'complete';\n\n  // Before paint: hide the woven strands, then draw them when the step is\n  // reached. The server HTML keeps them drawn, so nothing depends on this.\n  React.useLayoutEffect(() => {\n    const step = ref.current;\n    if (!step || !woven || reduced) return;\n    if (typeof IntersectionObserver === 'undefined') return;\n    // The last step has no strand on screen (`group-last/step:hidden`). Leave\n    // it alone, so a step appended later shows its strand drawn, not clipped.\n    if (step.matches(':last-child')) return;\n    const strand = step.querySelector<HTMLElement>('[data-slot=\"thread-step-strand\"]')!;\n    if (typeof strand.animate !== 'function') return;\n    strand.style.clipPath = HIDDEN;\n\n    const io = new IntersectionObserver(\n      (entries) => {\n        if (!entries.some((e) => e.isIntersecting)) return;\n        io.disconnect();\n        strand.style.clipPath = '';\n        strand.animate([{ clipPath: HIDDEN }, { clipPath: SHOWN }], {\n          duration: 600,\n          easing: 'ease-out',\n          fill: 'backwards',\n        });\n      },\n      { threshold: 0.4 },\n    );\n    io.observe(step);\n    return () => {\n      io.disconnect();\n      strand.style.clipPath = '';\n      for (const a of strand.getAnimations?.() ?? []) a.cancel();\n    };\n  }, [woven, reduced]);\n\n  return (\n    <li\n      ref={ref}\n      data-slot=\"thread-step\"\n      data-state={state}\n      aria-current={state === 'current' ? 'step' : undefined}\n      className={cn(\n        'group/step relative grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 pb-8 last:pb-0',\n        className,\n      )}\n      {...props}\n    >\n      <span aria-hidden className=\"flex justify-center pt-1.5\">\n        <span\n          data-slot=\"thread-step-knot\"\n          className={cn('size-3 rounded-full border-2', KNOT[state ?? 'none'])}\n        />\n      </span>\n      {/* The box sizes the strand: an <svg> is a replaced element, so\n          top + bottom alone would leave it at its intrinsic height. */}\n      <span\n        data-slot=\"thread-step-strand\"\n        aria-hidden\n        className=\"pointer-events-none absolute top-6 bottom-0 start-0 w-6 group-last/step:hidden\"\n      >\n        <svg\n          viewBox=\"0 0 12 100\"\n          preserveAspectRatio=\"none\"\n          fill=\"none\"\n          className=\"block size-full\"\n          aria-hidden\n          focusable=\"false\"\n        >\n          {woven ? (\n            WOVEN.map((d, i) => (\n              <path\n                key={d}\n                d={d}\n                strokeWidth={1.5}\n                vectorEffect=\"non-scaling-stroke\"\n                className={i === 0 ? 'stroke-strand-a' : 'stroke-strand-b'}\n              />\n            ))\n          ) : (\n            <path\n              d=\"M6 0 L6 100\"\n              strokeWidth={1.5}\n              strokeDasharray=\"2 4\"\n              strokeLinecap=\"round\"\n              vectorEffect=\"non-scaling-stroke\"\n              className=\"stroke-muted-foreground opacity-50\"\n            />\n          )}\n        </svg>\n      </span>\n      <div className=\"col-start-2 min-w-0 space-y-1\">\n        <p className=\"font-medium leading-6\">\n          {title}\n          {state ? <span className=\"sr-only\">{` (${STATE_TEXT[state]})`}</span> : null}\n        </p>\n        {children ? (\n          <div className=\"text-muted-foreground text-sm leading-relaxed\">{children}</div>\n        ) : null}\n      </div>\n    </li>\n  );\n}\n\nconst ThreadStepsWithDot = Object.assign(ThreadSteps, { Step: ThreadStep });\n\nexport { ThreadStepsWithDot as ThreadSteps, ThreadStep };\nexport type { ThreadStepProps };\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/thread-steps\n\nInstalled to `components/ui/patterns/thread-steps.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/thread-steps';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/thread-steps\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
