// // Copyright 2026 DXOS.org // // @import-as-namespace import { ark } from '@ark-ui/react/factory'; import React, { createContext, useContext } from 'react'; import { recipes } from '../../recipes.ts'; import { type Size } from '../../sizes.ts'; import { composableProps, slottable } from '../../util/slots.ts'; import { DefaultGutterProvider, type Gutter, type Level } from '../Container/Container.tsx'; // // Root // type PanelRootProps = { size?: Size; /** An absolute rung of the surface ladder; `base` by default, as the current Panel's content. */ level?: Exclude; /** `document` keeps a scrolling Body's content at the reading width, centred, while it still scrolls at the panel's edge. */ width?: 'document'; /** * The gutter of the first Container under the Body when it names none (`sm`, the form inset, by default); content * that puts icons in the rails names `gutter='rail'` itself. */ gutter?: Exclude; }; const PanelGutterContext = createContext>('sm'); /** * The plank host: fills its parent, sets `data-size` and a level for its subtree, and is the pane's * query container, so its header, body and footer collapse at the same pane width. */ const PanelRoot = slottable( ({ children, asChild, size, level = 'base', width, gutter = 'sm', ...props }, forwardedRef) => { const { className, ...rest } = composableProps(props, { classNames: recipes.panel() }); return ( {children} ); }, ); PanelRoot.displayName = 'Panel.Root'; // // Header // type PanelHeaderProps = {}; /** * The top row on the bar aspect, which steps off whatever level hosts the panel; it sizes to its content, so it takes * no space when empty and one block when it holds a `Toolbar.Root`. */ const PanelHeader = slottable(({ children, asChild, ...props }, forwardedRef) => { const { className, ...rest } = composableProps(props, { classNames: recipes.panelHeader() }); return ( {children} ); }); PanelHeader.displayName = 'Panel.Header'; // // Body // type PanelBodyProps = {}; /** * The growing middle row, a plain slot: it neither scrolls nor adds a gutter, so content composes its own frame * (`asChild` onto a `ScrollArea.Root` around a Container, or a canvas that fills the row). The first Container under it * takes the panel's gutter unless it names one. Like the header and footer it is no query container, so its content * collapses against the panel. */ const PanelBody = slottable(({ children, asChild, ...props }, forwardedRef) => { const gutter = useContext(PanelGutterContext); const { className, ...rest } = composableProps(props, { classNames: recipes.panelBody() }); return ( {children} ); }); PanelBody.displayName = 'Panel.Body'; // // Footer // type PanelFooterProps = {}; /** The bottom row on the bar aspect; like Header it sizes to its content, holding a `Toolbar.Root` when it needs one. */ const PanelFooter = slottable(({ children, asChild, ...props }, forwardedRef) => { const { className, ...rest } = composableProps(props, { classNames: recipes.panelFooter() }); return ( {children} ); }); PanelFooter.displayName = 'Panel.Footer'; export type { PanelBodyProps as BodyProps, PanelFooterProps as FooterProps, PanelHeaderProps as HeaderProps, PanelRootProps as RootProps, }; export { PanelBody as Body, PanelFooter as Footer, PanelHeader as Header, PanelRoot as Root };