{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-tabs",
  "type": "registry:ui",
  "title": "react-tw/tabs.tsx",
  "description": "Carbon `Tabs` as React + Tailwind components, the look and keyboard of `<ui-tabs>`: `line` (default) Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-layer",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-tooltip",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/tabs.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/tabs.tsx",
      "content": "import { Children, createContext, Fragment, isValidElement, useContext, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type ReactNode, type ComponentProps } from 'react';\nimport { Tabs as TabsPrimitive } from '@purpurabog/ui/headless';\nimport { cn } from './lib/utils.ts';\nimport { useTranslation } from './lib/i18n.ts';\nimport { useLayerLevel } from './layer.tsx';\nimport { Tooltip } from './tooltip.tsx';\n\n/** Carbon VERTICAL_TABS_BREAKPOINT: vertical tabs from just above md (42rem); below, contained tabs in a row. */\nconst VERTICAL_TABS_QUERY = '(min-width: 42.01rem)';\n\nfunction useWide() {\n    return useSyncExternalStore(\n        (onChange) => {\n            const query = matchMedia(VERTICAL_TABS_QUERY);\n            query.addEventListener('change', onChange);\n            return () => query.removeEventListener('change', onChange);\n        },\n        () => matchMedia(VERTICAL_TABS_QUERY).matches,\n        () => false,\n    );\n}\n\n/** Literal class names (Tailwind): a panel of vertical tabs one layer up for its fields (its colour is the tabs' own layer, `--_panel-bg`). */\nconst PANEL_LAYER = ['', 'layer-1', 'layer-2'] as const;\n\n/**\n * Carbon `Tabs` as React + Tailwind components, the look and keyboard of `<ui-tabs>`: `line` (default)\n * or `contained` (48px on layer-accent, dividers, the selected tab on the layer with a blue top edge,\n * panels on the layer), sizes, `fullWidth` (contained: equal columns, ellipsis). ← / → move with wrap\n * (mirrored right-to-left), Home / End jump; `activation=\"automatic\"` selects as focus moves, `manual`\n * selects on Enter / Space. When the tabs overflow, scroll buttons appear for the mouse (no Tab stops).\n * A `Tab` takes an `icon`, a `secondaryLabel` (contained) or `iconOnly` + `label`; `dismissable` tabs\n * have a close button and close on Delete (`onTabCloseRequest`).\n */\nexport type TabsType = 'line' | 'contained';\nexport type TabsSize = 'sm' | 'md' | 'lg' | 'xl';\nexport type TabsActivation = 'automatic' | 'manual';\n\n/** What the styled parts need to look right; the state (selection, Tab stop, closing) is the primitive's. */\ninterface TabsLookValue {\n    type: TabsType;\n    fullWidth: boolean;\n    /** Vertical tabs at least md wide: a column beside the panels. */\n    column: boolean;\n    /** The layer the panels of vertical tabs shift their fields to (1 or 2). */\n    panelLayer: 1 | 2;\n    /** A secondary label on a contained tab: every tab 64px (Carbon tabs--tall). */\n    tall: boolean;\n    /** Close buttons, Delete closes (never in vertical tabs). */\n    dismissable: boolean;\n    lang?: string;\n}\n\nconst TabsContext = createContext<TabsLookValue | null>(null);\n\nfunction useTabs(component: string) {\n    const ctx = useContext(TabsContext);\n    if (!ctx) throw new Error(`<${component}> goes inside <Tabs>`);\n    return ctx;\n}\n\n/** The props of the `<Tab>`s among the children (through fragments and the tab list): the default value, the tall strip. */\nfunction tabProps(children: ReactNode) {\n    const found: Partial<TabProps>[] = [];\n    const visit = (nodes: ReactNode) => {\n        Children.forEach(nodes, (child) => {\n            if (!isValidElement(child)) return;\n            const props = child.props as Partial<TabProps>;\n            if (child.type === Tab) found.push(props);\n            else if (child.type === TabList || child.type === Fragment) visit(props.children);\n        });\n    };\n    visit(children);\n    return found;\n}\n\n/** The tabs of a tab list, in order. */\nconst tabsIn = (list: Element) => [...list.querySelectorAll<HTMLElement>('[role=\"tab\"]')];\n\n/** Tab height: line sm 32 / md 40 / lg 48 (xl too: line tabs stop at lg); contained defaults to lg, xl 64. */\nfunction tabHeight(type: TabsType, size: TabsSize | undefined) {\n    if (size === 'sm') return '32px';\n    if (size === 'md') return '40px';\n    if (size === 'xl' && type === 'contained') return '64px';\n    if (size === 'lg' || size === 'xl') return '48px';\n    // --ui-tabs-contained-height: Carbon's 48px contained tabs; a design can make the segmented control smaller\n    return type === 'contained' ? 'var(--ui-tabs-contained-height, 48px)' : '40px';\n}\n\nexport interface TabsProps extends Omit<ComponentProps<'div'>, 'value' | 'defaultValue' | 'onValueChange' | 'type' | 'size' | 'activation' | 'fullWidth' | 'children' | 'className'> {\n    /** The selected tab's value (controlled). Defaults to the first enabled tab. */\n    value?: string;\n    defaultValue?: string;\n    /** After the user selects another tab (keep `value` to cancel, e.g. unsaved changes). */\n    onValueChange?: (value: string) => void;\n    type?: TabsType;\n    size?: TabsSize;\n    activation?: TabsActivation;\n    /** Contained: the tabs share the full width in equal columns. */\n    fullWidth?: boolean;\n    /** Carbon `TabsVertical`: the tabs in a column beside the panels from md up (contained tabs in a row below). */\n    vertical?: boolean;\n    /** A fixed height for vertical tabs (Carbon `height`): the tab list and the panels then scroll. */\n    height?: string;\n    /** A close button on every tab, and Delete closes the focused tab (Carbon `dismissable`); not with `vertical`. */\n    dismissable?: boolean;\n    /**\n     * A tab's close button or Delete asked to close it (Carbon `onTabCloseRequest`): drop it from the\n     * children to close it. A closed selected tab passes the selection to the first enabled tab\n     * (`onValueChange`) unless you chose another; focus moves to the tab now in its place, else the one before.\n     */\n    onTabCloseRequest?: (value: string) => void;\n    children: ReactNode;\n    className?: string;\n}\n\n/** Vertical tabs as a column: xl 64px unless sized. */\nfunction columnTabHeight(size: TabsSize | undefined) {\n    return { sm: '32px', md: '40px', lg: '48px', xl: '64px' }[size ?? 'xl'];\n}\n\nexport function Tabs({ value, defaultValue, onValueChange, type = 'line', size, activation = 'automatic', fullWidth = false, vertical = false, height, dismissable = false, onTabCloseRequest, lang, children, className, ...rest }: Readonly<TabsProps>) {\n    const wide = useWide();\n    const column = vertical && wide;\n    // below md vertical tabs are contained tabs in a row (Carbon), an xl size there is lg\n    const effectiveType: TabsType = vertical ? 'contained' : type;\n    const panelLayer = Math.min(Math.max(useLayerLevel(), 0) + 1, 2) as 1 | 2;\n    const tabs = tabProps(children);\n    // Carbon tabs--tall: a secondary label on any contained tab (not in a column)\n    const tall = !column && effectiveType === 'contained' && tabs.some((t) => t.secondaryLabel);\n    const firstEnabled = tabs.find((t) => !t.disabled)?.value;\n    const closable = dismissable && !vertical;\n    const look = useMemo<TabsLookValue>(\n        () => ({ type: effectiveType, fullWidth: effectiveType === 'contained' && fullWidth && !vertical, column, panelLayer, tall, dismissable: closable, lang }),\n        [effectiveType, fullWidth, vertical, column, panelLayer, tall, closable, lang],\n    );\n    // below md, vertical tabs' xl is lg (Carbon)\n    const rowSize = vertical && size === 'xl' ? 'lg' : size;\n    const tabH = column ? columnTabHeight(size) : tabHeight(effectiveType, rowSize);\n    return (\n        <TabsContext.Provider value={look}>\n            <TabsPrimitive.Root\n                {...rest}\n                value={value}\n                defaultValue={defaultValue ?? firstEnabled}\n                onValueChange={onValueChange}\n                activation={activation}\n                orientation={column ? 'vertical' : 'horizontal'}\n                dismissable={closable}\n                onTabCloseRequest={onTabCloseRequest}\n                lang={lang}\n                // Carbon iconSize=\"lg\": 20px icons in 48px icon-only tabs\n                style={{ ...rest.style, ...({ '--_tab-h': tabH, '--_tab-lines': column && size === 'sm' ? 1 : undefined, '--_tab-icon': size === 'lg' ? '20px' : undefined } as CSSProperties), ...(column && height ? { height } : {}) }}\n                className={cn(\n                    'block font-sans',\n                    // Carbon TabsVertical: a CSS grid (8 columns, 16 from lg; 16px margins, 24px from max), one row\n                    column && 'grid [grid-template-columns:repeat(var(--_cols),minmax(0,1fr))] [grid-template-rows:minmax(0,1fr)] box-border w-full max-w-[1584px] mx-auto px-(--_margin) [--_cols:8] [--_margin:16px] min-[66rem]:[--_cols:16] min-[99rem]:[--_margin:24px]',\n                    // the layer the tabs sit on, resolved here: the panels shift their fields a layer up but keep this colour\n                    column && '[--_panel-bg:var(--ui-surface-1)]',\n                    className,\n                )}\n            >\n                {children}\n            </TabsPrimitive.Root>\n        </TabsContext.Provider>\n    );\n}\n\nconst chevron = (d: string) => (\n    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className=\"size-4 fill-current rtl:-scale-x-100\">\n        <path d={d} />\n    </svg>\n);\n\nexport interface TabListProps extends Omit<ComponentProps<'div'>, 'label' | 'end' | 'children' | 'className'> {\n    /** Accessible name of the tab strip, e.g. \"Contract details\". */\n    label?: string;\n    /** Content at the end of the strip, e.g. an action button. */\n    end?: ReactNode;\n    children: ReactNode;\n    className?: string;\n}\n\nexport function TabList({ label, end, children, className, ...rest }: Readonly<TabListProps>) {\n    const ctx = useTabs('TabList');\n    const list = useRef<HTMLDivElement>(null);\n    const [canStart, setCanStart] = useState(false);\n    const [canEnd, setCanEnd] = useState(false);\n    const contained = ctx.type === 'contained';\n    const column = ctx.column;\n\n    // scroll buttons while the tabs overflow (scrollLeft is negative right-to-left: measure from the start edge);\n    // in a column, a gradient where tabs are hidden once half a tab (32px) is out of view (Carbon)\n    useLayoutEffect(() => {\n        const el = list.current;\n        if (!el) return;\n        const update = () => {\n            if (column) {\n                setCanStart(el.scrollTop > 32);\n                setCanEnd(el.scrollTop + el.clientHeight + 32 <= el.scrollHeight);\n                return;\n            }\n            const fromStart = Math.abs(el.scrollLeft);\n            setCanStart(fromStart > 1);\n            setCanEnd(fromStart + el.clientWidth < el.scrollWidth - 1);\n        };\n        update();\n        const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(update);\n        observer?.observe(el);\n        el.addEventListener('scroll', update);\n        return () => {\n            observer?.disconnect();\n            el.removeEventListener('scroll', update);\n        };\n    }, [column]);\n\n    // contained dividers: none before the first tab or after the selected one, by position (a tab may sit in a wrapper)\n    useLayoutEffect(() => {\n        const tabs = list.current ? tabsIn(list.current) : [];\n        tabs.forEach((tab, i) => {\n            tab.toggleAttribute('data-first', i === 0);\n            tab.toggleAttribute('data-after-selected', i > 0 && tabs[i - 1].getAttribute('aria-selected') === 'true');\n        });\n    });\n\n    const scrollStrip = (direction: 1 | -1) => {\n        const el = list.current;\n        if (!el) return;\n        const rtl = getComputedStyle(el).direction === 'rtl' ? -1 : 1;\n        const smooth = matchMedia('(prefers-reduced-motion: no-preference)').matches;\n        el.scrollBy({ left: direction * rtl * el.clientWidth * 0.8, behavior: smooth ? 'smooth' : 'auto' });\n    };\n\n    const scrollButton = cn(\n        'grid min-h-(--_tab-h) shrink-0 cursor-pointer place-items-center p-0 text-ink',\n        contained ? 'w-12 border-0 bg-layer-accent hover:bg-layer-accent-hover active:bg-layer-accent-active' : 'w-10 ui-tab-line bg-canvas hover:bg-canvas-hover active:bg-canvas-active',\n    );\n\n    const tablist = (\n        <TabsPrimitive.List\n            ref={list}\n            aria-label={label}\n            className={cn(\n                'flex min-w-0 flex-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden',\n                // Carbon line tabs: 1px apart (--ui-tabs-gap); dismissable: the close button's box after each tab leaves 1px between contained tabs too\n                contained ? (ctx.dismissable ? 'gap-x-px' : column ? 'gap-x-0' : 'gap-x-[var(--ui-tabs-contained-gap,0px)]') : 'gap-x-[var(--ui-tabs-gap,1px)]',\n                // --ui-tabs-contained-*: Carbon's strip runs full width; a design can draw a track that hugs the tabs\n                contained && !column && 'flex-[var(--ui-tabs-contained-flex,1)] rounded-[var(--ui-tabs-contained-radius,0px)] bg-[color:var(--ui-tabs-contained-track,transparent)] p-[var(--ui-tabs-contained-padding,0px)]',\n                ctx.fullWidth && 'grid auto-cols-[minmax(0,1fr)] grid-flow-col',\n                column && 'flex-col overflow-x-hidden overflow-y-auto',\n            )}\n        >\n            {children}\n        </TabsPrimitive.List>\n    );\n\n    if (column) {\n        // the tab list over 2 of 8 columns (4 of 16 from lg) on the layer, a border-subtle edge at the end\n        return (\n            <div {...rest} className={cn('relative row-start-1 col-span-2 flex min-h-0 bg-[var(--ui-tab-vertical-background,var(--ui-surface-1))] shadow-[inset_-1px_0_var(--ui-hairline)] min-[66rem]:col-span-4', className)}>\n                {tablist}\n                {canStart ? <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 top-0 h-12 bg-linear-to-t from-transparent to-[var(--ui-tab-vertical-background,var(--ui-surface-1))]\" /> : null}\n                {canEnd ? <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 bottom-0 h-12 bg-linear-to-b from-transparent to-[var(--ui-tab-vertical-background,var(--ui-surface-1))]\" /> : null}\n            </div>\n        );\n    }\n\n    return (\n        // --ui-tabs-track: a design can draw one line under the whole strip (Carbon: each tab draws its own)\n        <div {...rest} className={cn('flex', !contained && 'shadow-[var(--ui-tabs-track,none)]', className)}>\n            <button type=\"button\" tabIndex={-1} aria-hidden=\"true\" hidden={!canStart} className={cn(scrollButton, !canStart && 'hidden')} onClick={() => scrollStrip(-1)}>\n                {chevron('m5 8 5-5 .7.7L6.4 8l4.3 4.3-.7.7z')}\n            </button>\n            {tablist}\n            <button type=\"button\" tabIndex={-1} aria-hidden=\"true\" hidden={!canEnd} className={cn(scrollButton, !canEnd && 'hidden')} onClick={() => scrollStrip(1)}>\n                {chevron('m11 8-5 5-.7-.7L9.6 8 5.3 3.7 6 3z')}\n            </button>\n            <div className={cn('flex shrink-0 items-center', !contained && 'ui-tab-line')}>{end}</div>\n        </div>\n    );\n}\n\nexport interface TabProps extends Omit<ComponentProps<'button'>, 'value' | 'disabled' | 'children' | 'className' | 'label'> {\n    /** Matches the `value` of its `<TabPanel>`. */\n    value: string;\n    disabled?: boolean;\n    /** A 16px icon after the label (Carbon `renderIcon`; before it in dismissable tabs), or alone with `iconOnly` (20px in `size=\"lg\"`). */\n    icon?: ReactNode;\n    /** A second line under the label (Carbon `secondaryLabel`); contained tabs only, they all grow to 64px. */\n    secondaryLabel?: string;\n    /** Only `icon` shows (Carbon `IconTab`): a square tab named by `label`, shown as its tooltip below. */\n    iconOnly?: boolean;\n    /** Accessible name and tooltip of an `iconOnly` tab — required with it. */\n    label?: string;\n    children?: ReactNode;\n    className?: string;\n}\n\ninterface TabLook {\n    contained: boolean;\n    column: boolean;\n    fullWidth: boolean;\n    tall: boolean;\n    dismissable: boolean;\n    iconOnly: boolean;\n}\n\n/** The tab (the button): line, contained, icon-only, tall, full width or vertical. */\nfunction tabClasses({ contained, column, fullWidth, tall, dismissable, iconOnly }: TabLook, className?: string) {\n    return cn(\n        'm-0 inline-flex min-h-(--_tab-h) shrink-0 cursor-pointer border-0 bg-[color:var(--ui-tab-background,var(--ui-canvas))] p-0 text-start text-ink-muted type-body-sm whitespace-nowrap',\n        'outline-none transition-[color,background-color,outline] duration-(--ui-duration-fast) ease-carbon hover:not-aria-disabled:text-ink focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:outline-solid focus-visible:outline-focus',\n        // --ui-tab-focus-radius / -offset: a design can round the focus ring and keep it clear of the selected underline (Carbon: square, over it)\n        'focus-visible:rounded-[var(--ui-tab-focus-radius,0px)]',\n        contained\n            ? 'focus-visible:outline-offset-[var(--ui-tab-contained-focus-offset,var(--ui-tab-focus-offset,-2px))]'\n            : 'focus-visible:outline-offset-[var(--ui-tab-focus-offset,-2px)]',\n        'aria-selected:text-ink aria-selected:type-body-emphasis',\n        'aria-disabled:cursor-not-allowed aria-disabled:text-ink-disabled',\n        // Carbon IconTab: square, its height both ways\n        iconOnly && 'w-(--_tab-h)',\n        contained && [\n            // --ui-tab-contained-*: Carbon's boxes on layer-accent; a design can make them a segmented control\n            'relative rounded-[var(--ui-tab-contained-radius,0px)] bg-[color:var(--ui-tab-contained-background,var(--ui-layer-accent))]',\n            \"before:absolute before:inset-y-0 before:-start-px before:w-px before:bg-[color:var(--ui-tab-contained-divider,var(--ui-hairline-strong))] before:content-['']\",\n            // the first tab and the one after the selected tab are marked by the tab list (they may sit in wrappers)\n            'data-first:before:content-none data-after-selected:before:content-none aria-selected:before:content-none [[aria-selected=true]+&]:before:content-none',\n            'hover:not-aria-selected:not-aria-disabled:bg-[color:var(--ui-tab-contained-hover,var(--ui-layer-accent-hover))]',\n            'aria-selected:bg-[color:var(--ui-tab-contained-selected,var(--ui-surface-1))] aria-selected:shadow-[var(--ui-tab-contained-selected-shadow,inset_0_2px_0_0_var(--ui-tab-selected-line,var(--ui-border-interactive)))] forced-colors:aria-selected:bg-[SelectedItem]',\n            'aria-disabled:bg-[color:var(--ui-tab-contained-disabled,var(--ui-button-disabled))] aria-disabled:text-[color:var(--ui-tab-contained-disabled-ink,var(--ui-on-color-disabled))]',\n            iconOnly && 'me-px',\n        ],\n        tall && 'min-h-16',\n        fullWidth && (tall ? 'flex min-w-0 overflow-hidden leading-[1.29]!' : 'block min-w-0 overflow-hidden leading-(--_tab-h)!'),\n        fullWidth && dismissable && 'flex-1',\n        // vertical (Carbon tabs--vertical): full width on layer-01, a 1px border-subtle below and at the end, a 3px bar at the start;\n        // --ui-tab-vertical-*: a design can make the rows inset, rounded, undivided ones as the side nav's\n        column && [\n            'box-border h-(--_tab-h) min-h-0 w-[calc(100%-2*var(--ui-tab-vertical-inset,0px))] mx-[var(--ui-tab-vertical-inset,0px)] flex-none whitespace-normal rounded-[var(--ui-tab-vertical-radius,0px)]',\n            'border-0 [border-block-end:var(--ui-tab-vertical-divider,1px_solid_var(--ui-hairline))] [border-inline-end:var(--ui-tab-vertical-divider,1px_solid_var(--ui-hairline))] bg-[var(--ui-tab-vertical-background,var(--ui-surface-1))]',\n            'shadow-[inset_3px_0_0_0_var(--ui-tab-vertical-bar,var(--ui-hairline))] rtl:shadow-[inset_-3px_0_0_0_var(--ui-tab-vertical-bar,var(--ui-hairline))]',\n            'hover:not-aria-selected:not-aria-disabled:bg-ghost-hover hover:not-aria-selected:not-aria-disabled:shadow-[inset_3px_0_0_0_var(--ui-tab-vertical-hover-bar,var(--ui-hairline-strong))] rtl:hover:not-aria-selected:not-aria-disabled:shadow-[inset_-3px_0_0_0_var(--ui-tab-vertical-hover-bar,var(--ui-hairline-strong))]',\n            'aria-selected:[border-inline-end:none] aria-selected:bg-[var(--ui-tab-vertical-selected,var(--ui-tab-vertical-background,var(--ui-surface-1)))] aria-selected:shadow-[inset_3px_0_0_0_var(--ui-tab-vertical-mark,var(--ui-tab-selected-line,var(--ui-border-interactive)))] rtl:aria-selected:shadow-[inset_-3px_0_0_0_var(--ui-tab-vertical-mark,var(--ui-tab-selected-line,var(--ui-border-interactive)))]',\n            'aria-disabled:bg-[var(--ui-tab-vertical-background,var(--ui-surface-1))]',\n        ],\n        className,\n    );\n}\n\n/** The part filling the tab: its padding and (line tabs) its underline. */\nfunction baseClasses({ contained, column, fullWidth, tall, dismissable, iconOnly }: TabLook) {\n    return cn(\n        'box-border flex flex-1 items-center px-4',\n        !contained && !column && [\n            // Carbon: a 2px track under every tab; --ui-tab-line / --ui-tabs-track let a design draw one line under the strip\n            'ui-tab-line transition-[border-color] duration-(--ui-duration-fast) ease-carbon',\n            // one rule per state, mutually exclusive (Lit: disabled over selected over hover); --ui-tab-selected-line: the selected tab's mark\n            '[[role=tab]:hover:not([aria-selected=true],[aria-disabled=true])>&]:border-b-[color:var(--ui-tab-hover-line,var(--ui-ink-subtle))]',\n            '[[aria-selected=true]:not([aria-disabled=true])>&]:border-b-[color:var(--ui-tab-selected-line,var(--ui-border-interactive))]',\n            '[[aria-disabled=true]>&]:border-b-[color:var(--ui-tab-disabled-line,var(--ui-hairline))]',\n            'forced-colors:[[aria-selected=true]>&]:border-b-[Highlight]',\n        ],\n        fullWidth && 'block overflow-hidden text-ellipsis',\n        // Carbon tabs--tall: the label over the secondary label, both at the start, centred together\n        tall && 'flex-col items-start justify-center',\n        tall && fullWidth && 'flex',\n        // Carbon dismissable: room for the close button (40px, contained 47px)\n        dismissable && !iconOnly && (contained ? 'pe-[47px]' : 'pe-10'),\n        iconOnly && 'justify-center p-0',\n    );\n}\n\n/** The label: two lines at most in a column, an ellipsis in full width, hidden in an icon-only tab. */\nfunction labelClasses({ column, fullWidth, iconOnly }: TabLook) {\n    return cn(\n        column && '[display:-webkit-box] overflow-hidden text-ellipsis leading-[18px] [-webkit-box-orient:vertical] [-webkit-line-clamp:var(--_tab-lines,2)]',\n        fullWidth && 'overflow-hidden text-ellipsis',\n        iconOnly && 'hidden',\n    );\n}\n\n/**\n * The icon (Carbon renderIcon): 16px in the text colour after the label, 8px from it (contained and vertical\n * 16px, pushed to the end in full width); dismissable: before the label, 8px from it, 1px higher; icon-only: centred.\n */\nfunction iconClasses({ contained, column, fullWidth, dismissable, iconOnly }: TabLook) {\n    if (iconOnly) return '[&>svg]:m-0 [&>svg]:size-(--_tab-icon,16px) [&>svg]:shrink-0 [&>svg]:fill-current';\n    const base = '[&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:fill-current';\n    if (dismissable) return `${base} [&>svg]:-order-1 [&>svg]:self-start [&>svg]:ms-0 [&>svg]:me-2`;\n    if (fullWidth) return `${base} [&>svg]:ms-auto`;\n    return `${base} ${contained || column ? '[&>svg]:ms-4' : '[&>svg]:ms-2'}`;\n}\n\nconst closeIcon = (\n    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className=\"size-4 fill-current\">\n        <path d=\"m12 4.7-.7-.7L8 7.3 4.7 4l-.7.7L7.3 8 4 11.3l.7.7L8 8.7l3.3 3.3.7-.7L8.7 8z\" />\n    </svg>\n);\n\n/**\n * Carbon dismissable: a 24px close button 12px from the tab's end, centred — a 16px text-secondary ×\n * (icon-primary on a hovered or selected tab), layer-hover under the pointer, the focus outline while\n * pressed; no Tab stop and hidden from assistive tech (Delete closes the focused tab).\n */\nfunction CloseButton({ value, title, selected, disabled }: Readonly<{ value: string; title: string; selected: boolean; disabled?: boolean }>) {\n    return (\n        <TabsPrimitive.Close\n            value={value}\n            title={title}\n            disabled={disabled}\n            className={cn(\n                'absolute inset-y-0 end-3 my-auto box-border grid size-6 cursor-pointer place-items-center rounded-[var(--ui-icon-control-radius,0px)] border-0 bg-transparent p-1 outline-none',\n                disabled\n                    ? 'cursor-not-allowed text-icon-disabled'\n                    : ['hover:bg-ghost-hover focus:outline-[length:var(--ui-focus-width,2px)] focus:outline-solid focus:-outline-offset-2 focus:outline-focus focus:not-focus-visible:outline-[color:var(--ui-pointer-focus,var(--ui-focus))] active:outline-[length:var(--ui-focus-width,2px)] active:outline-solid active:-outline-offset-2 active:outline-[color:var(--ui-pointer-focus,var(--ui-focus))]', selected ? 'text-icon-primary' : 'text-ink-muted group-hover/dismiss:text-icon-primary'],\n            )}\n        >\n            {closeIcon}\n        </TabsPrimitive.Close>\n    );\n}\n\nexport function Tab({ value, disabled, icon, secondaryLabel, iconOnly = false, label, children, className, ...rest }: Readonly<TabProps>) {\n    const ctx = useTabs('Tab');\n    const t = useTranslation(ctx.lang).common;\n    const selected = TabsPrimitive.useTabsContext().value === value;\n    const dismissable = ctx.dismissable;\n    const look: TabLook = { contained: ctx.type === 'contained' && !ctx.column, column: ctx.column, fullWidth: ctx.fullWidth, tall: ctx.tall, dismissable, iconOnly };\n    const tab = (\n        <TabsPrimitive.Tab {...rest} value={value} disabled={disabled} className={tabClasses(look, className)}>\n            <span className={baseClasses(look)}>\n                {/* the label and its icon (Carbon tabs__nav-item-label-wrapper) */}\n                <span className={cn('flex min-w-0 items-center', ctx.tall && 'max-w-full', iconClasses(look))}>\n                    <span className={labelClasses(look)}>{children}</span>\n                    {icon}\n                </span>\n                {ctx.tall && secondaryLabel ? (\n                    // Carbon secondaryLabel: label-01, at least 16px tall, regular weight\n                    <span title={secondaryLabel} className=\"block min-h-4 max-w-full overflow-hidden text-ellipsis type-caption\">\n                        {secondaryLabel}\n                    </span>\n                ) : null}\n            </span>\n        </TabsPrimitive.Tab>\n    );\n    const item = iconOnly && label ? (\n        <Tooltip text={label} asLabel placement=\"bottom\" className=\"inline-flex\">\n            {tab}\n        </Tooltip>\n    ) : (\n        tab\n    );\n    if (!dismissable || iconOnly) return item;\n    // Carbon: \"Remove <label> tab\"\n    const text = label || (typeof children === 'string' ? children : '');\n    const title = t.removeTab.replace('{text}', text).replaceAll(/\\s+/g, ' ').trim();\n    return (\n        <span className={cn('group/dismiss relative flex shrink-0', ctx.fullWidth && 'min-w-0')}>\n            {item}\n            <CloseButton value={value} title={title} selected={selected} disabled={disabled} />\n        </span>\n    );\n}\n\nexport interface TabPanelProps extends Omit<ComponentProps<'div'>, 'value' | 'children' | 'className'> {\n    /** Matches the `value` of its `<Tab>`. */\n    value: string;\n    children?: ReactNode;\n    className?: string;\n}\n\nexport function TabPanel({ value, children, className, ...rest }: Readonly<TabPanelProps>) {\n    const ctx = useTabs('TabPanel');\n    const selected = TabsPrimitive.useTabsContext().value === value;\n    return (\n        <TabsPrimitive.Panel\n            {...rest}\n            value={value}\n            className={cn(\n                'block p-4 outline-none focus-visible:rounded-[var(--ui-tab-focus-radius,0px)] focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-focus',\n                ctx.type === 'contained' && !ctx.column && 'bg-surface-1',\n                !selected && 'hidden',\n                // vertical: every panel in one cell over the rest of the grid, so the tallest sets the height; the others out of sight\n                ctx.column && ['row-start-1 col-[3/-1] min-h-0 overflow-y-auto bg-(--_panel-bg) min-[66rem]:col-[5/-1]', PANEL_LAYER[ctx.panelLayer], !selected && 'block! invisible'],\n                className,\n            )}\n        >\n            {children}\n        </TabsPrimitive.Panel>\n    );\n}\n\n/** Carbon `TabsSkeleton`: `tabs` tabs of 160×40, 1px apart, each a 2px skeleton-coloured underline and a 14px bar. Hidden from assistive tech. */\nexport function TabsSkeleton({ tabs = 5, className, ...rest }: Readonly<ComponentProps<'div'> & { tabs?: number }>) {\n    return (\n        <div {...rest} aria-hidden=\"true\" className={cn('flex gap-px', className)}>\n            {Array.from({ length: Math.max(1, tabs) }, (_, i) => (\n                <div key={i} className=\"box-border flex h-10 w-40 items-center border-0 border-b-2 border-solid border-skeleton-element px-4\">\n                    <span className=\"skeleton block h-3.5 w-full\" />\n                </div>\n            ))}\n        </div>\n    );\n}\n"
    }
  ]
}
