{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "demo-tabs",
  "title": "Demo Tabs",
  "description": "A tabbed product demo with a shared playback timeline, progress underline, and customizable scenes. Includes three synchronized terminal-and-result examples.",
  "dependencies": [
    "@base-ui/react",
    "motion",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ui.ericts.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/base/blocks/demo-tabs.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Tabs } from \"@base-ui/react/tabs\";\nimport {\n  motion,\n  motionValue,\n  useTransform,\n  type MotionValue,\n} from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\n\nexport type DemoTabsScene = {\n  /** Shared, linear playback position, from 0 to 1. Use useTransform in a child. */\n  progress: MotionValue<number>;\n  isPlaying: boolean;\n  reducedMotion: boolean;\n};\n\nexport type DemoTabsItem = {\n  /** Unique, stable identifier. */\n  value: string;\n  label: string;\n  description?: string;\n  /** Total scene length in milliseconds, including time to read the final frame. */\n  duration: number;\n  render: (scene: DemoTabsScene) => React.ReactNode;\n};\n\nexport type DemoTabsProps = Omit<\n  React.ComponentProps<\"section\">,\n  \"children\" | \"defaultValue\" | \"onChange\"\n> & {\n  items: readonly DemoTabsItem[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  autoPlay?: boolean;\n  loop?: boolean;\n  selectorLabel?: string;\n  emptyLabel?: string;\n  classNames?: {\n    list?: string;\n    tab?: string;\n    progress?: string;\n    panel?: string;\n  };\n};\n\nfunction ProgressLine({\n  progress,\n  className,\n}: {\n  progress: MotionValue<number>;\n  className?: string;\n}) {\n  const transform = useTransform(progress, (value) => `scaleX(${value})`);\n  return (\n    <motion.span\n      aria-hidden=\"true\"\n      data-slot=\"demo-tabs-progress\"\n      className={cn(\n        \"absolute inset-x-0 bottom-0 h-px origin-left bg-foreground\",\n        className,\n      )}\n      style={{ transform }}\n    />\n  );\n}\n\n/**\n * A single clock drives the active scene and its tab underline, without React\n * renders on every frame. Scenes should derive ALL motion from progress, not\n * start independent timers. Manual selection plays once and disables advancing.\n */\nexport function DemoTabs({\n  items,\n  value,\n  defaultValue,\n  onValueChange,\n  autoPlay = true,\n  loop = true,\n  selectorLabel = \"Choose a demo\",\n  emptyLabel = \"Add a demo to get started.\",\n  classNames,\n  className,\n  ref,\n  onFocusCapture,\n  onBlurCapture,\n  ...props\n}: DemoTabsProps) {\n  const reducedMotion = useReducedMotion();\n  const [selected, setSelected] = React.useState(\n    defaultValue ?? items[0]?.value,\n  );\n  const active =\n    items.find((item) => item.value === (value ?? selected)) ?? items[0];\n  const activeValue = active?.value;\n  const duration =\n    active && Number.isFinite(active.duration) && active.duration > 0\n      ? active.duration\n      : 6000;\n  const [replay, setReplay] = React.useState(0);\n  // A new clock resets both scene and underline atomically, including prop changes.\n  const progress = React.useMemo(() => {\n    void activeValue;\n    void replay;\n    void duration;\n    return motionValue(reducedMotion ? 1 : 0);\n  }, [activeValue, duration, replay, reducedMotion]);\n  const [completed, setCompleted] = React.useState<MotionValue<number> | null>(\n    null,\n  );\n  const [requestedPlaying, setRequestedPlaying] = React.useState(autoPlay);\n  const [previousAutoPlay, setPreviousAutoPlay] = React.useState(autoPlay);\n  if (previousAutoPlay !== autoPlay) {\n    setPreviousAutoPlay(autoPlay);\n    setRequestedPlaying(autoPlay);\n  }\n  const [manual, setManual] = React.useState(false);\n  const [inView, setInView] = React.useState(false);\n  const [visible, setVisible] = React.useState(true);\n  const [contentFocused, setContentFocused] = React.useState(false);\n  const [node, setNode] = React.useState<HTMLElement | null>(null);\n  const mergedRef = React.useCallback(\n    (element: HTMLElement | null) => {\n      setNode(element);\n      if (element && typeof IntersectionObserver === \"undefined\")\n        setInView(true);\n      if (typeof ref === \"function\") return ref(element);\n      if (ref) ref.current = element;\n    },\n    [ref],\n  );\n  const finished = completed === progress;\n  const isPlaying =\n    Boolean(active) &&\n    requestedPlaying &&\n    inView &&\n    visible &&\n    !contentFocused &&\n    !reducedMotion &&\n    !finished;\n\n  React.useEffect(() => {\n    if (!node || typeof IntersectionObserver === \"undefined\") return;\n    const observer = new IntersectionObserver(\n      ([entry]) =>\n        setInView(\n          Boolean(entry?.isIntersecting && entry.intersectionRatio >= 0.2),\n        ),\n      { threshold: 0.2 },\n    );\n    observer.observe(node);\n    return () => observer.disconnect();\n  }, [node]);\n\n  React.useEffect(() => {\n    const update = () => setVisible(!document.hidden);\n    update();\n    document.addEventListener(\"visibilitychange\", update);\n    return () => document.removeEventListener(\"visibilitychange\", update);\n  }, []);\n\n  const complete = React.useEffectEvent(() => {\n    setCompleted(progress);\n    if (manual || items.length < 2) return;\n    const index = items.findIndex((item) => item.value === activeValue);\n    if (index === items.length - 1 && !loop) return;\n    const next = items[(index + 1) % items.length];\n    if (value === undefined) setSelected(next.value);\n    onValueChange?.(next.value);\n  });\n\n  React.useEffect(() => {\n    if (!isPlaying) return;\n    let frame = 0;\n    let last = performance.now();\n    const tick = (now: number) => {\n      // Also guard here: a visibility event can precede React's effect cleanup.\n      if (document.hidden) {\n        last = now;\n        frame = requestAnimationFrame(tick);\n        return;\n      }\n      const next = Math.min(\n        1,\n        progress.get() + Math.max(0, now - last) / duration,\n      );\n      last = now;\n      progress.set(next);\n      if (next >= 1) complete();\n      else frame = requestAnimationFrame(tick);\n    };\n    frame = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(frame);\n  }, [isPlaying, progress, duration]);\n\n  function select(next: string) {\n    setManual(true);\n    setRequestedPlaying(true);\n    if (next === activeValue) setReplay((count) => count + 1);\n    if (value === undefined) setSelected(next);\n    if (next !== activeValue) onValueChange?.(next);\n  }\n\n  return (\n    <section\n      {...props}\n      ref={mergedRef}\n      data-slot=\"demo-tabs\"\n      className={cn(\n        \"@container/demo w-full overflow-hidden rounded-xl border bg-background text-foreground\",\n        className,\n      )}\n      onFocusCapture={(event) => {\n        onFocusCapture?.(event);\n        // Focus alone is not a choice: keyboard users tabbing past the\n        // tablist keep auto-advance. Only `select` (click, Enter/Space on a\n        // tab) switches to manual playback.\n        setContentFocused(\n          Boolean(\n            (event.target as HTMLElement).closest(\n              '[data-slot=\"demo-tabs-panel\"]',\n            ) &&\n            event.currentTarget.contains(\n              (event.target as HTMLElement).closest(\n                '[data-slot=\"demo-tabs-panel\"]',\n              ),\n            ),\n          ),\n        );\n      }}\n      onBlurCapture={(event) => {\n        onBlurCapture?.(event);\n        if (!event.currentTarget.contains(event.relatedTarget))\n          setContentFocused(false);\n      }}\n    >\n      {active ? (\n        <>\n          <Tabs.Root\n            value={active.value}\n            onValueChange={(next) => {\n              if (typeof next === \"string\") select(next);\n            }}\n          >\n            <Tabs.List\n              aria-label={selectorLabel}\n              activateOnFocus={false}\n              className={cn(\"flex overflow-x-auto border-b\", classNames?.list)}\n            >\n              {items.map((item) => (\n                <Tabs.Tab\n                  key={item.value}\n                  value={item.value}\n                  onClick={() => {\n                    if (item.value === activeValue) select(item.value);\n                  }}\n                  className={cn(\n                    \"relative flex min-w-24 flex-1 flex-col items-start gap-1 border-r px-5 py-4 text-left last:border-r-0 focus-visible:z-10 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring data-active:bg-muted/50 @min-[40rem]/demo:min-w-44\",\n                    classNames?.tab,\n                  )}\n                >\n                  <span className=\"font-mono text-xs\">{item.label}</span>\n                  {item.description && (\n                    <span className=\"hidden text-xs whitespace-nowrap text-muted-foreground @min-[40rem]/demo:block\">\n                      {item.description}\n                    </span>\n                  )}\n                  {item.value === activeValue && (\n                    <ProgressLine\n                      progress={progress}\n                      className={classNames?.progress}\n                    />\n                  )}\n                </Tabs.Tab>\n              ))}\n            </Tabs.List>\n            {items.map((item) => (\n              <Tabs.Panel\n                data-slot=\"demo-tabs-panel\"\n                key={item.value}\n                value={item.value}\n                className={cn(\n                  \"outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\",\n                  classNames?.panel,\n                )}\n              >\n                {item.value === activeValue && (\n                  <React.Fragment key={`${item.value}-${replay}`}>\n                    {item.render({ progress, isPlaying, reducedMotion })}\n                  </React.Fragment>\n                )}\n              </Tabs.Panel>\n            ))}\n          </Tabs.Root>\n        </>\n      ) : (\n        <p className=\"p-8 text-sm text-muted-foreground\">{emptyLabel}</p>\n      )}\n    </section>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/blocks/demo-tabs.tsx"
    },
    {
      "path": "registry/base/blocks/demo-tabs-example.tsx",
      "content": "\"use client\";\n\nimport {\n  ArrowUpRightIcon,\n  CheckIcon,\n  FileCodeIcon,\n  GlobeIcon,\n  ShieldCheckIcon,\n} from \"lucide-react\";\nimport { motion, useTransform, type MotionValue } from \"motion/react\";\n\nimport { DemoTabs, type DemoTabsItem, type DemoTabsScene } from \"./demo-tabs\";\n\nconst scripts = {\n  docs: {\n    command: \"atlas docs --quickstart\",\n    lines: [\n      \"Resolving project context…\",\n      \"Found 12 endpoints\",\n      \"Generating typed examples\",\n      \"Documentation ready.\",\n    ],\n    eyebrow: \"YOUR FIRST REQUEST\",\n    title: \"From question to working code.\",\n    description: \"A small example. Everything you need to start.\",\n    icon: FileCodeIcon,\n  },\n  check: {\n    command: \"atlas check --strict\",\n    lines: [\n      \"Reading project configuration…\",\n      \"Types verified · 24 modules\",\n      \"All 18 checks passed\",\n      \"Ready for production.\",\n    ],\n    eyebrow: \"CONFIDENCE, BUILT IN\",\n    title: \"Catch it before you ship it.\",\n    description: \"One check for everything that matters.\",\n    icon: ShieldCheckIcon,\n  },\n  deploy: {\n    command: \"atlas deploy --production\",\n    lines: [\n      \"Building production bundle…\",\n      \"Uploading assets · 142 kB\",\n      \"Propagating to the edge\",\n      \"Live at demo.atlas.dev\",\n    ],\n    eyebrow: \"A SHORTER PATH TO LIVE\",\n    title: \"Local idea. Global release.\",\n    description: \"Your next release is one command away.\",\n    icon: GlobeIcon,\n  },\n} as const;\n\n// Both columns read the same MotionValue. No independent delays or timers:\n// pause, replay and tab changes stay synchronized, even halfway through a reveal.\nfunction Beat({\n  progress,\n  at,\n  children,\n  className,\n}: {\n  progress: MotionValue<number>;\n  at: number;\n  children: React.ReactNode;\n  className?: string;\n}) {\n  const opacity = useTransform(progress, [at, at + 0.06], [0, 1]);\n  const transform = useTransform(\n    progress,\n    [at, at + 0.06],\n    [\"translateY(6px)\", \"translateY(0px)\"],\n  );\n  return (\n    <motion.div style={{ opacity, transform }} className={className}>\n      {children}\n    </motion.div>\n  );\n}\n\nfunction DemoScene({\n  kind,\n  progress,\n}: DemoTabsScene & { kind: keyof typeof scripts }) {\n  const script = scripts[kind];\n  const Icon = script.icon;\n  return (\n    <>\n      <p className=\"sr-only\">\n        {script.title} {script.description} {script.lines.at(-1)}\n      </p>\n      <div\n        aria-hidden=\"true\"\n        className=\"grid @min-[40rem]/demo:grid-cols-[0.95fr_1.05fr]\"\n      >\n        <div className=\"flex min-h-64 flex-col gap-8 border-b p-6 @min-[40rem]/demo:min-h-[25rem] @min-[40rem]/demo:border-r @min-[40rem]/demo:border-b-0 @min-[40rem]/demo:p-8\">\n          <div className=\"flex items-center justify-between font-mono text-[10px] tracking-widest text-muted-foreground\">\n            <span>TERMINAL</span>\n            <span>~/project</span>\n          </div>\n          <div className=\"flex flex-col gap-5 font-mono text-xs leading-relaxed\">\n            <div className=\"flex gap-3\">\n              <span className=\"text-muted-foreground\">$</span>\n              <span>{script.command}</span>\n            </div>\n            <div className=\"flex flex-col gap-3\">\n              {script.lines.map((line, index) => (\n                <Beat\n                  key={line}\n                  progress={progress}\n                  at={0.1 + index * 0.18}\n                  className=\"flex items-center gap-3\"\n                >\n                  <span className=\"text-muted-foreground\">\n                    {index === 3 ? \"✓\" : \"›\"}\n                  </span>\n                  <span\n                    className={\n                      index === 3 ? \"text-foreground\" : \"text-muted-foreground\"\n                    }\n                  >\n                    {line}\n                  </span>\n                </Beat>\n              ))}\n            </div>\n          </div>\n          <div className=\"mt-auto pt-5 font-mono text-[10px] tracking-wide text-muted-foreground\">\n            ATLAS CLI <span className=\"ml-2 opacity-50\">v1.0.0</span>\n          </div>\n        </div>\n        <div className=\"relative flex min-h-[25rem] flex-col items-center justify-center gap-7 overflow-hidden bg-muted/15 px-6 py-10 @min-[40rem]/demo:px-10\">\n          <div className=\"flex w-full max-w-72 flex-col gap-3\">\n            <span className=\"font-mono text-[9px] tracking-[0.16em] text-muted-foreground\">\n              {script.eyebrow}\n            </span>\n            <h3 className=\"max-w-64 text-2xl leading-tight tracking-tight\">\n              {script.title}\n            </h3>\n            <p className=\"text-xs leading-relaxed text-muted-foreground\">\n              {script.description}\n            </p>\n          </div>\n          <Beat\n            progress={progress}\n            at={0.1}\n            className=\"w-full max-w-72 rounded-lg border bg-background shadow-sm\"\n          >\n            <div className=\"flex items-center gap-2 border-b px-4 py-3 text-xs\">\n              <Icon className=\"size-3.5 text-muted-foreground\" />\n              <span>\n                {kind === \"docs\"\n                  ? \"quickstart.ts\"\n                  : kind === \"check\"\n                    ? \"Project health\"\n                    : \"Production\"}\n              </span>\n            </div>\n            <div className=\"flex min-h-28 flex-col justify-center gap-3 p-4\">\n              {kind === \"docs\" ? (\n                <>\n                  <Beat\n                    progress={progress}\n                    at={0.28}\n                    className=\"font-mono text-[11px] text-muted-foreground\"\n                  >\n                    const client = atlas();\n                  </Beat>\n                  <Beat\n                    progress={progress}\n                    at={0.46}\n                    className=\"font-mono text-[11px]\"\n                  >\n                    await client.hello();\n                  </Beat>\n                  <Beat\n                    progress={progress}\n                    at={0.64}\n                    className=\"flex items-center gap-2 text-[11px] text-muted-foreground\"\n                  >\n                    <CheckIcon className=\"size-3\" /> 200 OK · Hello, world.\n                  </Beat>\n                </>\n              ) : kind === \"check\" ? (\n                [\"Type safety\", \"Dependencies\", \"Build integrity\"].map(\n                  (label, index) => (\n                    <Beat\n                      key={label}\n                      progress={progress}\n                      at={0.28 + index * 0.18}\n                      className=\"flex items-center justify-between text-xs\"\n                    >\n                      <span className=\"text-muted-foreground\">{label}</span>\n                      <CheckIcon className=\"size-3.5\" />\n                    </Beat>\n                  ),\n                )\n              ) : (\n                <>\n                  <Beat\n                    progress={progress}\n                    at={0.28}\n                    className=\"flex items-center justify-between text-xs\"\n                  >\n                    <span className=\"text-muted-foreground\">Build</span>\n                    <span>Complete</span>\n                  </Beat>\n                  <Beat\n                    progress={progress}\n                    at={0.46}\n                    className=\"flex items-center justify-between text-xs\"\n                  >\n                    <span className=\"text-muted-foreground\">Regions</span>\n                    <span>12 / 12</span>\n                  </Beat>\n                  <Beat\n                    progress={progress}\n                    at={0.64}\n                    className=\"flex items-center justify-between text-xs\"\n                  >\n                    <span>demo.atlas.dev</span>\n                    <ArrowUpRightIcon className=\"size-3.5\" />\n                  </Beat>\n                </>\n              )}\n            </div>\n          </Beat>\n        </div>\n      </div>\n    </>\n  );\n}\n\nconst items: readonly DemoTabsItem[] = [\n  {\n    value: \"docs\",\n    label: \"docs\",\n    description: \"Find your starting point\",\n    duration: 6500,\n    render: (scene) => <DemoScene {...scene} kind=\"docs\" />,\n  },\n  {\n    value: \"check\",\n    label: \"check\",\n    description: \"Ship with confidence\",\n    duration: 6000,\n    render: (scene) => <DemoScene {...scene} kind=\"check\" />,\n  },\n  {\n    value: \"deploy\",\n    label: \"deploy\",\n    description: \"Take it to production\",\n    duration: 6500,\n    render: (scene) => <DemoScene {...scene} kind=\"deploy\" />,\n  },\n];\n\nexport function DemoTabsExample() {\n  return <DemoTabs items={items} />;\n}\n",
      "type": "registry:block",
      "target": "@components/blocks/demo-tabs-example.tsx"
    }
  ],
  "meta": {
    "tags": [
      "tabs",
      "demo",
      "product",
      "timeline",
      "controlled"
    ],
    "effects": [
      "progress",
      "synchronized-playback",
      "reduced-motion"
    ]
  },
  "categories": [
    "marketing"
  ],
  "type": "registry:block"
}