import { type AnchorHTMLAttributes, type HTMLAttributes, type SetStateAction, type Dispatch, type DOMAttributes } from 'react'; import type { _AriaBaseButtonProps as AriaBaseButtonProps, _AriaButtonProps as AriaButtonProps, _ButtonAria as ButtonAria } from '@dynatrace/strato-components/buttons'; import { OverlayTriggerState } from './useOverlay.js'; import { Elevation } from '../../core/hooks/useOverlayStacking.js'; import type { FormControlRef } from '../../forms/shared-types.js'; /** * @public */ export type OverlayPlacement = 'auto' | 'auto-start' | 'auto-end' | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'right-start' | 'right-end' | 'left-start' | 'left-end'; /** * @public */ export type OverlaySizeStrategyRange = { min?: number; max?: number; }; /** * @public */ export type WidthStrategy = 'content' | 'trigger' | OverlaySizeStrategyRange; /** * @public */ export type HeightStrategy = 'content' | 'maxViewport' | OverlaySizeStrategyRange; /** * @public */ export interface UseOverlayWithTriggerUncontrolledProps { /** * Whether the overlay is open by default. * @defaultValue false */ defaultOpen?: boolean; /** * Determines whether or not the overlay is open in a controlled scenario. */ open?: never; } /** * @public */ export interface UseOverlayWithTriggerControlledProps { /** * Whether the overlay is open by default. */ defaultOpen?: never; /** * Determines whether or not the overlay is open in a controlled scenario. */ open: boolean; } /** * @public */ export interface UseOverlayWithTriggerBaseProps { /** * Placement of the overlay * @defaultValue 'bottom' */ placement?: OverlayPlacement; /** * Alternative positions that will be assumed if the original placement will not fit * @defaultValue ['top'] */ placementFallbacks?: OverlayPlacement[]; /** * Offset between overlay and target element * @defaultValue 0 */ offset?: number; /** * Offset along the cross axis between the overlay and target element * @defaultValue 0 */ crossOffset?: number; /** * An additional z-index elevation value to add to the one derived from the stacking order */ additionalElevation?: Elevation; /** * Whether the trigger is disabled or not * @defaultValue false */ disabled?: boolean; /** * Defines which strategy to use for setting the overlay width * @defaultValue 'content' */ widthStrategy?: WidthStrategy; /** * Defines which strategy to use for setting the overlay height * @defaultValue 'content' */ heightStrategy?: HeightStrategy; /** * Whether the overlay should trap the focus. * @defaultValue false */ trapFocus?: boolean; /** * Callback fired when the open attribute changes. */ onOpenChange?: (isOpen: boolean) => void; /** * Whether the overlay should close on blur. * @defaultValue false */ shouldCloseOnBlur?: boolean; /** * Id used for the accessible label of the overlay */ 'aria-labelledby'?: string; } /** * @public */ export type UseOverlayWithTriggerProps = UseOverlayWithTriggerBaseProps & (UseOverlayWithTriggerUncontrolledProps | UseOverlayWithTriggerControlledProps); /** * @public */ export interface OverlayRefs { /** * Use this ref and attach it to the trigger element. * State handling of opening and closing will be automatically attached * to the trigger. */ triggerRef: Dispatch>; /** * Use this ref to attach it to the overlaying element. This is used * to correctly position the overlay on the screen. */ overlayRef: Dispatch>; /** * Use this ref in order to give the overlay its anchoring element. * The overlaying element will attach to the target element by following * the provided placement and placementFallback strategies. * If the triggerRef and targetRef should be on the same element, consider * using the `useMergeRefs` from the package core to combine target and trigger * refs. */ targetRef: Dispatch>; } /** * Type used for defining the 'data-ismodal' property, as well as modal accessibility and styling properties. * @public */ export interface ModalAriaProps extends HTMLAttributes { /** Data attribute marks the dom node as a modal for the aria-modal-polyfill. */ 'data-ismodal'?: boolean; } /** * @public */ export interface OverlayProps { /** * Properties for connecting the overlay to the overlay trigger. * Includes styles and accessibility attributes. */ overlayProps: ModalAriaProps & Pick; /** * Overlay state, which contains information about the open/closed state of the overlay, * as well as opening/closing/toggling methods. */ overlayState: OverlayTriggerState; /** * Props for the OverlayContainer component, used in order to ensure correct * zIndex stacking. */ overlayContainerProps: Record; } /** * @deprecated Will be removed. Use `OverlayWithTriggerReturnType` to access `overlayTriggerProps` instead. `hasError` was never set. * @public */ export interface OverlayTriggerProps { /** Properties for the behavior and accessibility of the overlay trigger. */ overlayTriggerProps: ButtonAria> & AriaButtonProps; /** Whether or not the trigger is used within a component in an error state. */ hasError?: boolean; } /** * Properties for spreading onto the trigger and overlay container, handling the * behavior and accessibility of the trigger and overlay. * @deprecated Will be removed. Use `TriggerProps` instead * @public */ export type OverlayWithTriggerProps = OverlayRefs & OverlayProps & OverlayWithTriggerReturnType['overlayTriggerProps']; /** * Type reflecting the properties for the behavior and accessibility of the overlay trigger. * @public */ export type TriggerProps = Pick & Pick, 'onKeyDown' | 'onKeyUp' | 'onClick' | 'onMouseDown' | 'onMouseUp' | 'onPointerDown' | 'onPointerUp' | 'onDragStart' | 'onMouseEnter' | 'onMouseLeave' | 'onTouchStart' | 'onTouchEnd' | 'onTouchMove' | 'onTouchCancel'> & { /** Whether the trigger is disabled. */ disabled?: boolean; }; /** * Properties for spreading onto the trigger and overlay container, handling the * behavior and accessibility of the trigger and overlay. * @public */ export type OverlayWithTriggerReturnType = OverlayRefs & OverlayProps & { /** Properties for the behavior and accessibility of the overlay trigger. */ overlayTriggerProps: TriggerProps; }; /** * Custom hook used for overlays with trigger. * @public */ export declare function useOverlayWithTrigger(props?: UseOverlayWithTriggerProps): OverlayWithTriggerReturnType;