UNPKG

4.86 kBTypeScriptView Raw
1import * as React from 'react';
2import { StandardProps } from '..';
3import { PaperProps } from '../Paper';
4import { ModalProps } from '../Modal';
5import { TransitionHandlerProps, TransitionProps } from '../transitions/transition';
6
7export interface PopoverOrigin {
8 vertical: 'top' | 'center' | 'bottom' | number;
9 horizontal: 'left' | 'center' | 'right' | number;
10}
11
12export interface PopoverPosition {
13 top: number;
14 left: number;
15}
16
17export type PopoverReference = 'anchorEl' | 'anchorPosition' | 'none';
18
19export interface PopoverProps
20 extends StandardProps<ModalProps & Partial<TransitionHandlerProps>, PopoverClassKey, 'children'> {
21 /**
22 * A ref for imperative actions.
23 * It currently only supports updatePosition() action.
24 */
25 action?: React.Ref<PopoverActions>;
26 /**
27 * A HTML element, or a function that returns it.
28 * It's used to set the position of the popover.
29 */
30 anchorEl?: null | Element | ((element: Element) => Element);
31 /**
32 * This is the point on the anchor where the popover's
33 * `anchorEl` will attach to. This is not used when the
34 * anchorReference is 'anchorPosition'.
35 *
36 * Options:
37 * vertical: [top, center, bottom];
38 * horizontal: [left, center, right].
39 */
40 anchorOrigin?: PopoverOrigin;
41 /**
42 * This is the position that may be used
43 * to set the position of the popover.
44 * The coordinates are relative to
45 * the application's client area.
46 */
47 anchorPosition?: PopoverPosition;
48 /**
49 * This determines which anchor prop to refer to to set
50 * the position of the popover.
51 */
52 anchorReference?: PopoverReference;
53 /**
54 * The content of the component.
55 */
56 children?: React.ReactNode;
57 /**
58 * A HTML element, component instance, or function that returns either.
59 * The `container` will passed to the Modal component.
60 *
61 * By default, it uses the body of the anchorEl's top-level document object,
62 * so it's simply `document.body` most of the time.
63 */
64 container?: ModalProps['container'];
65 /**
66 * The elevation of the popover.
67 */
68 elevation?: number;
69 /**
70 * This function is called in order to retrieve the content anchor element.
71 * It's the opposite of the `anchorEl` prop.
72 * The content anchor element should be an element inside the popover.
73 * It's used to correctly scroll and set the position of the popover.
74 * The positioning strategy tries to make the content anchor element just above the
75 * anchor element.
76 */
77 getContentAnchorEl?: null | ((element: Element) => Element);
78 /**
79 * Specifies how close to the edge of the window the popover can appear.
80 */
81 marginThreshold?: number;
82 onClose?: ModalProps['onClose'];
83 /**
84 * Callback fired before the component is entering.
85 */
86 onEnter?: TransitionHandlerProps['onEnter'];
87 /**
88 * Callback fired when the component has entered.
89 */
90 onEntered?: TransitionHandlerProps['onEntered'];
91 /**
92 * Callback fired when the component is entering.
93 */
94 onEntering?: TransitionHandlerProps['onEntering'];
95 /**
96 * Callback fired before the component is exiting.
97 */
98 onExit?: TransitionHandlerProps['onExit'];
99 /**
100 * Callback fired when the component has exited.
101 */
102 onExited?: TransitionHandlerProps['onExited'];
103 /**
104 * Callback fired when the component is exiting.
105 */
106 onExiting?: TransitionHandlerProps['onExiting'];
107 /**
108 * If `true`, the popover is visible.
109 */
110 open: boolean;
111 /**
112 * Props applied to the [`Paper`](/api/paper/) element.
113 */
114 PaperProps?: Partial<PaperProps>;
115 /**
116 * This is the point on the popover which
117 * will attach to the anchor's origin.
118 *
119 * Options:
120 * vertical: [top, center, bottom, x(px)];
121 * horizontal: [left, center, right, x(px)].
122 */
123 transformOrigin?: PopoverOrigin;
124 /**
125 * The component used for the transition.
126 * [Follow this guide](/components/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
127 */
128 TransitionComponent?: React.ComponentType<
129 TransitionProps & { children?: React.ReactElement<any, any> }
130 >;
131 /**
132 * Set to 'auto' to automatically calculate transition time based on height.
133 */
134 transitionDuration?: TransitionProps['timeout'] | 'auto';
135 /**
136 * Props applied to the [`Transition`](http://reactcommunity.org/react-transition-group/transition#Transition-props) element.
137 */
138 TransitionProps?: TransitionProps;
139}
140
141export type PopoverClassKey = 'root' | 'paper';
142
143export interface PopoverActions {
144 updatePosition(): void;
145}
146
147/**
148 *
149 * Demos:
150 *
151 * - [Menus](https://material-ui.com/components/menus/)
152 * - [Popover](https://material-ui.com/components/popover/)
153 *
154 * API:
155 *
156 * - [Popover API](https://material-ui.com/api/popover/)
157 * - inherits [Modal API](https://material-ui.com/api/modal/)
158 */
159export default function Popover(props: PopoverProps): JSX.Element;
160
\No newline at end of file