{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "morph-tabs",
  "type": "registry:component",
  "title": "Morph Tabs",
  "description": "Tabs where the container smoothly resizes to each panel, panels crossfade with a slight scale, and a pill glides between triggers.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "tabs",
    "morph",
    "height",
    "crossfade",
    "pill"
  ],
  "docs": "https://hyperblur.dev/effects/morph-tabs",
  "files": [
    {
      "path": "registry/hyperblur/morph-tabs.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/morph-tabs.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MorphTab {\n  id: string;\n  label: string;\n  content: React.ReactNode;\n}\n\nexport interface MorphTabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  tabs: MorphTab[];\n  defaultValue?: string;\n  value?: string;\n  onChange?: (value: string) => void;\n  color?: string;\n}\n\nconst css = `\n.hb-mt { width: 100%; color: #ededed; }\n.hb-mt:not([data-ready]) .hb-mt-tab[aria-selected=\"true\"] {\n  background: color-mix(in srgb, var(--hb-mt-c) 24%, transparent);\n}\n.hb-mt-list {\n  position: relative;\n  display: flex;\n  gap: 2px;\n  width: max-content;\n  max-width: 100%;\n  padding: 4px;\n  overflow-x: auto;\n  scrollbar-width: none;\n  border-radius: 999px;\n  background: rgba(255, 255, 255, 0.04);\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);\n}\n.hb-mt-list::-webkit-scrollbar { display: none; }\n.hb-mt-pill {\n  position: absolute;\n  top: 4px;\n  bottom: 4px;\n  left: 0;\n  width: 0;\n  border-radius: 999px;\n  background: color-mix(in srgb, var(--hb-mt-c) 24%, transparent);\n  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-mt-c) 60%, transparent), 0 0 18px color-mix(in srgb, var(--hb-mt-c) 28%, transparent);\n  opacity: 0;\n  pointer-events: none;\n}\n.hb-mt[data-ready] .hb-mt-pill {\n  opacity: 1;\n  transition: transform 0.4s cubic-bezier(.34, 1.3, .64, 1), width 0.4s cubic-bezier(.34, 1.3, .64, 1);\n}\n.hb-mt-tab {\n  position: relative;\n  z-index: 1;\n  flex: 0 0 auto;\n  padding: 7px 14px;\n  border: 0;\n  border-radius: 999px;\n  background: transparent;\n  color: rgba(255, 255, 255, 0.58);\n  font: inherit;\n  font-size: 13px;\n  font-weight: 500;\n  line-height: 1.2;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: color 0.25s ease;\n}\n.hb-mt-tab:hover { color: rgba(255, 255, 255, 0.9); }\n.hb-mt-tab[aria-selected=\"true\"] { color: #fff; }\n.hb-mt-tab:focus-visible { outline: 2px solid var(--hb-mt-c); outline-offset: 1px; }\n.hb-mt-body {\n  position: relative;\n  margin-top: 10px;\n  overflow: hidden;\n  border-radius: 14px;\n  background: rgba(255, 255, 255, 0.03);\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);\n}\n.hb-mt[data-ready] .hb-mt-body { transition: height 0.4s cubic-bezier(.22, 1, .36, 1); }\n.hb-mt-panel {\n  position: absolute;\n  top: 0;\n  left: 0;\n  right: 0;\n  padding: 14px 16px;\n  font-size: 14px;\n  line-height: 1.55;\n  color: rgba(255, 255, 255, 0.75);\n  opacity: 0;\n  visibility: hidden;\n  pointer-events: none;\n  transform: scale(0.97);\n  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;\n}\n.hb-mt-panel[data-active] {\n  position: relative;\n  opacity: 1;\n  visibility: visible;\n  pointer-events: auto;\n  transform: none;\n  transition: opacity 0.35s ease 0.1s, transform 0.4s cubic-bezier(.22, 1, .36, 1) 0.1s, visibility 0s;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-mt[data-ready] .hb-mt-pill { transition: none; }\n  .hb-mt[data-ready] .hb-mt-body { transition: none; }\n  .hb-mt-panel, .hb-mt-panel[data-active] { transform: none; transition: opacity 0.15s ease, visibility 0s linear 0.15s; }\n  .hb-mt-panel[data-active] { transition: opacity 0.2s ease; }\n  .hb-mt-tab { transition: none; }\n}\n`;\n\nexport function MorphTabs({\n  tabs,\n  defaultValue,\n  value,\n  onChange,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: MorphTabsProps) {\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const listRef = React.useRef<HTMLDivElement>(null);\n  const pillRef = React.useRef<HTMLSpanElement>(null);\n  const activePanel = React.useRef<HTMLDivElement>(null);\n  const [inner, setInner] = React.useState(defaultValue ?? tabs[0]?.id ?? \"\");\n  const [height, setHeight] = React.useState<number | null>(null);\n\n  const requested = value ?? inner;\n  const current = tabs.some((t) => t.id === requested) ? requested : (tabs[0]?.id ?? \"\");\n  const currentIndex = tabs.findIndex((t) => t.id === current);\n\n  function select(id: string) {\n    if (value === undefined) setInner(id);\n    if (id !== current) onChange?.(id);\n  }\n\n  React.useLayoutEffect(() => {\n    const list = listRef.current;\n    const pill = pillRef.current;\n    const root = rootRef.current;\n    if (!list || !pill || !root) return;\n    const place = () => {\n      const tab = list.querySelector<HTMLElement>('[role=\"tab\"][aria-selected=\"true\"]');\n      if (!tab) return;\n      pill.style.width = `${tab.offsetWidth}px`;\n      pill.style.transform = `translateX(${tab.offsetLeft}px)`;\n    };\n    place();\n    const frame = requestAnimationFrame(() => root.setAttribute(\"data-ready\", \"\"));\n    const ro = new ResizeObserver(place);\n    ro.observe(list);\n    list.querySelectorAll(\"[role=tab]\").forEach((el) => ro.observe(el));\n    return () => {\n      cancelAnimationFrame(frame);\n      ro.disconnect();\n    };\n  }, [current, tabs]);\n\n  React.useEffect(() => {\n    const el = activePanel.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setHeight(el.offsetHeight));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [current]);\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    const n = tabs.length;\n    if (n === 0) return;\n    let to = -1;\n    if (e.key === \"ArrowRight\") to = (currentIndex + 1) % n;\n    else if (e.key === \"ArrowLeft\") to = (currentIndex - 1 + n) % n;\n    else if (e.key === \"Home\") to = 0;\n    else if (e.key === \"End\") to = n - 1;\n    if (to < 0) return;\n    e.preventDefault();\n    select(tabs[to].id);\n    listRef.current?.querySelectorAll<HTMLElement>(\"[role=tab]\")[to]?.focus();\n  }\n\n  const vars = { \"--hb-mt-c\": color, ...style } as React.CSSProperties;\n\n  return (\n    <div ref={rootRef} className={`hb-mt ${className}`} style={vars} {...rest}>\n      <style href=\"hb-morph-tabs\" precedence=\"default\">{css}</style>\n      <div className=\"hb-mt-list\" role=\"tablist\" ref={listRef} onKeyDown={handleKeyDown}>\n        <span className=\"hb-mt-pill\" ref={pillRef} aria-hidden=\"true\" />\n        {tabs.map((tab) => (\n          <button\n            type=\"button\"\n            key={tab.id}\n            role=\"tab\"\n            id={`${uid}-t-${tab.id}`}\n            aria-selected={tab.id === current}\n            aria-controls={`${uid}-p-${tab.id}`}\n            tabIndex={tab.id === current ? 0 : -1}\n            className=\"hb-mt-tab\"\n            onClick={() => select(tab.id)}\n          >\n            {tab.label}\n          </button>\n        ))}\n      </div>\n      <div className=\"hb-mt-body\" style={height === null ? undefined : { height }}>\n        {tabs.map((tab) => {\n          const active = tab.id === current;\n          return (\n            <div\n              key={tab.id}\n              ref={active ? activePanel : undefined}\n              role=\"tabpanel\"\n              id={`${uid}-p-${tab.id}`}\n              aria-labelledby={`${uid}-t-${tab.id}`}\n              className=\"hb-mt-panel\"\n              data-active={active ? \"\" : undefined}\n              aria-hidden={active ? undefined : true}\n            >\n              {tab.content}\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}