import type { JSX } from "@solidjs/web"; import { FloatingDelayGroup } from "../../internals/floating-ui/components/floating-delay-group"; import { TooltipProviderContext, type TooltipProviderContextValue, } from "../tooltip-provider-context"; export interface TooltipProviderProps { /** Tooltip children. */ children?: JSX.Element; /** * How long to wait before opening a tooltip. Specified in milliseconds. */ delay?: number | undefined; /** * How long to wait before closing a tooltip. Specified in milliseconds. */ closeDelay?: number | undefined; /** * Another tooltip will open instantly if the previous tooltip * is closed within this timeout. Specified in milliseconds. * @default 400 */ timeout?: number | undefined; } /** * Provides a shared delay for multiple tooltips. The grouping logic ensures * that once a tooltip becomes visible, the adjacent tooltips will be shown * instantly. Mirrors Base UI React's ``. * * Solid 2 notes: * * - `FloatingDelayGroup` lives under the floating-ui-react Solid port and * owns the `delayRef` / instant-phase coordination. The provider only * contributes the consumer-configurable `delay` / `closeDelay` values — * sibling triggers read them via `useTooltipProviderContext`. * - Timeout defaults to 400 ms (matches React). */ export function TooltipProvider(props: TooltipProviderProps): JSX.Element { const contextValue: TooltipProviderContextValue = { get delay() { return props.delay; }, get closeDelay() { return props.closeDelay; }, }; const timeout = (): number => props.timeout ?? 400; // `FloatingDelayGroup` expects a `Delay` object (or number). We construct // one lazily so the provider re-renders pick up `delay` / `closeDelay` // prop changes without dropping the group context. const delayValue = { get open() { return props.delay; }, get close() { return props.closeDelay; }, }; return ( {props.children} ); }