import type { JSX } from "@solidjs/web"; import { type Accessor, createContext, useContext } from "solid-js"; import type { MutableRef } from "../../internals/floating-ui/types"; /** `side` values reported by floating-ui's `placement.split('-')[0]`. */ export type PopoverSide = | "top" | "right" | "bottom" | "left" | "inline-start" | "inline-end"; /** `align` values mapped from floating-ui's placement suffix. */ export type PopoverAlign = "start" | "center" | "end"; /** * Shared positioning state produced by the positioner and consumed by the * arrow + popup for their own reactive `side` / `align` data-attrs and for * the arrow's absolute-position styles. * * Mirrors Base UI React's `PopoverPositionerContext`. */ export interface PopoverPositionerContextValue { /** Resolved side (`'top'`, `'bottom'`, ...) from the placement. */ side: Accessor; /** Resolved align (`'start'`, `'center'`, `'end'`) from the placement. */ align: Accessor; /** Whether the anchor has been scrolled out of view. */ anchorHidden: Accessor; /** * Arrow element ref slot. `` writes to this on mount so * the arrow middleware can read the element dimensions on next update. */ arrowRef: MutableRef; /** Reactive absolute-position styles for the arrow element. */ arrowStyles: Accessor; /** Whether the arrow is visually off-center (too close to a collision edge). */ arrowUncentered: Accessor; } export const PopoverPositionerContext = createContext(null); /** * Read the current `` context. Throws unless the * consumer is rendered inside a positioner. */ export function usePopoverPositionerContext(): PopoverPositionerContextValue { const context = useContext(PopoverPositionerContext); if (context == null) { throw new Error( "Base UI: PopoverPositionerContext is missing. Popover.Arrow and Popover.Popup must be placed inside .", ); } return context; }