import type { JSX } from "@solidjs/web"; import { type Accessor } from "solid-js"; import { type MaybeAccessor } from "./maybe-accessor.js"; /** * Why a popup's open state changed. * * Compounds may extend this with their own reason literals — e.g. * `"trigger-hover"` for Tooltip. The common reasons are surfaced here so * `createPopupCore` can emit a meaningful default without knowing the * per-compound vocabulary. * * - `"trigger-press"` — user activated the trigger (click / Enter / Space). * - `"imperative"` — `popup.setOpen()` called with no originating DOM event. * - `"escape-key"` — Escape key dismissed the popup. * - `"outside-press"` — pointer press outside the popup dismissed it. */ export type PopupCoreChangeReason = "trigger-press" | "imperative" | "escape-key" | "outside-press"; /** * Options accepted by {@link createPopupCore}. Every reactive field is * `MaybeAccessor` — pass an accessor to keep the option live. */ export interface CreatePopupCoreOptions { /** * Open state. Consumer-owned signal — the primitive reads through the * accessor and does NOT keep an internal copy. Writes happen via * `onOpenChange` (the consumer's responsibility to update their signal). */ open: MaybeAccessor; /** * Whether interaction is suppressed. * @default false */ disabled?: MaybeAccessor; /** * Pre-change callback. Called via `runWithOwner(null, ...)` so consumer * signal writes inside the handler don't trigger SIGNAL_WRITE_IN_OWNED_SCOPE. */ onOpenChange?: (open: boolean, event: Event, reason: Reason) => void; } /** * Public API returned by {@link createPopupCore}. */ export interface PopupCoreApi { /** Reactive accessor for the current open state. */ open: Accessor; /** Whether interaction is suppressed. */ disabled: Accessor; /** * Imperative open setter. Fires `onOpenChange(next, event, reason)` via * `runWithOwner(null, ...)` to escape the reactive owner. */ setOpen: (next: boolean, event?: Event, reason?: Reason) => void; /** * Flip open (no-op when disabled). Same event/reason contract as setOpen. */ toggle: (event?: Event, reason?: Reason) => void; /** * Context provider. Wrap a subtree to expose the core api via * `usePopupCore()`. */ Provider: (props: { children: JSX.Element; }) => JSX.Element; } /** * Read the nearest {@link PopupCoreApi} from a ``. * Throws unless `optional` is true. */ export declare function usePopupCore(): PopupCoreApi; export declare function usePopupCore(optional: true): PopupCoreApi | null; /** * Shared headless primitive for popup compounds (Tooltip, Popover, Dialog, * PreviewCard, AlertDialog, Drawer). Owns: * * - `open` memo — reads through the consumer's accessor. * - `disabled` memo — guards setOpen / toggle. * - `setOpen` / `toggle` — pure event-emitters that fire `onOpenChange` * via `runWithOwner(null, ...)`. * - `Provider` — optional context provider. * * DOM machinery (floating-ui, portal, focus trap, scroll lock, animation) * lives in the per-compound `` wrappers that compose this. */ export declare function createPopupCore(options: CreatePopupCoreOptions): PopupCoreApi; //# sourceMappingURL=create-popup-core.d.ts.map