{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"continuity-tabs","type":"registry:component","title":"Continuity Tabs","description":"One selection surface, moving with the content it reveals.","dependencies":[],"categories":["navigation","tabs","spring","measurement","settings"],"files":[{"path":"components/lab/continuity-tabs/continuity-tabs.tsx","target":"components/lab/continuity-tabs/continuity-tabs.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useCallback,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n  type KeyboardEvent,\n  type ReactNode,\n} from \"react\";\nimport \"./continuity-tabs.css\";\n\nexport type ContinuityTab = {\n  id: string;\n  label: string;\n  content: ReactNode;\n  disabled?: boolean;\n};\n\nexport type ContinuityTabsProps = {\n  tabs: ContinuityTab[];\n  /** Controlled active tab id. */\n  value?: string;\n  /** Initial tab id in uncontrolled use. */\n  defaultValue?: string;\n  onValueChange?: (id: string) => void;\n  /** Accessible name for the tab list. */\n  label?: string;\n  /**\n   * spring — a short, damped glide; fade — a calm crossfade;\n   * none — instant, for low-power surfaces.\n   */\n  motion?: \"spring\" | \"fade\" | \"none\";\n  className?: string;\n};\n\nfunction reducedMotion() {\n  return (\n    typeof window !== \"undefined\" &&\n    window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches\n  );\n}\n\n/**\n * CONTINUITY TABS\n *\n * The selection surface is one object: it is measured from the live tab\n * and moves with a damped spring. Content panels stay mounted, so their\n * internal state survives tab changes; only the active and outgoing\n * panels are painted. The viewport height follows the measured active\n * panel, which means a shorter panel does not yank the page upward.\n */\nexport function ContinuityTabs({\n  tabs,\n  value,\n  defaultValue,\n  onValueChange,\n  label = \"Tabs\",\n  motion = \"spring\",\n  className,\n}: ContinuityTabsProps) {\n  const uid = useId();\n  const enabled = tabs.filter((tab) => !tab.disabled);\n  const firstId = enabled[0]?.id ?? tabs[0]?.id ?? \"\";\n  const controlled = value !== undefined;\n  const [internal, setInternal] = useState(defaultValue ?? firstId);\n  const requested = controlled ? value : internal;\n  const activeIndex = Math.max(\n    0,\n    tabs.findIndex((tab) => tab.id === requested && !tab.disabled),\n  );\n  const active = tabs[activeIndex];\n\n  const listRef = useRef<HTMLDivElement>(null);\n  const tabRefs = useRef(new Map<string, HTMLButtonElement>());\n  const panelRefs = useRef(new Map<string, HTMLDivElement>());\n  const [indicator, setIndicator] = useState({ x: 0, width: 0, ready: false });\n  const [overflow, setOverflow] = useState({ left: false, right: false });\n  const [height, setHeight] = useState<number | null>(null);\n  const [outgoing, setOutgoing] = useState<string | null>(null);\n  const [direction, setDirection] = useState(1);\n  const outgoingTimer = useRef<number | null>(null);\n  const panelAnimation = useRef<Animation | null>(null);\n\n  const measureOverflow = useCallback(() => {\n    const list = listRef.current;\n    if (!list) return;\n    const next = {\n      left: list.scrollLeft > 2,\n      right: list.scrollLeft + list.clientWidth < list.scrollWidth - 2,\n    };\n    setOverflow((current) =>\n      current.left === next.left && current.right === next.right\n        ? current\n        : next,\n    );\n  }, []);\n\n  const measure = useCallback(() => {\n    const list = listRef.current;\n    if (!list) return;\n    const button = tabRefs.current.get(active?.id ?? \"\");\n    if (!button) return;\n    setIndicator({\n      x: button.offsetLeft,\n      width: button.offsetWidth,\n      ready: true,\n    });\n    measureOverflow();\n  }, [active?.id, measureOverflow]);\n\n  useLayoutEffect(() => {\n    measure();\n    const list = listRef.current;\n    if (!list || typeof ResizeObserver !== \"function\") return;\n    const observer = new ResizeObserver(measure);\n    observer.observe(list);\n    for (const button of tabRefs.current.values()) observer.observe(button);\n    return () => observer.disconnect();\n  }, [measure]);\n\n  useEffect(() => {\n    const onResize = () => measure();\n    window.addEventListener(\"resize\", onResize);\n    return () => window.removeEventListener(\"resize\", onResize);\n  }, [measure]);\n\n  /* Keep the active tab visible when the list overflows. */\n  useEffect(() => {\n    const button = tabRefs.current.get(active?.id ?? \"\");\n    button?.scrollIntoView({ block: \"nearest\", inline: \"nearest\" });\n  }, [active?.id]);\n\n  /* The viewport height is the measured height of the active panel. */\n  const measurePanel = useCallback(() => {\n    const panel = panelRefs.current.get(active?.id ?? \"\");\n    if (!panel) return;\n    const next = panel.scrollHeight;\n    setHeight((current) => (current === next ? current : next));\n  }, [active?.id]);\n\n  useLayoutEffect(() => {\n    measurePanel();\n    const panel = panelRefs.current.get(active?.id ?? \"\");\n    if (!panel || typeof ResizeObserver !== \"function\") return;\n    const observer = new ResizeObserver(measurePanel);\n    observer.observe(panel);\n    return () => observer.disconnect();\n  }, [measurePanel, active?.id]);\n\n  /* Animate the entering panel and retire the outgoing one. */\n  const previousId = useRef(active?.id);\n  useLayoutEffect(() => {\n    if (!active) return;\n    const previous = previousId.current;\n    previousId.current = active.id;\n    if (!previous || previous === active.id) return;\n\n    const panel = panelRefs.current.get(active.id);\n    const prevPanel = panelRefs.current.get(previous);\n    const dir =\n      tabs.findIndex((tab) => tab.id === active.id) >\n      tabs.findIndex((tab) => tab.id === previous)\n        ? 1\n        : -1;\n    setDirection(dir);\n    setOutgoing(previous);\n\n    panelAnimation.current?.cancel();\n    if (panel && motion !== \"none\") {\n      if (reducedMotion()) {\n        panel.style.opacity = \"1\";\n        panel.style.transform = \"none\";\n      } else {\n        panelAnimation.current = panel.animate(\n          [\n            {\n              opacity: 0,\n              transform: `translate3d(${dir * 18}px, 0, 0)`,\n            },\n            { opacity: 1, transform: \"translate3d(0, 0, 0)\" },\n          ],\n          {\n            duration: motion === \"spring\" ? 300 : 220,\n            easing:\n              motion === \"spring\"\n                ? \"cubic-bezier(0.16, 1, 0.3, 1)\"\n                : \"cubic-bezier(0.4, 0, 0.2, 1)\",\n          },\n        );\n      }\n    }\n    if (prevPanel && motion !== \"none\" && !reducedMotion()) {\n      prevPanel.animate(\n        [\n          { opacity: 1, transform: \"translate3d(0, 0, 0)\" },\n          {\n            opacity: 0,\n            transform: `translate3d(${dir * -14}px, 0, 0)`,\n          },\n        ],\n        {\n          duration: motion === \"spring\" ? 230 : 180,\n          easing: \"cubic-bezier(0.4, 0, 1, 1)\",\n        },\n      );\n    }\n\n    if (outgoingTimer.current !== null) window.clearTimeout(outgoingTimer.current);\n    outgoingTimer.current = window.setTimeout(\n      () => {\n        setOutgoing(null);\n        outgoingTimer.current = null;\n      },\n      motion === \"none\" ? 0 : 320,\n    );\n  }, [active, motion, tabs]);\n\n  useEffect(\n    () => () => {\n      if (outgoingTimer.current !== null)\n        window.clearTimeout(outgoingTimer.current);\n      panelAnimation.current?.cancel();\n    },\n    [],\n  );\n\n  const select = (id: string, focus = false) => {\n    if (controlled) onValueChange?.(id);\n    else setInternal(id);\n    if (focus) tabRefs.current.get(id)?.focus();\n  };\n\n  const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>, index: number) => {\n    const selectable = tabs\n      .map((tab, position) => ({ tab, position }))\n      .filter(({ tab }) => !tab.disabled);\n    if (selectable.length === 0) return;\n    const current = selectable.findIndex(({ position }) => position === index);\n    let next: number | null = null;\n    if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\")\n      next = (current + 1) % selectable.length;\n    else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\")\n      next = (current - 1 + selectable.length) % selectable.length;\n    else if (event.key === \"Home\") next = 0;\n    else if (event.key === \"End\") next = selectable.length - 1;\n    if (next === null) return;\n    event.preventDefault();\n    const target = selectable[next];\n    select(target.tab.id, true);\n  };\n\n  if (!active) return null;\n\n  return (\n    <div\n      className={`ct-root${className ? ` ${className}` : \"\"}`}\n      data-motion={motion}\n    >\n      <div className=\"ct-tablist-wrap\" data-fade-left={overflow.left ? \"true\" : \"false\"} data-fade-right={overflow.right ? \"true\" : \"false\"}>\n        <div\n          ref={listRef}\n          className=\"ct-tablist\"\n          role=\"tablist\"\n          aria-label={label}\n          onScroll={measureOverflow}\n        >\n          {tabs.map((tab, index) => {\n            const selected = tab.id === active.id;\n            return (\n              <button\n                key={tab.id}\n                ref={(node) => {\n                  if (node) tabRefs.current.set(tab.id, node);\n                  else tabRefs.current.delete(tab.id);\n                }}\n                type=\"button\"\n                role=\"tab\"\n                id={`${uid}-tab-${tab.id}`}\n                aria-selected={selected}\n                aria-controls={`${uid}-panel-${tab.id}`}\n                aria-disabled={tab.disabled || undefined}\n                disabled={tab.disabled}\n                tabIndex={selected ? 0 : -1}\n                className=\"ct-tab\"\n                onClick={() => select(tab.id)}\n                onKeyDown={(event) => onKeyDown(event, index)}\n              >\n                {tab.label}\n              </button>\n            );\n          })}\n          <span\n            className=\"ct-indicator\"\n            aria-hidden=\"true\"\n            data-ready={indicator.ready ? \"true\" : \"false\"}\n            style={{\n              width: indicator.width,\n              transform: `translate3d(${indicator.x}px, 0, 0)`,\n            }}\n          />\n        </div>\n      </div>\n      <div\n        className=\"ct-viewport\"\n        data-ready={height !== null ? \"true\" : \"false\"}\n        style={height !== null ? { height } : undefined}\n      >\n        {tabs.map((tab) => {\n          const selected = tab.id === active.id;\n          const leaving = tab.id === outgoing;\n          return (\n            <div\n              key={tab.id}\n              ref={(node) => {\n                if (node) panelRefs.current.set(tab.id, node);\n                else panelRefs.current.delete(tab.id);\n              }}\n              className={`ct-panel${leaving ? \" ct-panel--leaving\" : \"\"}`}\n              id={`${uid}-panel-${tab.id}`}\n              role=\"tabpanel\"\n              aria-labelledby={`${uid}-tab-${tab.id}`}\n              aria-hidden={!selected}\n              inert={!selected}\n              hidden={!selected && !leaving}\n              data-direction={direction}\n            >\n              {tab.content}\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"},{"path":"components/lab/continuity-tabs/continuity-tabs.css","target":"components/lab/continuity-tabs/continuity-tabs.css","type":"registry:file","content":".ct-root {\n  --ct-ink: #1d2026;\n  --ct-muted: #6b6f78;\n  --ct-line: rgba(29, 32, 38, 0.12);\n  --ct-surface: #ffffff;\n  --ct-soft: #f4f4f1;\n  --ct-accent: #3c36c9;\n  --ct-accent-soft: rgba(60, 54, 201, 0.09);\n  --ct-focus: #3c36c9;\n  --ct-ease: cubic-bezier(0.16, 1, 0.3, 1);\n  width: 100%;\n  min-width: 0;\n  color: var(--ct-ink);\n  font: inherit;\n}\n\n.ct-tablist-wrap {\n  position: relative;\n  min-width: 0;\n}\n\n.ct-tablist-wrap::before,\n.ct-tablist-wrap::after {\n  content: \"\";\n  position: absolute;\n  top: 0;\n  bottom: 0;\n  width: 22px;\n  z-index: 2;\n  pointer-events: none;\n  opacity: 0;\n  transition: opacity 180ms linear;\n}\n\n.ct-tablist-wrap::before {\n  left: 0;\n  background: linear-gradient(90deg, var(--ct-soft), transparent);\n}\n\n.ct-tablist-wrap::after {\n  right: 0;\n  background: linear-gradient(270deg, var(--ct-soft), transparent);\n}\n\n.ct-tablist-wrap[data-fade-left=\"true\"]::before,\n.ct-tablist-wrap[data-fade-right=\"true\"]::after {\n  opacity: 1;\n}\n\n.ct-tablist {\n  position: relative;\n  display: flex;\n  align-items: stretch;\n  gap: 2px;\n  padding: 3px;\n  border: 1px solid var(--ct-line);\n  border-radius: 11px;\n  background: var(--ct-soft);\n  overflow-x: auto;\n  overscroll-behavior-x: contain;\n  scrollbar-width: none;\n  -ms-overflow-style: none;\n}\n\n.ct-tablist::-webkit-scrollbar {\n  display: none;\n}\n\n.ct-tab {\n  position: relative;\n  z-index: 1;\n  flex: 0 0 auto;\n  min-height: 38px;\n  padding: 8px 15px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: var(--ct-muted);\n  font: inherit;\n  font-size: 0.875rem;\n  font-weight: 500;\n  letter-spacing: -0.006em;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: color 180ms var(--ct-ease);\n}\n\n.ct-tab:hover {\n  color: var(--ct-ink);\n}\n\n.ct-tab[aria-selected=\"true\"] {\n  color: var(--ct-ink);\n}\n\n.ct-tab:disabled {\n  color: var(--ct-muted);\n  opacity: 0.42;\n  cursor: not-allowed;\n}\n\n.ct-tab:focus-visible {\n  outline: 2px solid var(--ct-focus);\n  outline-offset: 1px;\n}\n\n.ct-indicator {\n  position: absolute;\n  top: 3px;\n  left: 0;\n  bottom: 3px;\n  z-index: 0;\n  border: 1px solid rgba(29, 32, 38, 0.08);\n  border-radius: 8px;\n  background: var(--ct-surface);\n  box-shadow:\n    0 1px 2px rgba(29, 32, 38, 0.07),\n    0 6px 18px -12px rgba(29, 32, 38, 0.3);\n  opacity: 0;\n  pointer-events: none;\n  transition:\n    transform 360ms var(--ct-ease),\n    width 360ms var(--ct-ease),\n    opacity 140ms linear;\n  will-change: transform, width;\n}\n\n.ct-indicator[data-ready=\"true\"] {\n  opacity: 1;\n}\n\n.ct-root[data-motion=\"fade\"] .ct-indicator {\n  transition:\n    transform 260ms ease-out,\n    width 260ms ease-out,\n    opacity 140ms linear;\n}\n\n.ct-root[data-motion=\"none\"] .ct-indicator {\n  transition: opacity 100ms linear;\n}\n\n.ct-viewport {\n  position: relative;\n  min-width: 0;\n  margin-top: 18px;\n  overflow: hidden;\n  transition: height 300ms var(--ct-ease);\n}\n\n.ct-viewport:not([data-ready=\"true\"]) .ct-panel {\n  position: static;\n}\n\n.ct-panel {\n  position: absolute;\n  inset: 0 0 auto;\n  min-width: 0;\n  opacity: 1;\n}\n\n.ct-panel[hidden] {\n  display: none;\n}\n\n.ct-panel--leaving {\n  pointer-events: none;\n  user-select: none;\n}\n\n.ct-root[data-motion=\"none\"] .ct-viewport {\n  transition: none;\n}\n\n@media (max-width: 520px) {\n  .ct-tab {\n    min-height: 36px;\n    padding-inline: 12px;\n    font-size: 0.8125rem;\n  }\n\n  .ct-viewport {\n    margin-top: 14px;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .ct-indicator,\n  .ct-viewport,\n  .ct-tab {\n    transition-duration: 0.01ms;\n  }\n}\n"}]}