// // Copyright 2026 DXOS.org // // @import-as-namespace import { Tabs as TabsPrimitive, useTabsContext } from '@ark-ui/react/tabs'; import React, { type ComponentPropsWithoutRef, forwardRef } from 'react'; import { mx } from '@dxos/ui-theme'; import { type ThemedClassName } from '@dxos/ui-types'; import { recipes } from '../../recipes.ts'; import { type Size } from '../../sizes.ts'; import { composable, composableProps } from '../../util/slots.ts'; import { Button } from '../Button/Button.tsx'; type TabsOrientation = 'horizontal' | 'vertical'; /** How the selected trigger is filled: the input surface, or the accent (e.g. while the host has attention). */ type TabsSelectedVariant = 'default' | 'primary'; // // Root // type TabsRootProps = ThemedClassName< Omit > & { value?: string; defaultValue?: string; onValueChange?: (value: string) => void; size?: Size; selectedVariant?: TabsSelectedVariant; /** Keep inactive panels mounted (hidden); by default they unmount, so their content re-runs its effects on show. */ keepMounted?: boolean; }; /** * Ark's tabs: a list of triggers over (horizontal) or beside (vertical) the selected content. A trigger activates on * click or Enter (`activationMode='manual'`); arrow keys move focus along the list. Composable, so a host's `asChild` * (e.g. `Panel.Root`) merges its className and ref onto the tabs element. */ const TabsRoot = composable>( ( { value, defaultValue, onValueChange, orientation = 'horizontal', activationMode = 'manual', size, selectedVariant = 'default', keepMounted = false, ...props }, forwardedRef, ) => ( onValueChange(value))} orientation={orientation} activationMode={activationMode} lazyMount={!keepMounted} unmountOnExit={!keepMounted} data-size={size} data-selected-variant={selectedVariant} ref={forwardedRef} /> ), ); TabsRoot.displayName = 'Tabs.Root'; // // List // type TabsListProps = ThemedClassName; /** The tablist: a row (or column) of triggers that scrolls along its axis when they overflow. */ const TabsList = forwardRef(({ classNames, ...props }, forwardedRef) => ( )); TabsList.displayName = 'Tabs.List'; // // Trigger // type TabsTriggerProps = | (ComponentPropsWithoutRef & Pick & { asChild?: false }) | (Omit & { asChild: true }); /** * A ghost Button that fills when selected; takes Button's content props (`icon`, `label`, `iconOnly`). With `asChild` * the child element is the tab as it is (e.g. a rail of avatars), taking only the tab's state and behaviour. */ const TabsTrigger = forwardRef((props, forwardedRef) => { if (props.asChild) { return ; } const { value, disabled, classNames, variant = 'ghost', asChild: _asChild, ...buttonProps } = props; return (