UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

77 lines (76 loc) 3.74 kB
import React, { CSSProperties } from "react"; import { AsChild } from "../../util/types/AsChild"; import { CustomFocusEvent, CustomPointerDownEvent } from "./util/dispatchCustomEvent"; interface DismissableLayerBaseProps { /** * When `true`, hover/focus/click interactions will be disabled on elements outside * the `DismissableLayer`. Users will need to click twice on outside elements to * interact with them: once to close the `DismissableLayer`, and again to trigger the element. */ disableOutsidePointerEvents?: boolean; /** * Event handler called when the escape key is down. * Can be prevented. */ onEscapeKeyDown?: (event: KeyboardEvent) => void; /** * Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`. * Can be prevented. */ onPointerDownOutside?: (event: CustomPointerDownEvent) => void; /** * Event handler called when the focus moves outside of the `DismissableLayer`. * Can be prevented. */ onFocusOutside?: (event: CustomFocusEvent) => void; /** * Event handler called when an interaction happens outside the `DismissableLayer`. * Specifically, when a `pointerdown` event happens outside or focus moves outside of it. * Can be prevented. */ onInteractOutside?: (event: CustomPointerDownEvent | CustomFocusEvent) => void; /** * Handler called when the `DismissableLayer` should be dismissed */ onDismiss?: () => void; /** * Stops `onDismiss` from beeing called when interacting with the `safeZone` elements. * `safeZone.dismissable` is only needed when its element does not have a `tabIndex` since it will not receive focus-events. */ safeZone?: { anchor?: Element | null; dismissable?: Element | null; }; style?: CSSProperties; /** * Disables layer from beeing counted in context for nested `DismissableLayer`. */ enabled?: boolean; } type DismissableLayerProps = DismissableLayerBaseProps & AsChild; export declare const DismissableDescendantsProvider: React.Provider<import("../../util/hooks/descendants/descendant").DescendantsManager<HTMLDivElement, { disableOutsidePointerEvents: boolean; forceUpdate: () => void; }>>, useDismissableDescendantsContext: <S extends boolean = true>(strict?: S) => S extends true ? import("../../util/hooks/descendants/descendant").DescendantsManager<HTMLDivElement, { disableOutsidePointerEvents: boolean; forceUpdate: () => void; }> : import("../../util/hooks/descendants/descendant").DescendantsManager<HTMLDivElement, { disableOutsidePointerEvents: boolean; forceUpdate: () => void; }> | undefined, useDismissableDescendants: () => import("../../util/hooks/descendants/descendant").DescendantsManager<HTMLDivElement, { disableOutsidePointerEvents: boolean; forceUpdate: () => void; }>, useDismissableDescendant: (options?: import("../../util/hooks/descendants/descendant").DescendantOptions<{ disableOutsidePointerEvents: boolean; forceUpdate: () => void; }> | undefined) => { descendants: import("../../util/hooks/descendants/descendant").DescendantsManager<HTMLDivElement, { disableOutsidePointerEvents: boolean; forceUpdate: () => void; }>; index: number; enabledIndex: number; register: (instance: HTMLDivElement | null) => void | React.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof React.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]; }; declare const DismissableLayer: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>; export { DismissableLayer, type DismissableLayerProps };