// // Copyright 2026 DXOS.org // // @import-as-namespace import { Collapsible as CollapsiblePrimitive } from '@ark-ui/react/collapsible'; import React, { forwardRef, useContext } from 'react'; import { mx } from '@dxos/ui-theme'; import { type ThemedClassName } from '@dxos/ui-types'; import { recipes } from '../../recipes.ts'; import { containerAttributes } from '../Container/Container.tsx'; import * as Icon from '../Icon/Icon.tsx'; import { RowContext } from '../Listbox/grid.ts'; // // Root // type CollapsibleRootProps = ThemedClassName; const CollapsibleRoot = forwardRef(({ classNames, ...props }, forwardedRef) => ( )); CollapsibleRoot.displayName = 'Collapsible.Root'; // // Trigger // type CollapsibleTriggerProps = ThemedClassName & { icon?: string; }; /** * A block row: a caret that turns to point down when open, followed by the label. Without children it is the caret * alone, a block-sized square for a list row's trailing column, named by the row's `ItemText` unless given a label. */ const CollapsibleTrigger = forwardRef( ({ classNames, icon = 'ph--caret-right--regular', children, ...props }, forwardedRef) => { const row = useContext(RowContext); const caretOnly = children === undefined; const labelledBy = caretOnly && props['aria-label'] === undefined && props['aria-labelledby'] === undefined ? row?.textId : undefined; return ( {children} ); }, ); CollapsibleTrigger.displayName = 'Collapsible.Trigger'; // // Content // type CollapsibleContentProps = ThemedClassName & { /** `inherit` makes the content a subgrid of the enclosing grid (a Container or a grid Fieldset), keeping its rails. */ gutter?: 'inherit'; }; /** Animates its height from Ark's measured `--height`. */ const CollapsibleContent = forwardRef( ({ classNames, gutter, style, ...props }, forwardedRef) => { const { style: gridStyle, ...grid } = gutter ? containerAttributes({ gutter }) : { style: undefined }; return ( ); }, ); CollapsibleContent.displayName = 'Collapsible.Content'; export type { CollapsibleContentProps as ContentProps, CollapsibleRootProps as RootProps, CollapsibleTriggerProps as TriggerProps, }; export { CollapsibleContent as Content, CollapsibleRoot as Root, CollapsibleTrigger as Trigger };