import { type Accessor, createContext, useContext } from "solid-js"; import type { Orientation } from "../internals/types"; /** * Per-item metadata carried alongside a `` or `` * registration. `focusableWhenDisabled` is the only field — it drives the * `disabledIndices` projection on the composite root so arrow navigation can * skip items that cannot take focus. */ export interface ToolbarRootItemMetadata { focusableWhenDisabled: boolean; } /** * Value handed down by `` to descendant parts. * * Solid 2 adaptations from Base UI React's `ToolbarRootContext`: * * - Reactive slots are `Accessor` so children pull on demand without * tripping the top-level-reactive-read rule. * - `present` is `true` only when provided by a real ``. * Parts branch on it — `` tolerates being rendered * outside, and `` / `` throw (matching React). * * Note: React's `setItemMap` does NOT appear here. Each item already reports * its metadata via `useCompositeListItem({ metadata })`; the root captures the * sorted map from `` and derives `disabledIndices` * directly. See the header comment in `toolbar-root.tsx`. */ export interface ToolbarRootContextValue { /** Whether the whole toolbar ignores user interaction. */ disabled: Accessor; /** Navigation orientation. */ orientation: Accessor; /** Marker — `true` when provided by a real ``. */ readonly present: boolean; } /** * No-op sentinel used when parts are rendered outside a ``. * Children branch on `.present` to decide whether to throw. */ export const NOOP_TOOLBAR_ROOT_CONTEXT: ToolbarRootContextValue = { disabled: () => false, orientation: () => "horizontal", present: false, }; export const ToolbarRootContext = createContext( NOOP_TOOLBAR_ROOT_CONTEXT, ); export function useToolbarRootContext(optional: true): ToolbarRootContextValue; export function useToolbarRootContext( optional?: false, ): ToolbarRootContextValue; export function useToolbarRootContext( optional = false, ): ToolbarRootContextValue { const context = useContext(ToolbarRootContext); if (!context.present && !optional) { throw new Error( "Base UI: ToolbarRootContext is missing. Toolbar parts must be placed within .", ); } return context; }