UNPKG

4.16 kBTypeScriptView Raw
1/// <reference types="react" />
2import { Middleware as PopupMiddleware, OffsetOptions as PopupOffsetOptions, Placement as PopupPlacement, Strategy as PopupStrategy, VirtualElement as PopupVirtualElement } from '@floating-ui/react-dom';
3import { PortalProps } from '../Portal';
4import { PolymorphicProps, SlotComponentProps } from '../utils';
5export type { PopupPlacement, PopupStrategy, PopupOffsetOptions, PopupMiddleware, PopupVirtualElement, };
6export interface PopupRootSlotPropsOverrides {
7}
8export interface PopupOwnProps {
9 /**
10 * An HTML element, [virtual element](https://floating-ui.com/docs/virtual-elements),
11 * or a function that returns either.
12 * It's used to set the position of the popup.
13 */
14 anchor?: PopupVirtualElement | HTMLElement | (() => HTMLElement) | (() => PopupVirtualElement) | null;
15 children?: React.ReactNode;
16 /**
17 * An HTML element or function that returns one. The container will have the portal children appended to it.
18 By default, it uses the body of the top-level document object, so it's `document.body` in these cases.
19 */
20 container?: PortalProps['container'];
21 /**
22 * If `true`, the popup will be rendered where it is defined, without the use of portals.
23 * @default false
24 */
25 disablePortal?: boolean;
26 /**
27 * If `true`, the popup will exist in the DOM even if it's closed.
28 * Its visibility will be controlled by the `visibility` CSS property.
29 *
30 * Otherwise, a closed popup will be removed from the DOM.
31 *
32 * @default false
33 */
34 keepMounted?: boolean;
35 /**
36 * Collection of Floating UI middleware to use when positioning the popup.
37 * If not provided, the [`offset`](https://floating-ui.com/docs/offset)
38 * and [`flip`](https://floating-ui.com/docs/flip) functions will be used.
39 *
40 * @see https://floating-ui.com/docs/computePosition#middleware
41 */
42 middleware?: Array<PopupMiddleware | null | undefined | false>;
43 /**
44 * Distance between a popup and the trigger element.
45 * This prop is ignored when custom `middleware` is provided.
46 *
47 * @default 0
48 * @see https://floating-ui.com/docs/offset
49 */
50 offset?: PopupOffsetOptions;
51 /**
52 * If `true`, the popup is visible.
53 *
54 * @default false
55 */
56 open?: boolean;
57 /**
58 * Determines where to place the popup relative to the trigger element.
59 *
60 * @default 'bottom'
61 * @see https://floating-ui.com/docs/computePosition#placement
62 */
63 placement?: PopupPlacement;
64 /**
65 * The components used for each slot inside the Popup.
66 * Either a string to use a HTML element or a component.
67 *
68 * @default {}
69 */
70 slots?: {
71 root?: React.ElementType;
72 };
73 /**
74 * The props used for each slot inside the Popup.
75 *
76 * @default {}
77 */
78 slotProps?: {
79 root?: SlotComponentProps<'div', PopupRootSlotPropsOverrides, PopupProps>;
80 };
81 /**
82 * The type of CSS position property to use (absolute or fixed).
83 *
84 * @default 'absolute'
85 * @see https://floating-ui.com/docs/computePosition#strategy
86 */
87 strategy?: PopupStrategy;
88}
89export interface PopupSlots {
90 /**
91 * The component that renders the root.
92 * @default 'div'
93 */
94 root?: React.ElementType;
95}
96export interface PopupTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
97 props: PopupOwnProps & AdditionalProps;
98 defaultComponent: RootComponentType;
99}
100export type PopupProps<RootComponentType extends React.ElementType = PopupTypeMap['defaultComponent']> = PolymorphicProps<PopupTypeMap<{}, RootComponentType>, RootComponentType>;
101export interface PopupOwnerState extends PopupOwnProps {
102 disablePortal: boolean;
103 open: boolean;
104 keepMounted: boolean;
105 offset: PopupOffsetOptions;
106 placement: PopupPlacement;
107 finalPlacement: PopupPlacement;
108 strategy: PopupStrategy;
109}
110export type PopupRootSlotProps = {
111 className?: string;
112 children?: React.ReactNode;
113 ownerState: PopupOwnerState;
114 style: React.CSSProperties;
115 role: React.AriaRole;
116};
117
\No newline at end of file