import React from 'react'; import { SpringConfig } from '@react-spring/web'; import PropTypes from 'prop-types'; import { ComponentProps } from '../utils/types'; /** @public */ type PopoverChildrenRenderer = (data: { anchorHeight: number | null; anchorWidth: number | null; maxHeight: number | null; maxWidth: number | null; placement: PopoverPlacementStatus | null; toggleId?: string; }) => React.ReactNode; /** @public */ type PopoverPlacement = 'above' | 'below' | 'left' | 'right' | 'vertical' | 'horizontal'; /** @public */ type PopoverPlacementStatus = 'above' | 'below' | 'left' | 'right' | 'misaligned'; /** @public */ type PopoverPossibleCloseReason = 'clickAway' | 'escapeKey' | 'offScreen' | 'tabKey'; /** @public */ type PopoverRequestCloseHandler = (data: { event?: MouseEvent | KeyboardEvent | TouchEvent; reason: PopoverPossibleCloseReason; }) => void; interface PopoverPropsBase { /** * The `Popover `can align itself to the center of the anchor or to its edges. * * This property is ignored when `pointTo` is set. * * Note: `end` is ONLY supported with `below` PopoverPlacement * * TODO: Allow users to supply align prop SUI-5101 * @private */ align?: 'center' | 'edge' | 'end'; /** * The element used to set the position of the `Popover`. It is required when the `Popover` is * open and must be mounted. */ anchor?: HTMLElement | null; /** * A React ref which is set to the DOM element when the component mounts and null when it unmounts. */ elementRef?: React.Ref; /** * Allows the `Popover` to point to and align with a different part of the anchor. * The x and y values are relative to the upper left corner of the anchor. * * This property overides `align`. * * When positioned above or below, only `x` is used. When positioned left or right, `y` is used. */ pointTo?: { x?: number; y?: number; }; /** * If `true`, the popover applies transitions when * it is added to the DOM. */ animation?: boolean; /** * Allows the animation config to be overridden. * This is merged with Popover's default animation config. * @private */ animationConfig?: SpringConfig; /** * `'normal'` is the default appearance.`'none'` is a transparent box. * * @deprecatedValue 'inverted' * The 'inverted' value is deprecated and will be removed in a future major version. */ appearance?: 'normal' | 'inverted' | 'none'; /** * If `true`, the `Popover` hides when the anchor is scrolled off the screen. */ autoCloseWhenOffScreen?: boolean; /** * If there isn't enough room to render the `Popover` in a direction, this option enables * it to be rendered over the anchor. */ canCoverAnchor?: boolean; /** * The content of the `Popover`. If a function is provided, it is invoked with an * object containing `anchorHeight`, `anchorWidth`, `maxHeight`, `maxWidth`, and * `placement`, and is expected to return renderable content. */ children?: React.ReactNode | PopoverChildrenRenderer; /** * An array of reasons for which this `Popover` should close. */ closeReasons?: PopoverPossibleCloseReason[]; /** * The default placement of the `Popover`. It might be rendered in a different direction * depending upon the space available and the `repositionMode`. */ defaultPlacement?: PopoverPlacement; /** * Whether or not to hide the arrow pointing to the anchor. * * The arrow is always hidden when `appearance="none"`. */ hideArrow?: boolean; /** * A ref for the hit area path. * @private */ hitAreaRef?: React.Ref; /** * @private. */ id?: string; /** * Callback function fired when the popover is requested to be closed. */ onRequestClose?: PopoverRequestCloseHandler; /** * If `true`, the `Popover` is visible. */ open?: boolean; /** * A ref for the outer popover container. * @private */ outerRef?: React.Ref; /** * If the `Popover` doesn't fit in the `defaultPlacement`, `repositionMode` determines if * and how the `Popover` repositions itself to fit on the page. * `none` doesn't reposition the `Popover`. It always renders in the * `defaultPlacement` direction. * `flip` allows the `Popover` to reposition to the opposite of the `defaultPlacement` * if it can fit there and not in the `defaultPlacement`. * `any` allows the `Popover` to reposition in any direction if it can fit on the page. */ repositionMode?: 'none' | 'flip' | 'any'; /** * Keeps focus within the `Popover` while open. */ retainFocus?: boolean; /** * When `true`, the `Popover` automatically takes focus when 'open' changes to `true`. * Disable this for a `Popover` that has shows on hover, such as a tooltip. */ takeFocus?: boolean; /** * Id of the toggle is added to aria-labelledby attribute of inner results menu * @private */ toggleId?: string; } type PopoverProps = ComponentProps; /** * `Popover` is used to create layovers such as dropdowns, contextual menus, or tooltips. Use * this only when the other components don't provide sufficient functionality or control. A controlled * `Dropdown` covers use cases where you might consider using `Popover` directly. */ declare function Popover({ align, anchor, animation, animationConfig, appearance, autoCloseWhenOffScreen, canCoverAnchor, children, closeReasons, defaultPlacement, elementRef, hideArrow, hitAreaRef, id, onRequestClose, open, outerRef, pointTo, repositionMode, retainFocus, takeFocus, toggleId, ...otherProps }: PopoverProps): React.JSX.Element; declare namespace Popover { var propTypes: { align: PropTypes.Requireable; anchor: PropTypes.Requireable; animation: PropTypes.Requireable; animationConfig: PropTypes.Requireable; appearance: PropTypes.Requireable; autoCloseWhenOffScreen: PropTypes.Requireable; canCoverAnchor: PropTypes.Requireable; children: PropTypes.Requireable>; closeReasons: PropTypes.Requireable<(PopoverPossibleCloseReason | null | undefined)[]>; defaultPlacement: PropTypes.Requireable; elementRef: PropTypes.Requireable; id: PropTypes.Requireable; hideArrow: PropTypes.Requireable; hitAreaRef: PropTypes.Requireable; onRequestClose: PropTypes.Requireable<(...args: any[]) => any>; open: PropTypes.Requireable; outerRef: PropTypes.Requireable; pointTo: PropTypes.Requireable; y: PropTypes.Requireable; }>>; repositionMode: PropTypes.Requireable; retainFocus: PropTypes.Requireable; takeFocus: PropTypes.Requireable; splunkTheme: PropTypes.Requireable; }; var possibleCloseReasons: PopoverPossibleCloseReason[]; } export default Popover; export type { PopoverChildrenRenderer, PopoverPlacement, PopoverPlacementStatus, PopoverPossibleCloseReason, PopoverRequestCloseHandler, };