import { type Accessor, createContext, useContext } from "solid-js"; /** * Context value provided by `` to its compound parts. * * Reactive values are exposed as `Accessor`s (not plain numbers/strings) so * descendants stay reactive to upstream prop changes without having to * subscribe through a signal wrapper. * * `setLabelId` is the registration channel used by `` to report * its generated id into the root, so the root can wire up `aria-labelledby`. */ export interface MeterRootContextValue { /** Accessor for the current meter value. */ value: Accessor; /** Accessor for the minimum value of the range. */ min: Accessor; /** Accessor for the maximum value of the range. */ max: Accessor; /** * Accessor for the formatted (human-readable) current value — either the * value formatted via the root's `format` / `locale` props, or the default * percentage form when no explicit format is provided. */ formattedValue: Accessor; /** * Register/deregister the label id that drives ``'s * `aria-labelledby`. Called by `` from its mount/unmount * lifecycle. */ setLabelId: (id: string | undefined) => void; } /** * Meter root context. Solid 2's `useContext` throws `ContextNotFoundError` * when the resolved value is `undefined`, so the sentinel for "no provider * mounted" is `null` — a custom message after `useContext` would never fire * against the default `undefined`. */ export const MeterRootContext = createContext( null, ); export function useMeterRootContext(): MeterRootContextValue { const context = useContext(MeterRootContext); if (context == null) { throw new Error( "Base UI: parts must be used within .", ); } return context; }