UNPKG

@hypothesis/frontend-shared

Version:

Shared components, styles and utilities for Hypothesis projects

46 lines (45 loc) 1.76 kB
import type { ComponentChildren, JSX, RefObject } from 'preact'; /** * Space in pixels to apply between the popover and the viewport sides to * prevent it from growing to the very edges. */ export declare const POPOVER_VIEWPORT_HORIZONTAL_GAP = 8; export type PopoverProps = { children?: ComponentChildren; classes?: string | string[]; variant?: 'panel' | 'custom'; /** Ref for the popover element. */ elementRef?: RefObject<HTMLElement>; /** Whether the popover is currently open or not */ open: boolean; /** * Callback invoked when the popover is automatically closed. * Use this callback to sync local state. */ onClose: () => void; /** The element relative to which the popover should be positioned */ anchorElementRef: RefObject<HTMLElement | undefined>; /** * Determines to which side of the anchor element the popover should be * aligned. * * Defaults to `left` */ align?: 'right' | 'left'; /** * Determines if focus should be restored when the popover is closed. * Defaults to true. * * @deprecated - Setting this prop to `false` does not work if native popovers * are used. This prop will be removed entirely in future. */ restoreFocusOnClose?: boolean; /** * Used to determine if the popover API should be used. * Defaults to true, as long as the browser supports it. */ asNativePopover?: boolean; /** A callback passed to the outermost element onScroll */ onScroll?: JSX.HTMLAttributes<HTMLElement>['onScroll']; }; export default function Popover({ anchorElementRef, children, open, onClose, align, classes, variant, onScroll, elementRef, asNativePopover, }: PopoverProps): JSX.Element;