UNPKG

6.71 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { BackdropProps, InternalStandardProps as StandardProps } from '..';
4import Paper, { PaperProps } from '../Paper';
5import Modal, { ModalOwnerState, ModalProps } from '../Modal';
6import { Theme } from '../styles';
7import { TransitionProps } from '../transitions/transition';
8import { PopoverClasses } from './popoverClasses';
9import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';
10
11export interface PopoverSlots {
12 root: React.ElementType;
13 paper: React.ElementType;
14}
15
16export type PopoverSlotsAndSlotProps = CreateSlotsAndSlotProps<
17 PopoverSlots,
18 {
19 root: SlotProps<typeof Modal, {}, ModalOwnerState>;
20 paper: SlotProps<typeof Paper, {}, {}>;
21 }
22>;
23
24export interface PopoverOrigin {
25 vertical: 'top' | 'center' | 'bottom' | number;
26 horizontal: 'left' | 'center' | 'right' | number;
27}
28
29export interface PopoverPosition {
30 top: number;
31 left: number;
32}
33
34export type PopoverReference = 'anchorEl' | 'anchorPosition' | 'none';
35
36interface PopoverVirtualElement {
37 getBoundingClientRect: () => DOMRect;
38 nodeType: Node['ELEMENT_NODE'];
39}
40
41export interface PopoverProps
42 extends StandardProps<
43 Omit<ModalProps, 'slots' | 'slotProps' | 'BackdropProps' | 'BackdropComponent'>,
44 'children'
45 >,
46 PopoverSlotsAndSlotProps {
47 /**
48 * A ref for imperative actions.
49 * It currently only supports updatePosition() action.
50 */
51 action?: React.Ref<PopoverActions>;
52 /**
53 * An HTML element, [PopoverVirtualElement](https://mui.com/material-ui/react-popover/#virtual-element),
54 * or a function that returns either.
55 * It's used to set the position of the popover.
56 */
57 anchorEl?:
58 | null
59 | Element
60 | (() => Element)
61 | PopoverVirtualElement
62 | (() => PopoverVirtualElement);
63 /**
64 * This is the point on the anchor where the popover's
65 * `anchorEl` will attach to. This is not used when the
66 * anchorReference is 'anchorPosition'.
67 *
68 * Options:
69 * vertical: [top, center, bottom];
70 * horizontal: [left, center, right].
71 * @default {
72 * vertical: 'top',
73 * horizontal: 'left',
74 * }
75 */
76 anchorOrigin?: PopoverOrigin;
77 /**
78 * This is the position that may be used to set the position of the popover.
79 * The coordinates are relative to the application's client area.
80 */
81 anchorPosition?: PopoverPosition;
82 /**
83 * This determines which anchor prop to refer to when setting
84 * the position of the popover.
85 * @default 'anchorEl'
86 */
87 anchorReference?: PopoverReference;
88 /**
89 * A backdrop component. This prop enables custom backdrop rendering.
90 * @deprecated Use `slotProps.root.slots.backdrop` instead. While this prop currently works, it will be removed in the next major version.
91 * Use the `slotProps.root.slots.backdrop` prop to make your application ready for the next version of Material UI.
92 * @default styled(Backdrop, {
93 * name: 'MuiModal',
94 * slot: 'Backdrop',
95 * overridesResolver: (props, styles) => {
96 * return styles.backdrop;
97 * },
98 * })({
99 * zIndex: -1,
100 * })
101 */
102 BackdropComponent?: React.ElementType<BackdropProps>;
103 /**
104 * Props applied to the [`Backdrop`](/material-ui/api/backdrop/) element.
105 * @deprecated Use `slotProps.root.slotProps.backdrop` instead.
106 */
107 BackdropProps?: Partial<BackdropProps>;
108 /**
109 * The content of the component.
110 */
111 children?: React.ReactNode;
112 /**
113 * Override or extend the styles applied to the component.
114 */
115 classes?: Partial<PopoverClasses>;
116 /**
117 * An HTML element, component instance, or function that returns either.
118 * The `container` will passed to the Modal component.
119 *
120 * By default, it uses the body of the anchorEl's top-level document object,
121 * so it's simply `document.body` most of the time.
122 */
123 container?: ModalProps['container'];
124 /**
125 * The elevation of the popover.
126 * @default 8
127 */
128 elevation?: number;
129 /**
130 * Specifies how close to the edge of the window the popover can appear.
131 * If null, the popover will not be constrained by the window.
132 * @default 16
133 */
134 marginThreshold?: number | null;
135 onClose?: ModalProps['onClose'];
136 /**
137 * If `true`, the component is shown.
138 */
139 open: boolean;
140 /**
141 * Props applied to the [`Paper`](https://mui.com/material-ui/api/paper/) element.
142 *
143 * This prop is an alias for `slotProps.paper` and will be overriden by it if both are used.
144 * @deprecated Use `slotProps.paper` instead.
145 *
146 * @default {}
147 */
148 PaperProps?: Partial<PaperProps<React.ElementType>>;
149 /**
150 * The system prop that allows defining system overrides as well as additional CSS styles.
151 */
152 sx?: SxProps<Theme>;
153 /**
154 * This is the point on the popover which
155 * will attach to the anchor's origin.
156 *
157 * Options:
158 * vertical: [top, center, bottom, x(px)];
159 * horizontal: [left, center, right, x(px)].
160 * @default {
161 * vertical: 'top',
162 * horizontal: 'left',
163 * }
164 */
165 transformOrigin?: PopoverOrigin;
166 /**
167 * The component used for the transition.
168 * [Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
169 * @default Grow
170 */
171 TransitionComponent?: React.JSXElementConstructor<
172 TransitionProps & { children: React.ReactElement<unknown, any> }
173 >;
174 /**
175 * Set to 'auto' to automatically calculate transition time based on height.
176 * @default 'auto'
177 */
178 transitionDuration?: TransitionProps['timeout'] | 'auto';
179 /**
180 * Props applied to the transition element.
181 * By default, the element is based on this [`Transition`](https://reactcommunity.org/react-transition-group/transition/) component.
182 * @default {}
183 */
184 TransitionProps?: TransitionProps;
185}
186
187export interface PopoverActions {
188 updatePosition(): void;
189}
190
191export function getOffsetTop(rect: DOMRect, vertical: number | 'center' | 'bottom' | 'top'): number;
192
193export function getOffsetLeft(
194 rect: DOMRect,
195 horizontal: number | 'center' | 'right' | 'left',
196): number;
197
198type PopoverRootProps = NonNullable<PopoverProps['slotProps']>['root'];
199type PopoverPaperProps = NonNullable<PopoverProps['slotProps']>['paper'];
200
201export declare const PopoverRoot: React.FC<PopoverRootProps>;
202export declare const PopoverPaper: React.FC<PopoverPaperProps>;
203
204/**
205 *
206 * Demos:
207 *
208 * - [Menu](https://mui.com/material-ui/react-menu/)
209 * - [Popover](https://mui.com/material-ui/react-popover/)
210 *
211 * API:
212 *
213 * - [Popover API](https://mui.com/material-ui/api/popover/)
214 * - inherits [Modal API](https://mui.com/material-ui/api/modal/)
215 */
216export default function Popover(props: PopoverProps): React.JSX.Element;
217
\No newline at end of file