{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabs",
  "type": "registry:ui",
  "title": "Tabs",
  "description": "Tabs with keyboard arrows, Home and End, built on Radix Tabs.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/tabs.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/tabs.tsx",
      "content": "import { createContext, useContext, useId, useState, type ButtonHTMLAttributes, type HTMLAttributes, type KeyboardEvent, type ReactNode } from 'react';\nimport { cn } from '../lib/utils';\n\n// Own implementation (not Radix): Radix Tabs writes inline style attributes into server-rendered HTML, which a strict CSP blocks.\n// Same API and behaviour: roving tabindex, arrow keys / Home / End move and activate, panels labelled by their tab.\n\ninterface Ctx { value: string; setValue: (v: string) => void; base: string; variant: TabsVariant }\n/** pill: a segmented control on a tinted track. underline: tabs on one hairline, the active one underlined in ink (a page's sections). */\nexport type TabsVariant = 'pill' | 'underline';\nconst TabsCtx = createContext<Ctx | null>(null);\nconst useTabs = () => {\n  const c = useContext(TabsCtx);\n  if (!c) throw new Error('Tabs parts must be inside <Tabs>');\n  return c;\n};\nconst slug = (v: string) => v.replace(/[^a-zA-Z0-9_-]/g, '_');\n\nexport function Tabs({ defaultValue, value, onValueChange, variant = 'pill', className, children, ...rest }: Omit<HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'onChange'> & {\n  defaultValue?: string; value?: string; onValueChange?: (v: string) => void; variant?: TabsVariant;\n}) {\n  const [inner, setInner] = useState(defaultValue ?? '');\n  const base = useId();\n  const current = value ?? inner;\n  const setValue = (v: string) => {\n    if (v === current) return;\n    if (value === undefined) setInner(v);\n    onValueChange?.(v);\n  };\n  return (\n    <TabsCtx.Provider value={{ value: current, setValue, base, variant }}>\n      <div className={className} {...rest}>{children}</div>\n    </TabsCtx.Provider>\n  );\n}\n\nexport function TabsList({ children, className, label, end, ...rest }: HTMLAttributes<HTMLDivElement> & { label?: string; /** Underline only: an action at the right end of the line (a button, a menu). Not a tab. */ end?: ReactNode }) {\n  const { variant } = useTabs();\n  const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {\n    const tabs = Array.from(e.currentTarget.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]:not(:disabled)'));\n    const at = tabs.indexOf(document.activeElement as HTMLButtonElement);\n    if (at < 0) return;\n    const to = { ArrowRight: (at + 1) % tabs.length, ArrowLeft: (at - 1 + tabs.length) % tabs.length, Home: 0, End: tabs.length - 1 }[e.key];\n    if (to === undefined) return;\n    e.preventDefault();\n    tabs[to]!.focus();\n    tabs[to]!.click();\n  };\n  return (\n    variant === 'underline' ? (\n      <div className={cn('flex min-w-0 items-end gap-3 border-b border-kh-line', className)}>\n        <div role=\"tablist\" aria-label={label} aria-orientation=\"horizontal\" onKeyDown={onKeyDown} className=\"-mb-px flex min-w-0 items-end gap-5 overflow-x-auto\" {...rest}>{children}</div>\n        {end && <div className=\"ml-auto flex shrink-0 items-center gap-2 pb-1.5\">{end}</div>}\n      </div>\n    ) : (\n      <div role=\"tablist\" aria-label={label} aria-orientation=\"horizontal\" onKeyDown={onKeyDown} className={cn('inline-flex items-center gap-1 rounded-kh-lg bg-kh-surface-2 p-1', className)} {...rest}>\n        {children}\n      </div>\n    )\n  );\n}\n\nexport function TabsTrigger({ value, children, className, onClick, ...rest }: Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'value'> & { value: string }) {\n  const { value: current, setValue, base, variant } = useTabs();\n  const active = current === value;\n  return (\n    <button\n      type=\"button\"\n      role=\"tab\"\n      id={`${base}-tab-${slug(value)}`}\n      aria-selected={active}\n      aria-controls={`${base}-panel-${slug(value)}`}\n      tabIndex={active ? 0 : -1}\n      data-state={active ? 'active' : 'inactive'}\n      onClick={(e) => {\n        onClick?.(e);\n        if (!e.defaultPrevented) setValue(value);\n      }}\n      className={cn(\n        'inline-flex items-center justify-center text-kh-small font-medium text-kh-muted transition-colors duration-(--kh-dur) hover:text-kh-ink focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-(--kh-focus)',\n        variant === 'underline'\n          ? 'min-h-11 shrink-0 whitespace-nowrap border-b-2 border-transparent px-0.5 data-[state=active]:border-kh-ink data-[state=active]:text-kh-ink'\n          : 'min-h-9 rounded-kh px-3 data-[state=active]:bg-kh-surface data-[state=active]:text-kh-ink data-[state=active]:shadow-kh-1',\n        className,\n      )}\n      {...rest}\n    >\n      {children}\n    </button>\n  );\n}\n\nexport function TabsContent({ value, children, className, forceMount, ...rest }: Omit<HTMLAttributes<HTMLDivElement>, 'children'> & { value: string; children: ReactNode; forceMount?: true }) {\n  const { value: current, base } = useTabs();\n  const active = current === value;\n  if (!active && !forceMount) return null;\n  return (\n    <div\n      role=\"tabpanel\"\n      id={`${base}-panel-${slug(value)}`}\n      aria-labelledby={`${base}-tab-${slug(value)}`}\n      tabIndex={0}\n      hidden={!active}\n      data-state={active ? 'active' : 'inactive'}\n      className={cn(forceMount && 'data-[state=inactive]:hidden', 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus)', className)}\n      {...rest}\n    >\n      {children}\n    </div>\n  );\n}\n"
    }
  ]
}
