import { type ComponentProps, type ReactNode, type RefObject } from 'react'; import type { Placement } from '../core/position.js'; /** * Unstyled Carbon `Popover` / `Toggletip`, the behaviour of the styled ones without a single class: * your own content in a `Popup` in the top layer beside the trigger (flipped when it doesn't fit, * re-placed on scroll). A `Trigger` button toggles it (`aria-expanded`, `aria-controls`); or wrap * your own trigger element in an `Anchor` and give it `triggerProps` from `usePopoverContext()`. * `dismissible` (on by default): Esc on the trigger or in the popup (one nothing inside took) and a * press outside the trigger and the popup ask to close; after Esc, focus goes back to the trigger. * `closeOnFocusOut` (Toggletip): focus moving from the trigger or the popup to anything else * closes it. `Close` asks to close from inside. * * `onOpenChange(open, reason)` reports changes only — `trigger`, `escape`, `outside`, `focus-out`, * `close` (focus leaving a closed toggletip reports nothing). State shows as data attributes: `data-open` on `Trigger`, * `Anchor` and `Popup` (not on `Close`), `data-side` (top | bottom | left | right, where it ended up) on * `Popup`; with `caret`, the popup gets `--_caret-start`, where a caret `--_caret-w` wide starts so it * points at the trigger's centre. * * ```tsx * * … * …Done * * ``` */ export type PopoverChangeReason = 'trigger' | 'escape' | 'outside' | 'focus-out' | 'close'; export interface RootProps { /** Controlled: the popup shows while true. */ open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean, reason: PopoverChangeReason) => void; /** Esc on the trigger or in the popup, and a press outside, ask to close (default true). */ dismissible?: boolean; /** Focus moving out of the trigger and the popup closes it (Carbon Toggletip). */ closeOnFocusOut?: boolean; /** top | bottom | left | right, optionally `-start` / `-end` (default bottom). */ placement?: Placement; /** Space between the trigger and the popup (default 8). */ gap?: number; /** Writes `--_caret-start` on the popup, to place a caret. */ caret?: boolean; children?: ReactNode; } type DismissReason = 'escape' | 'outside' | 'close'; interface PopoverContextValue { popupId: string; open: boolean; /** For your own trigger element inside an `Anchor`. */ triggerProps: { 'aria-expanded': boolean; 'aria-controls': string; }; popup: RefObject; setOpen: (open: boolean, reason: PopoverChangeReason) => void; /** Asks to close; after Esc or `Close`, focus goes back to the trigger when it was inside. */ dismiss: (reason: DismissReason) => void; /** Where presses and focus count as inside (with the popup), and what the popup sits beside. */ register: (area: Element | null, anchor: Element | null) => void; /** Focus moved to `next` (a blur's relatedTarget): with `closeOnFocusOut`, somewhere else closes. */ focusMoved: (next: EventTarget | null) => void; /** A press with this composed path is on the trigger or the popup. */ pressedInside: (path: EventTarget[]) => boolean; } /** The state of the enclosing `Popover.Root` (open, the popup's id, `triggerProps` …). */ export declare function usePopoverContext(part?: string): PopoverContextValue; /** Holds the open state, places the popup and closes it on Esc / outside presses; renders only its children. */ export declare function Root({ open, defaultOpen, onOpenChange, dismissible, closeOnFocusOut, placement, gap, caret, children }: Readonly): import("react").JSX.Element; export type TriggerProps = Omit, 'type'>; /** The button that toggles the popup (`aria-expanded`, `aria-controls`); the popup sits beside it. */ export declare function Trigger({ ref, ...rest }: Readonly): import("react").JSX.Element; /** * Wraps your own trigger element (in place of `Trigger`): the popup sits beside its first element * child (the wrapper's own box differs between engines), a press anywhere inside it is not * outside, and focus returns to that child (or the control inside it) after Esc. Put the `Popup` * inside it to keep the two together. Give the trigger `triggerProps` from `usePopoverContext()`. */ export declare function Anchor({ ref, ...rest }: Readonly>): import("react").JSX.Element; export type PopupProps = Omit, 'popover' | 'id'>; /** The box in the top layer (`role="group"`: name it with `aria-label`); its content stays rendered while closed. */ export declare function Popup({ ref, ...rest }: Readonly): import("react").JSX.Element; /** Asks to close (`'close'`); focus goes back to the trigger. */ export declare function Close(props: Readonly, 'type'>>): import("react").JSX.Element; export {};