{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabs-underline",
  "type": "registry:component",
  "title": "Tabs Underline",
  "description": "Tabs with a measured sliding underline, icons, counts and crossfading panels.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "app-ui",
    "tabs",
    "underline",
    "navigation",
    "panels"
  ],
  "docs": "https://hyperblur.dev/effects/tabs-underline",
  "files": [
    {
      "path": "registry/hyperblur/tabs-underline.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/tabs-underline.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TabsUnderlineTab {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n  count?: number | string;\n  content: React.ReactNode;\n}\n\nexport interface TabsUnderlineProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  tabs: TabsUnderlineTab[];\n  defaultValue?: string;\n  value?: string;\n  onChange?: (id: string) => void;\n  fitted?: boolean;\n  color?: string;\n}\n\nconst css = `\n.hb-tu {\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  --hb-tu-accent: #2f7bff;\n}\n.hb-tu-list {\n  position: relative;\n  display: flex;\n  align-items: stretch;\n  gap: 4px;\n  border-bottom: 1px solid #262626;\n}\n.hb-tu[data-fitted=\"true\"] .hb-tu-list { gap: 0; }\n.hb-tu-bar {\n  position: absolute;\n  bottom: -1px;\n  left: 0;\n  width: var(--hb-tu-w, 0px);\n  height: 2px;\n  border-radius: 2px 2px 0 0;\n  background: var(--hb-tu-accent);\n  opacity: 0;\n  pointer-events: none;\n  transform: translate3d(var(--hb-tu-x, 0px), 0, 0);\n  transition: transform .32s cubic-bezier(.2, .9, .2, 1), width .32s cubic-bezier(.2, .9, .2, 1), opacity .2s ease;\n}\n.hb-tu-bar[data-ready=\"true\"] { opacity: 1; }\n.hb-tu-tab {\n  display: inline-flex;\n  flex: none;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 10px 12px;\n  border: 0;\n  border-radius: 8px 8px 0 0;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 13px;\n  font-weight: 500;\n  line-height: 18px;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: color .15s ease, background-color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-tu[data-fitted=\"true\"] .hb-tu-tab { flex: 1; }\n.hb-tu-tab:hover { color: #ededed; }\n.hb-tu-tab[aria-selected=\"true\"] { color: #ededed; }\n.hb-tu-tab:focus-visible { outline: 2px solid var(--hb-tu-accent); outline-offset: -2px; }\n.hb-tu-icon { display: grid; flex: none; place-items: center; width: 16px; height: 16px; }\n.hb-tu-icon svg { width: 16px; height: 16px; }\n.hb-tu-count {\n  min-width: 18px;\n  padding: 0 6px;\n  border-radius: 999px;\n  background: #1f1f1f;\n  color: #8f8f8f;\n  font-size: 11px;\n  line-height: 18px;\n  text-align: center;\n  transition: background-color .15s ease, color .15s ease;\n}\n.hb-tu-tab[aria-selected=\"true\"] .hb-tu-count { background: #262626; color: #ededed; }\n.hb-tu-panel { padding-top: 14px; font-size: 13px; line-height: 1.55; animation: hb-tu-in .2s ease both; }\n.hb-tu-panel:focus-visible { outline: 2px solid var(--hb-tu-accent); outline-offset: 2px; border-radius: 6px; }\n@keyframes hb-tu-in {\n  from { opacity: 0; transform: translate3d(0, 4px, 0); }\n  to { opacity: 1; transform: translate3d(0, 0, 0); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-tu-bar { transition: opacity .01s linear; }\n  .hb-tu-tab, .hb-tu-count { transition: none; }\n  .hb-tu-panel { animation: none; }\n}\n`;\n\nexport function TabsUnderline({\n  tabs,\n  defaultValue,\n  value,\n  onChange,\n  fitted = false,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: TabsUnderlineProps) {\n  const uid = React.useId();\n  const listRef = React.useRef<HTMLDivElement>(null);\n  const barRef = React.useRef<HTMLSpanElement>(null);\n  const tabRefs = React.useRef<Map<string, HTMLButtonElement>>(new Map());\n  const placedRef = React.useRef(false);\n  const [inner, setInner] = React.useState(defaultValue ?? tabs[0]?.id ?? \"\");\n  const current = value ?? inner;\n  const currentRef = React.useRef(current);\n\n  const place = React.useCallback((instant: boolean) => {\n    const bar = barRef.current;\n    if (!bar) return;\n    const el = tabRefs.current.get(currentRef.current);\n    if (!el) {\n      bar.dataset.ready = \"false\";\n      return;\n    }\n    if (instant) bar.style.transition = \"none\";\n    bar.style.setProperty(\"--hb-tu-w\", `${el.offsetWidth}px`);\n    bar.style.setProperty(\"--hb-tu-x\", `${el.offsetLeft}px`);\n    bar.dataset.ready = \"true\";\n    if (instant) {\n      void bar.offsetWidth;\n      bar.style.transition = \"\";\n    }\n  }, []);\n\n  React.useEffect(() => {\n    currentRef.current = current;\n    place(!placedRef.current);\n    placedRef.current = true;\n  }, [current, tabs, fitted, place]);\n\n  React.useEffect(() => {\n    const list = listRef.current;\n    if (!list) return;\n    const update = () => place(true);\n    if (typeof ResizeObserver === \"undefined\") {\n      window.addEventListener(\"resize\", update);\n      return () => window.removeEventListener(\"resize\", update);\n    }\n    const ro = new ResizeObserver(update);\n    ro.observe(list);\n    return () => ro.disconnect();\n  }, [place]);\n\n  function select(id: string) {\n    if (value === undefined) setInner(id);\n    onChange?.(id);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented || tabs.length === 0) return;\n    const n = tabs.length;\n    const idx = Math.max(0, tabs.findIndex((t) => t.id === current));\n    let next = -1;\n    if (e.key === \"ArrowRight\") next = (idx + 1) % n;\n    else if (e.key === \"ArrowLeft\") next = (idx - 1 + n) % n;\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = n - 1;\n    if (next < 0) return;\n    e.preventDefault();\n    const id = tabs[next].id;\n    select(id);\n    tabRefs.current.get(id)?.focus();\n  }\n\n  const tabStop = tabs.some((t) => t.id === current) ? current : tabs[0]?.id;\n  const vars = { \"--hb-tu-accent\": color, ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-tu ${className}`} data-fitted={fitted} style={vars} {...rest}>\n      <style href=\"hb-tabs-underline\" precedence=\"default\">{css}</style>\n      <div\n        ref={listRef}\n        className=\"hb-tu-list\"\n        role=\"tablist\"\n        aria-orientation=\"horizontal\"\n        onKeyDown={handleKeyDown}\n      >\n        <span ref={barRef} className=\"hb-tu-bar\" aria-hidden=\"true\" />\n        {tabs.map((tab) => (\n          <button\n            key={tab.id}\n            ref={(el) => {\n              if (el) tabRefs.current.set(tab.id, el);\n              else tabRefs.current.delete(tab.id);\n            }}\n            id={`${uid}-tab-${tab.id}`}\n            type=\"button\"\n            role=\"tab\"\n            className=\"hb-tu-tab\"\n            aria-selected={tab.id === current}\n            aria-controls={`${uid}-panel-${tab.id}`}\n            tabIndex={tab.id === tabStop ? 0 : -1}\n            onClick={() => select(tab.id)}\n          >\n            {tab.icon ? (\n              <span className=\"hb-tu-icon\" aria-hidden=\"true\">\n                {tab.icon}\n              </span>\n            ) : null}\n            <span>{tab.label}</span>\n            {tab.count !== undefined ? <span className=\"hb-tu-count\">{tab.count}</span> : null}\n          </button>\n        ))}\n      </div>\n      {tabs.map((tab) => (\n        <div\n          key={tab.id}\n          id={`${uid}-panel-${tab.id}`}\n          role=\"tabpanel\"\n          className=\"hb-tu-panel\"\n          aria-labelledby={`${uid}-tab-${tab.id}`}\n          tabIndex={0}\n          hidden={tab.id !== current}\n        >\n          {tab.content}\n        </div>\n      ))}\n    </div>\n  );\n}\n"
    }
  ]
}