/** * Context set by `` — a global coordinator that tracks * which drawers are open and exposes a non-reactive visual-state store * consumed by `` / ``. * * 1:1 port of Base UI React's `DrawerProviderContext`. */ import { type Accessor, createContext, useContext } from "solid-js"; /** * Non-reactive visual-state store. Driven by swipe progress updates; read * by `` to push CSS vars on its element without any Solid * reactivity round-trip (matches React's `useSyncExternalStore` model). */ export interface DrawerVisualState { swipeProgress: number; frontmostHeight: number; } export interface DrawerVisualStateStore { getSnapshot: () => DrawerVisualState; subscribe: (listener: () => void) => () => void; set: (state: Partial) => void; } export interface DrawerProviderContextValue { /** Register/update a drawer's open flag. */ setDrawerOpen: (drawerId: string, open: boolean) => void; /** Remove a drawer from the registry. */ removeDrawer: (drawerId: string) => void; /** Whether ANY registered drawer is currently open. */ active: Accessor; /** Visual-state store. */ visualStateStore: DrawerVisualStateStore; } /** * Null-sentinel context. `` is optional; most * drawer parts consult it via `useDrawerProviderContext(true)`. */ export const DrawerProviderContext = createContext(null); export function useDrawerProviderContext(): DrawerProviderContextValue; export function useDrawerProviderContext( optional: true, ): DrawerProviderContextValue | null; export function useDrawerProviderContext( optional?: boolean, ): DrawerProviderContextValue | null { const context = useContext(DrawerProviderContext); if (context == null && !optional) { throw new Error( "Base UI: DrawerProviderContext is missing. Use .", ); } return context; }