@fluentui/react-popover 0.0.0-nightly-20220302-0405.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +2819 -0
- package/CHANGELOG.md +854 -0
- package/LICENSE +15 -0
- package/README.md +25 -0
- package/Spec.md +496 -0
- package/dist/react-popover.d.ts +242 -0
- package/lib/Popover.d.ts +1 -0
- package/lib/Popover.js +2 -0
- package/lib/Popover.js.map +1 -0
- package/lib/PopoverSurface.d.ts +1 -0
- package/lib/PopoverSurface.js +2 -0
- package/lib/PopoverSurface.js.map +1 -0
- package/lib/PopoverTrigger.d.ts +1 -0
- package/lib/PopoverTrigger.js +2 -0
- package/lib/PopoverTrigger.js.map +1 -0
- package/lib/components/Popover/Popover.d.ts +6 -0
- package/lib/components/Popover/Popover.js +12 -0
- package/lib/components/Popover/Popover.js.map +1 -0
- package/lib/components/Popover/Popover.types.d.ts +103 -0
- package/lib/components/Popover/Popover.types.js +2 -0
- package/lib/components/Popover/Popover.types.js.map +1 -0
- package/lib/components/Popover/index.d.ts +4 -0
- package/lib/components/Popover/index.js +5 -0
- package/lib/components/Popover/index.js.map +1 -0
- package/lib/components/Popover/renderPopover.d.ts +5 -0
- package/lib/components/Popover/renderPopover.js +39 -0
- package/lib/components/Popover/renderPopover.js.map +1 -0
- package/lib/components/Popover/usePopover.d.ts +10 -0
- package/lib/components/Popover/usePopover.js +124 -0
- package/lib/components/Popover/usePopover.js.map +1 -0
- package/lib/components/PopoverSurface/PopoverSurface.d.ts +6 -0
- package/lib/components/PopoverSurface/PopoverSurface.js +15 -0
- package/lib/components/PopoverSurface/PopoverSurface.js.map +1 -0
- package/lib/components/PopoverSurface/PopoverSurface.types.d.ts +21 -0
- package/lib/components/PopoverSurface/PopoverSurface.types.js +2 -0
- package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -0
- package/lib/components/PopoverSurface/index.d.ts +5 -0
- package/lib/components/PopoverSurface/index.js +6 -0
- package/lib/components/PopoverSurface/index.js.map +1 -0
- package/lib/components/PopoverSurface/renderPopoverSurface.d.ts +5 -0
- package/lib/components/PopoverSurface/renderPopoverSurface.js +26 -0
- package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -0
- package/lib/components/PopoverSurface/usePopoverSurface.d.ts +12 -0
- package/lib/components/PopoverSurface/usePopoverSurface.js +94 -0
- package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -0
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +8 -0
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +112 -0
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -0
- package/lib/components/PopoverTrigger/PopoverTrigger.d.ts +7 -0
- package/lib/components/PopoverTrigger/PopoverTrigger.js +13 -0
- package/lib/components/PopoverTrigger/PopoverTrigger.js.map +1 -0
- package/lib/components/PopoverTrigger/PopoverTrigger.types.d.ts +18 -0
- package/lib/components/PopoverTrigger/PopoverTrigger.types.js +2 -0
- package/lib/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -0
- package/lib/components/PopoverTrigger/index.d.ts +4 -0
- package/lib/components/PopoverTrigger/index.js +5 -0
- package/lib/components/PopoverTrigger/index.js.map +1 -0
- package/lib/components/PopoverTrigger/renderPopoverTrigger.d.ts +5 -0
- package/lib/components/PopoverTrigger/renderPopoverTrigger.js +7 -0
- package/lib/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -0
- package/lib/components/PopoverTrigger/usePopoverTrigger.d.ts +10 -0
- package/lib/components/PopoverTrigger/usePopoverTrigger.js +82 -0
- package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/popoverContext.d.ts +8 -0
- package/lib/popoverContext.js +20 -0
- package/lib/popoverContext.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib-commonjs/Popover.d.ts +1 -0
- package/lib-commonjs/Popover.js +10 -0
- package/lib-commonjs/Popover.js.map +1 -0
- package/lib-commonjs/PopoverSurface.d.ts +1 -0
- package/lib-commonjs/PopoverSurface.js +10 -0
- package/lib-commonjs/PopoverSurface.js.map +1 -0
- package/lib-commonjs/PopoverTrigger.d.ts +1 -0
- package/lib-commonjs/PopoverTrigger.js +10 -0
- package/lib-commonjs/PopoverTrigger.js.map +1 -0
- package/lib-commonjs/components/Popover/Popover.d.ts +6 -0
- package/lib-commonjs/components/Popover/Popover.js +23 -0
- package/lib-commonjs/components/Popover/Popover.js.map +1 -0
- package/lib-commonjs/components/Popover/Popover.types.d.ts +103 -0
- package/lib-commonjs/components/Popover/Popover.types.js +6 -0
- package/lib-commonjs/components/Popover/Popover.types.js.map +1 -0
- package/lib-commonjs/components/Popover/index.d.ts +4 -0
- package/lib-commonjs/components/Popover/index.js +16 -0
- package/lib-commonjs/components/Popover/index.js.map +1 -0
- package/lib-commonjs/components/Popover/renderPopover.d.ts +5 -0
- package/lib-commonjs/components/Popover/renderPopover.js +50 -0
- package/lib-commonjs/components/Popover/renderPopover.js.map +1 -0
- package/lib-commonjs/components/Popover/usePopover.d.ts +10 -0
- package/lib-commonjs/components/Popover/usePopover.js +139 -0
- package/lib-commonjs/components/Popover/usePopover.js.map +1 -0
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.d.ts +6 -0
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.js +26 -0
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.js.map +1 -0
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.d.ts +21 -0
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.js +6 -0
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.js.map +1 -0
- package/lib-commonjs/components/PopoverSurface/index.d.ts +5 -0
- package/lib-commonjs/components/PopoverSurface/index.js +18 -0
- package/lib-commonjs/components/PopoverSurface/index.js.map +1 -0
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.d.ts +5 -0
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +38 -0
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -0
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.d.ts +12 -0
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +107 -0
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -0
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +8 -0
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +124 -0
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -0
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.d.ts +7 -0
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js +24 -0
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js.map +1 -0
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.d.ts +18 -0
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.js +6 -0
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -0
- package/lib-commonjs/components/PopoverTrigger/index.d.ts +4 -0
- package/lib-commonjs/components/PopoverTrigger/index.js +16 -0
- package/lib-commonjs/components/PopoverTrigger/index.js.map +1 -0
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.d.ts +5 -0
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js +16 -0
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -0
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.d.ts +10 -0
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +95 -0
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -0
- package/lib-commonjs/index.d.ts +4 -0
- package/lib-commonjs/index.js +16 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/popoverContext.d.ts +8 -0
- package/lib-commonjs/popoverContext.js +31 -0
- package/lib-commonjs/popoverContext.js.map +1 -0
- package/package.json +69 -0
@@ -0,0 +1,242 @@
|
|
1
|
+
import type { ComponentProps } from '@fluentui/react-utilities';
|
2
|
+
import type { ComponentState } from '@fluentui/react-utilities';
|
3
|
+
import type { Context } from '@fluentui/react-context-selector';
|
4
|
+
import type { ContextSelector } from '@fluentui/react-context-selector';
|
5
|
+
import type { FluentTriggerComponent } from '@fluentui/react-utilities';
|
6
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
7
|
+
import { JSXElementConstructor } from 'react';
|
8
|
+
import type { PopperVirtualElement } from '@fluentui/react-positioning';
|
9
|
+
import type { PortalProps } from '@fluentui/react-portal';
|
10
|
+
import type { PositioningShorthand } from '@fluentui/react-positioning';
|
11
|
+
import * as React_2 from 'react';
|
12
|
+
import { ReactElement } from 'react';
|
13
|
+
import type { Slot } from '@fluentui/react-utilities';
|
14
|
+
import type { usePopperMouseTarget } from '@fluentui/react-positioning';
|
15
|
+
|
16
|
+
export declare const arrowHeights: Record<PopoverSize, number>;
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Data attached to open/close events
|
20
|
+
*/
|
21
|
+
export declare type OnOpenChangeData = {
|
22
|
+
open: boolean;
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* The supported events that will trigger open/close of the menu
|
27
|
+
*/
|
28
|
+
export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React_2.MouseEvent<HTMLElement> | React_2.KeyboardEvent<HTMLElement> | React_2.FocusEvent<HTMLElement>;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.
|
32
|
+
*/
|
33
|
+
export declare const Popover: React_2.FC<PopoverProps>;
|
34
|
+
|
35
|
+
declare type PopoverCommons = Pick<PortalProps, 'mountNode'> & {
|
36
|
+
/**
|
37
|
+
* Controls the opening of the Popover
|
38
|
+
*/
|
39
|
+
open: boolean;
|
40
|
+
/**
|
41
|
+
* Used to set the initial open state of the Popover in uncontrolled mode
|
42
|
+
*/
|
43
|
+
defaultOpen?: boolean;
|
44
|
+
/**
|
45
|
+
* Call back when the component requests to change value
|
46
|
+
* The `open` value is used as a hint when directly controlling the component
|
47
|
+
*/
|
48
|
+
onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;
|
49
|
+
/**
|
50
|
+
* Flag to open the Popover by hovering the trigger
|
51
|
+
*/
|
52
|
+
openOnHover?: boolean;
|
53
|
+
/**
|
54
|
+
* Flag to open the Popover as a context menu. Disables all other interactions
|
55
|
+
*/
|
56
|
+
openOnContext?: boolean;
|
57
|
+
/**
|
58
|
+
* Do not display the arrow
|
59
|
+
*/
|
60
|
+
noArrow?: boolean;
|
61
|
+
/**
|
62
|
+
* Determines popover padding and arrow size
|
63
|
+
* @default medium
|
64
|
+
*/
|
65
|
+
size?: PopoverSize;
|
66
|
+
/**
|
67
|
+
* A popover can appear styled with brand or inverted.
|
68
|
+
* When not specified, the default style is used.
|
69
|
+
*/
|
70
|
+
appearance?: 'brand' | 'inverted';
|
71
|
+
/**
|
72
|
+
* Should trap focus
|
73
|
+
*/
|
74
|
+
trapFocus?: boolean;
|
75
|
+
/**
|
76
|
+
* Configures the position of the Popover
|
77
|
+
*/
|
78
|
+
positioning?: PositioningShorthand;
|
79
|
+
};
|
80
|
+
|
81
|
+
export declare const PopoverContext: Context<PopoverContextValue>;
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Context shared between Popover and its children components
|
85
|
+
*/
|
86
|
+
export declare type PopoverContextValue = Pick<PopoverState, 'open' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'noArrow' | 'arrowRef' | 'size' | 'appearance' | 'trapFocus'>;
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Popover Props
|
90
|
+
*/
|
91
|
+
export declare type PopoverProps = Partial<PopoverCommons> & {
|
92
|
+
/**
|
93
|
+
* Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.
|
94
|
+
* Alternatively can only contain {@link PopoverSurface} if using a custom `target`.
|
95
|
+
*/
|
96
|
+
children: [JSX.Element, JSX.Element] | JSX.Element;
|
97
|
+
};
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Determines popover padding and arrow size
|
101
|
+
*/
|
102
|
+
export declare type PopoverSize = 'small' | 'medium' | 'large';
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Popover State
|
106
|
+
*/
|
107
|
+
export declare type PopoverState = PopoverCommons & Pick<PopoverProps, 'children'> & {
|
108
|
+
/**
|
109
|
+
* Callback to open/close the Popover
|
110
|
+
*/
|
111
|
+
setOpen: (e: OpenPopoverEvents, open: boolean) => void;
|
112
|
+
/**
|
113
|
+
* Ref of the PopoverTrigger
|
114
|
+
*/
|
115
|
+
triggerRef: React_2.MutableRefObject<HTMLElement | null>;
|
116
|
+
/**
|
117
|
+
* Ref of the PopoverSurface
|
118
|
+
*/
|
119
|
+
contentRef: React_2.MutableRefObject<HTMLElement | null>;
|
120
|
+
/**
|
121
|
+
* Ref of the pointing arrow
|
122
|
+
*/
|
123
|
+
arrowRef: React_2.MutableRefObject<HTMLDivElement | null>;
|
124
|
+
/**
|
125
|
+
* Anchors the popper to the mouse click for context events
|
126
|
+
*/
|
127
|
+
contextTarget: PopperVirtualElement | undefined;
|
128
|
+
/**
|
129
|
+
* A callback to set the target of the popper to the mouse click for context events
|
130
|
+
*/
|
131
|
+
setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];
|
132
|
+
size: NonNullable<PopoverProps['size']>;
|
133
|
+
};
|
134
|
+
|
135
|
+
/**
|
136
|
+
* PopoverSurface component renders react children in a positioned box
|
137
|
+
*/
|
138
|
+
export declare const PopoverSurface: ForwardRefComponent<PopoverSurfaceProps>;
|
139
|
+
|
140
|
+
export declare const popoverSurfaceClassName = "fui-PopoverSurface";
|
141
|
+
|
142
|
+
/**
|
143
|
+
* PopoverSurface Props
|
144
|
+
*/
|
145
|
+
export declare type PopoverSurfaceProps = ComponentProps<PopoverSurfaceSlots>;
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Names of the slots in PopoverSurfaceProps
|
149
|
+
*/
|
150
|
+
export declare type PopoverSurfaceSlots = {
|
151
|
+
root: Slot<'div'>;
|
152
|
+
};
|
153
|
+
|
154
|
+
/**
|
155
|
+
* PopoverSurface State
|
156
|
+
*/
|
157
|
+
export declare type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> & Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'appearance' | 'arrowRef'> & {
|
158
|
+
/**
|
159
|
+
* CSS class for the arrow element
|
160
|
+
*/
|
161
|
+
arrowClassName?: string;
|
162
|
+
};
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Wraps a trigger element as an only child and adds the necessary event handling to open a popover.
|
166
|
+
*/
|
167
|
+
export declare const PopoverTrigger: React_2.FC<PopoverTriggerProps> & FluentTriggerComponent;
|
168
|
+
|
169
|
+
export declare type PopoverTriggerChildProps = {
|
170
|
+
ref?: React_2.Ref<never>;
|
171
|
+
} & Pick<React_2.HTMLAttributes<HTMLElement>, 'aria-haspopup' | 'onClick' | 'onMouseEnter' | 'onKeyDown' | 'onMouseLeave' | 'onContextMenu'>;
|
172
|
+
|
173
|
+
/**
|
174
|
+
* PopoverTrigger Props
|
175
|
+
*/
|
176
|
+
export declare type PopoverTriggerProps = {
|
177
|
+
children: (React_2.ReactElement & {
|
178
|
+
ref?: React_2.Ref<unknown>;
|
179
|
+
}) | ((props: PopoverTriggerChildProps) => React_2.ReactElement | null);
|
180
|
+
};
|
181
|
+
|
182
|
+
/**
|
183
|
+
* PopoverTrigger State
|
184
|
+
*/
|
185
|
+
export declare type PopoverTriggerState = {
|
186
|
+
children: React_2.ReactElement | null;
|
187
|
+
};
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Render the final JSX of Popover
|
191
|
+
*/
|
192
|
+
export declare const renderPopover_unstable: (state: PopoverState) => JSX.Element;
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Render the final JSX of PopoverSurface
|
196
|
+
*/
|
197
|
+
export declare const renderPopoverSurface_unstable: (state: PopoverSurfaceState) => JSX.Element | null;
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Render the final JSX of PopoverTrigger
|
201
|
+
*/
|
202
|
+
export declare const renderPopoverTrigger_unstable: (state: PopoverTriggerState) => ReactElement<any, string | JSXElementConstructor<any>> | null;
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Create the state required to render Popover.
|
206
|
+
*
|
207
|
+
* The returned state can be modified with hooks such as usePopoverStyles,
|
208
|
+
* before being passed to renderPopover_unstable.
|
209
|
+
*
|
210
|
+
* @param props - props from this instance of Popover
|
211
|
+
*/
|
212
|
+
export declare const usePopover_unstable: (props: PopoverProps) => PopoverState;
|
213
|
+
|
214
|
+
export declare const usePopoverContext_unstable: <T>(selector: ContextSelector<PopoverContextValue, T>) => T;
|
215
|
+
|
216
|
+
/**
|
217
|
+
* Create the state required to render PopoverSurface.
|
218
|
+
*
|
219
|
+
* The returned state can be modified with hooks such as usePopoverSurfaceStyles_unstable,
|
220
|
+
* before being passed to renderPopoverSurface_unstable.
|
221
|
+
*
|
222
|
+
* @param props - props from this instance of PopoverSurface
|
223
|
+
* @param ref - reference to root HTMLDivElement of PopoverSurface
|
224
|
+
*/
|
225
|
+
export declare const usePopoverSurface_unstable: (props: PopoverSurfaceProps, ref: React_2.Ref<HTMLDivElement>) => PopoverSurfaceState;
|
226
|
+
|
227
|
+
/**
|
228
|
+
* Apply styling to the PopoverSurface slots based on the state
|
229
|
+
*/
|
230
|
+
export declare const usePopoverSurfaceStyles_unstable: (state: PopoverSurfaceState) => PopoverSurfaceState;
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Create the state required to render PopoverTrigger.
|
234
|
+
*
|
235
|
+
* The returned state can be modified with hooks such as usePopoverTriggerStyles,
|
236
|
+
* before being passed to renderPopoverTrigger_unstable.
|
237
|
+
*
|
238
|
+
* @param props - props from this instance of PopoverTrigger
|
239
|
+
*/
|
240
|
+
export declare const usePopoverTrigger_unstable: (props: PopoverTriggerProps) => PopoverTriggerState;
|
241
|
+
|
242
|
+
export { }
|
package/lib/Popover.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './components/Popover/index';
|
package/lib/Popover.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Popover.js","sourceRoot":"../src/","sources":["Popover.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from './components/Popover/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './components/PopoverSurface/index';
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PopoverSurface.js","sourceRoot":"../src/","sources":["PopoverSurface.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC","sourcesContent":["export * from './components/PopoverSurface/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './components/PopoverTrigger/index';
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PopoverTrigger.js","sourceRoot":"../src/","sources":["PopoverTrigger.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC","sourcesContent":["export * from './components/PopoverTrigger/index';\n"]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { usePopover_unstable } from './usePopover';
|
2
|
+
import { renderPopover_unstable } from './renderPopover';
|
3
|
+
/**
|
4
|
+
* Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.
|
5
|
+
*/
|
6
|
+
|
7
|
+
export const Popover = props => {
|
8
|
+
const state = usePopover_unstable(props);
|
9
|
+
return renderPopover_unstable(state);
|
10
|
+
};
|
11
|
+
Popover.displayName = 'Popover';
|
12
|
+
//# sourceMappingURL=Popover.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Popover/Popover.tsx"],"names":[],"mappings":"AACA,SAAS,mBAAT,QAAoC,cAApC;AACA,SAAS,sBAAT,QAAuC,iBAAvC;AAGA;;AAEG;;AACH,OAAO,MAAM,OAAO,GAA2B,KAAK,IAAG;AACrD,QAAM,KAAK,GAAG,mBAAmB,CAAC,KAAD,CAAjC;AAEA,SAAO,sBAAsB,CAAC,KAAD,CAA7B;AACD,CAJM;AAMP,OAAO,CAAC,WAAR,GAAsB,SAAtB","sourcesContent":["import * as React from 'react';\nimport { usePopover_unstable } from './usePopover';\nimport { renderPopover_unstable } from './renderPopover';\nimport type { PopoverProps } from './Popover.types';\n\n/**\n * Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.\n */\nexport const Popover: React.FC<PopoverProps> = props => {\n const state = usePopover_unstable(props);\n\n return renderPopover_unstable(state);\n};\n\nPopover.displayName = 'Popover';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import type { PopperVirtualElement, PositioningShorthand, usePopperMouseTarget } from '@fluentui/react-positioning';
|
3
|
+
import type { PortalProps } from '@fluentui/react-portal';
|
4
|
+
/**
|
5
|
+
* Determines popover padding and arrow size
|
6
|
+
*/
|
7
|
+
export declare type PopoverSize = 'small' | 'medium' | 'large';
|
8
|
+
declare type PopoverCommons = Pick<PortalProps, 'mountNode'> & {
|
9
|
+
/**
|
10
|
+
* Controls the opening of the Popover
|
11
|
+
*/
|
12
|
+
open: boolean;
|
13
|
+
/**
|
14
|
+
* Used to set the initial open state of the Popover in uncontrolled mode
|
15
|
+
*/
|
16
|
+
defaultOpen?: boolean;
|
17
|
+
/**
|
18
|
+
* Call back when the component requests to change value
|
19
|
+
* The `open` value is used as a hint when directly controlling the component
|
20
|
+
*/
|
21
|
+
onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;
|
22
|
+
/**
|
23
|
+
* Flag to open the Popover by hovering the trigger
|
24
|
+
*/
|
25
|
+
openOnHover?: boolean;
|
26
|
+
/**
|
27
|
+
* Flag to open the Popover as a context menu. Disables all other interactions
|
28
|
+
*/
|
29
|
+
openOnContext?: boolean;
|
30
|
+
/**
|
31
|
+
* Do not display the arrow
|
32
|
+
*/
|
33
|
+
noArrow?: boolean;
|
34
|
+
/**
|
35
|
+
* Determines popover padding and arrow size
|
36
|
+
* @default medium
|
37
|
+
*/
|
38
|
+
size?: PopoverSize;
|
39
|
+
/**
|
40
|
+
* A popover can appear styled with brand or inverted.
|
41
|
+
* When not specified, the default style is used.
|
42
|
+
*/
|
43
|
+
appearance?: 'brand' | 'inverted';
|
44
|
+
/**
|
45
|
+
* Should trap focus
|
46
|
+
*/
|
47
|
+
trapFocus?: boolean;
|
48
|
+
/**
|
49
|
+
* Configures the position of the Popover
|
50
|
+
*/
|
51
|
+
positioning?: PositioningShorthand;
|
52
|
+
};
|
53
|
+
/**
|
54
|
+
* Popover Props
|
55
|
+
*/
|
56
|
+
export declare type PopoverProps = Partial<PopoverCommons> & {
|
57
|
+
/**
|
58
|
+
* Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.
|
59
|
+
* Alternatively can only contain {@link PopoverSurface} if using a custom `target`.
|
60
|
+
*/
|
61
|
+
children: [JSX.Element, JSX.Element] | JSX.Element;
|
62
|
+
};
|
63
|
+
/**
|
64
|
+
* Popover State
|
65
|
+
*/
|
66
|
+
export declare type PopoverState = PopoverCommons & Pick<PopoverProps, 'children'> & {
|
67
|
+
/**
|
68
|
+
* Callback to open/close the Popover
|
69
|
+
*/
|
70
|
+
setOpen: (e: OpenPopoverEvents, open: boolean) => void;
|
71
|
+
/**
|
72
|
+
* Ref of the PopoverTrigger
|
73
|
+
*/
|
74
|
+
triggerRef: React.MutableRefObject<HTMLElement | null>;
|
75
|
+
/**
|
76
|
+
* Ref of the PopoverSurface
|
77
|
+
*/
|
78
|
+
contentRef: React.MutableRefObject<HTMLElement | null>;
|
79
|
+
/**
|
80
|
+
* Ref of the pointing arrow
|
81
|
+
*/
|
82
|
+
arrowRef: React.MutableRefObject<HTMLDivElement | null>;
|
83
|
+
/**
|
84
|
+
* Anchors the popper to the mouse click for context events
|
85
|
+
*/
|
86
|
+
contextTarget: PopperVirtualElement | undefined;
|
87
|
+
/**
|
88
|
+
* A callback to set the target of the popper to the mouse click for context events
|
89
|
+
*/
|
90
|
+
setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];
|
91
|
+
size: NonNullable<PopoverProps['size']>;
|
92
|
+
};
|
93
|
+
/**
|
94
|
+
* Data attached to open/close events
|
95
|
+
*/
|
96
|
+
export declare type OnOpenChangeData = {
|
97
|
+
open: boolean;
|
98
|
+
};
|
99
|
+
/**
|
100
|
+
* The supported events that will trigger open/close of the menu
|
101
|
+
*/
|
102
|
+
export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement> | React.FocusEvent<HTMLElement>;
|
103
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Popover.types.js","sourceRoot":"../src/","sources":["components/Popover/Popover.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PopperVirtualElement, PositioningShorthand, usePopperMouseTarget } from '@fluentui/react-positioning';\nimport type { PortalProps } from '@fluentui/react-portal';\n\n/**\n * Determines popover padding and arrow size\n */\nexport type PopoverSize = 'small' | 'medium' | 'large';\n\ntype PopoverCommons = Pick<PortalProps, 'mountNode'> & {\n /**\n * Controls the opening of the Popover\n */\n open: boolean;\n /**\n * Used to set the initial open state of the Popover in uncontrolled mode\n */\n defaultOpen?: boolean;\n /**\n * Call back when the component requests to change value\n * The `open` value is used as a hint when directly controlling the component\n */\n onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;\n /**\n * Flag to open the Popover by hovering the trigger\n */\n openOnHover?: boolean;\n /**\n * Flag to open the Popover as a context menu. Disables all other interactions\n */\n openOnContext?: boolean;\n /**\n * Do not display the arrow\n */\n noArrow?: boolean;\n /**\n * Determines popover padding and arrow size\n * @default medium\n */\n size?: PopoverSize;\n\n /**\n * A popover can appear styled with brand or inverted.\n * When not specified, the default style is used.\n */\n appearance?: 'brand' | 'inverted';\n\n /**\n * Should trap focus\n */\n trapFocus?: boolean;\n\n /**\n * Configures the position of the Popover\n */\n positioning?: PositioningShorthand;\n};\n\n/**\n * Popover Props\n */\nexport type PopoverProps = Partial<PopoverCommons> & {\n /**\n * Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.\n * Alternatively can only contain {@link PopoverSurface} if using a custom `target`.\n */\n children: [JSX.Element, JSX.Element] | JSX.Element;\n};\n\n/**\n * Popover State\n */\nexport type PopoverState = PopoverCommons &\n Pick<PopoverProps, 'children'> & {\n /**\n * Callback to open/close the Popover\n */\n setOpen: (e: OpenPopoverEvents, open: boolean) => void;\n /**\n * Ref of the PopoverTrigger\n */\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n /**\n * Ref of the PopoverSurface\n */\n contentRef: React.MutableRefObject<HTMLElement | null>;\n /**\n * Ref of the pointing arrow\n */\n arrowRef: React.MutableRefObject<HTMLDivElement | null>;\n /**\n * Anchors the popper to the mouse click for context events\n */\n contextTarget: PopperVirtualElement | undefined;\n /**\n * A callback to set the target of the popper to the mouse click for context events\n */\n setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];\n\n size: NonNullable<PopoverProps['size']>;\n };\n\n/**\n * Data attached to open/close events\n */\nexport type OnOpenChangeData = { open: boolean };\n\n/**\n * The supported events that will trigger open/close of the menu\n */\nexport type OpenPopoverEvents =\n | MouseEvent\n | TouchEvent\n | React.MouseEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.FocusEvent<HTMLElement>;\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Popover/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC","sourcesContent":["export * from './Popover';\nexport * from './Popover.types';\nexport * from './renderPopover';\nexport * from './usePopover';\n"]}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { PopoverContext } from '../../popoverContext';
|
3
|
+
/**
|
4
|
+
* Render the final JSX of Popover
|
5
|
+
*/
|
6
|
+
|
7
|
+
export const renderPopover_unstable = state => {
|
8
|
+
const {
|
9
|
+
open,
|
10
|
+
setOpen,
|
11
|
+
triggerRef,
|
12
|
+
contentRef,
|
13
|
+
openOnContext,
|
14
|
+
openOnHover,
|
15
|
+
mountNode,
|
16
|
+
arrowRef,
|
17
|
+
size,
|
18
|
+
noArrow,
|
19
|
+
appearance,
|
20
|
+
trapFocus
|
21
|
+
} = state;
|
22
|
+
return /*#__PURE__*/React.createElement(PopoverContext.Provider, {
|
23
|
+
value: {
|
24
|
+
open,
|
25
|
+
setOpen,
|
26
|
+
triggerRef,
|
27
|
+
contentRef,
|
28
|
+
openOnHover,
|
29
|
+
openOnContext,
|
30
|
+
mountNode,
|
31
|
+
arrowRef,
|
32
|
+
size,
|
33
|
+
noArrow,
|
34
|
+
appearance,
|
35
|
+
trapFocus
|
36
|
+
}
|
37
|
+
}, state.children);
|
38
|
+
};
|
39
|
+
//# sourceMappingURL=renderPopover.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Popover/renderPopover.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,cAAT,QAA+B,sBAA/B;AAGA;;AAEG;;AACH,OAAO,MAAM,sBAAsB,GAAI,KAAD,IAAwB;AAC5D,QAAM;AACJ,IAAA,IADI;AAEJ,IAAA,OAFI;AAGJ,IAAA,UAHI;AAIJ,IAAA,UAJI;AAKJ,IAAA,aALI;AAMJ,IAAA,WANI;AAOJ,IAAA,SAPI;AAQJ,IAAA,QARI;AASJ,IAAA,IATI;AAUJ,IAAA,OAVI;AAWJ,IAAA,UAXI;AAYJ,IAAA;AAZI,MAaF,KAbJ;AAeA,sBACE,KAAA,CAAA,aAAA,CAAC,cAAc,CAAC,QAAhB,EAAwB;AACtB,IAAA,KAAK,EAAE;AACL,MAAA,IADK;AAEL,MAAA,OAFK;AAGL,MAAA,UAHK;AAIL,MAAA,UAJK;AAKL,MAAA,WALK;AAML,MAAA,aANK;AAOL,MAAA,SAPK;AAQL,MAAA,QARK;AASL,MAAA,IATK;AAUL,MAAA,OAVK;AAWL,MAAA,UAXK;AAYL,MAAA;AAZK;AADe,GAAxB,EAgBG,KAAK,CAAC,QAhBT,CADF;AAoBD,CApCM","sourcesContent":["import * as React from 'react';\nimport { PopoverContext } from '../../popoverContext';\nimport type { PopoverState } from './Popover.types';\n\n/**\n * Render the final JSX of Popover\n */\nexport const renderPopover_unstable = (state: PopoverState) => {\n const {\n open,\n setOpen,\n triggerRef,\n contentRef,\n openOnContext,\n openOnHover,\n mountNode,\n arrowRef,\n size,\n noArrow,\n appearance,\n trapFocus,\n } = state;\n\n return (\n <PopoverContext.Provider\n value={{\n open,\n setOpen,\n triggerRef,\n contentRef,\n openOnHover,\n openOnContext,\n mountNode,\n arrowRef,\n size,\n noArrow,\n appearance,\n trapFocus,\n }}\n >\n {state.children}\n </PopoverContext.Provider>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { PopoverProps, PopoverState } from './Popover.types';
|
2
|
+
/**
|
3
|
+
* Create the state required to render Popover.
|
4
|
+
*
|
5
|
+
* The returned state can be modified with hooks such as usePopoverStyles,
|
6
|
+
* before being passed to renderPopover_unstable.
|
7
|
+
*
|
8
|
+
* @param props - props from this instance of Popover
|
9
|
+
*/
|
10
|
+
export declare const usePopover_unstable: (props: PopoverProps) => PopoverState;
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { useControllableState, useEventCallback, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
|
3
|
+
import { useFluent } from '@fluentui/react-shared-contexts';
|
4
|
+
import { usePopper, resolvePositioningShorthand, mergeArrowOffset, usePopperMouseTarget } from '@fluentui/react-positioning';
|
5
|
+
import { elementContains } from '@fluentui/react-portal';
|
6
|
+
import { arrowHeights } from '../PopoverSurface/index';
|
7
|
+
/**
|
8
|
+
* Create the state required to render Popover.
|
9
|
+
*
|
10
|
+
* The returned state can be modified with hooks such as usePopoverStyles,
|
11
|
+
* before being passed to renderPopover_unstable.
|
12
|
+
*
|
13
|
+
* @param props - props from this instance of Popover
|
14
|
+
*/
|
15
|
+
|
16
|
+
export const usePopover_unstable = props => {
|
17
|
+
const [contextTarget, setContextTarget] = usePopperMouseTarget();
|
18
|
+
const initialState = {
|
19
|
+
size: 'medium',
|
20
|
+
contextTarget,
|
21
|
+
setContextTarget,
|
22
|
+
...props
|
23
|
+
};
|
24
|
+
const [open, setOpen] = useOpenState(initialState);
|
25
|
+
const popperRefs = usePopoverRefs(initialState);
|
26
|
+
const {
|
27
|
+
targetDocument
|
28
|
+
} = useFluent();
|
29
|
+
useOnClickOutside({
|
30
|
+
contains: elementContains,
|
31
|
+
element: targetDocument,
|
32
|
+
callback: ev => setOpen(ev, false),
|
33
|
+
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
34
|
+
disabled: !open
|
35
|
+
});
|
36
|
+
useOnScrollOutside({
|
37
|
+
contains: elementContains,
|
38
|
+
element: targetDocument,
|
39
|
+
callback: ev => setOpen(ev, false),
|
40
|
+
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
41
|
+
disabled: !open || !initialState.openOnContext // only close on scroll for context
|
42
|
+
|
43
|
+
});
|
44
|
+
return { ...initialState,
|
45
|
+
...popperRefs,
|
46
|
+
open,
|
47
|
+
setOpen,
|
48
|
+
setContextTarget,
|
49
|
+
contextTarget
|
50
|
+
};
|
51
|
+
};
|
52
|
+
/**
|
53
|
+
* Creates and manages the Popover open state
|
54
|
+
*/
|
55
|
+
|
56
|
+
function useOpenState(state) {
|
57
|
+
const onOpenChange = useEventCallback((e, data) => {
|
58
|
+
var _a;
|
59
|
+
|
60
|
+
return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
|
61
|
+
});
|
62
|
+
const [open, setOpenState] = useControllableState({
|
63
|
+
state: state.open,
|
64
|
+
defaultState: state.defaultOpen,
|
65
|
+
initialState: false
|
66
|
+
});
|
67
|
+
state.open = open !== undefined ? open : state.open;
|
68
|
+
const setContextTarget = state.setContextTarget;
|
69
|
+
const setOpen = React.useCallback((e, shouldOpen) => {
|
70
|
+
if (shouldOpen && e.type === 'contextmenu') {
|
71
|
+
setContextTarget(e);
|
72
|
+
}
|
73
|
+
|
74
|
+
if (!shouldOpen) {
|
75
|
+
setContextTarget(undefined);
|
76
|
+
}
|
77
|
+
|
78
|
+
setOpenState(prevOpen => {
|
79
|
+
// More than one event (mouse, focus, keyboard) can request the Popover to close
|
80
|
+
// We assume the first event is the correct one
|
81
|
+
if (prevOpen !== shouldOpen) {
|
82
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(e, {
|
83
|
+
open: shouldOpen
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
return shouldOpen;
|
88
|
+
});
|
89
|
+
}, [setOpenState, onOpenChange, setContextTarget]);
|
90
|
+
return [open, setOpen];
|
91
|
+
}
|
92
|
+
/**
|
93
|
+
* Creates and sets the necessary trigger, target and content refs used by Popover
|
94
|
+
*/
|
95
|
+
|
96
|
+
|
97
|
+
function usePopoverRefs(state) {
|
98
|
+
const popperOptions = {
|
99
|
+
position: 'above',
|
100
|
+
align: 'center',
|
101
|
+
target: state.openOnContext ? state.contextTarget : undefined,
|
102
|
+
...resolvePositioningShorthand(state.positioning)
|
103
|
+
}; // no reason to render arrow when covering the target
|
104
|
+
|
105
|
+
if (popperOptions.coverTarget) {
|
106
|
+
state.noArrow = true;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (!state.noArrow) {
|
110
|
+
popperOptions.offset = mergeArrowOffset(popperOptions.offset, arrowHeights[state.size]);
|
111
|
+
}
|
112
|
+
|
113
|
+
const {
|
114
|
+
targetRef: triggerRef,
|
115
|
+
containerRef: contentRef,
|
116
|
+
arrowRef
|
117
|
+
} = usePopper(popperOptions);
|
118
|
+
return {
|
119
|
+
triggerRef,
|
120
|
+
contentRef,
|
121
|
+
arrowRef
|
122
|
+
};
|
123
|
+
}
|
124
|
+
//# sourceMappingURL=usePopover.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Popover/usePopover.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from 'react';\nimport {\n useControllableState,\n useEventCallback,\n useOnClickOutside,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent } from '@fluentui/react-shared-contexts';\nimport {\n usePopper,\n resolvePositioningShorthand,\n mergeArrowOffset,\n usePopperMouseTarget,\n} from '@fluentui/react-positioning';\nimport { elementContains } from '@fluentui/react-portal';\nimport { arrowHeights } from '../PopoverSurface/index';\nimport type { OpenPopoverEvents, PopoverProps, PopoverState } from './Popover.types';\n\n/**\n * Create the state required to render Popover.\n *\n * The returned state can be modified with hooks such as usePopoverStyles,\n * before being passed to renderPopover_unstable.\n *\n * @param props - props from this instance of Popover\n */\nexport const usePopover_unstable = (props: PopoverProps): PopoverState => {\n const [contextTarget, setContextTarget] = usePopperMouseTarget();\n const initialState = {\n size: 'medium',\n contextTarget,\n setContextTarget,\n ...props,\n } as const;\n\n const [open, setOpen] = useOpenState(initialState);\n const popperRefs = usePopoverRefs(initialState);\n\n const { targetDocument } = useFluent();\n useOnClickOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [popperRefs.triggerRef, popperRefs.contentRef],\n disabled: !open,\n });\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [popperRefs.triggerRef, popperRefs.contentRef],\n disabled: !open || !initialState.openOnContext, // only close on scroll for context\n });\n\n return {\n ...initialState,\n ...popperRefs,\n open,\n setOpen,\n setContextTarget,\n contextTarget,\n };\n};\n\n/**\n * Creates and manages the Popover open state\n */\nfunction useOpenState(\n state: Pick<PopoverState, 'setContextTarget' | 'onOpenChange'> & Pick<PopoverProps, 'open' | 'defaultOpen'>,\n) {\n const onOpenChange: PopoverState['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const [open, setOpenState] = useControllableState({\n state: state.open,\n defaultState: state.defaultOpen,\n initialState: false,\n });\n state.open = open !== undefined ? open : state.open;\n const setContextTarget = state.setContextTarget;\n\n const setOpen = React.useCallback(\n (e: OpenPopoverEvents, shouldOpen: boolean) => {\n if (shouldOpen && e.type === 'contextmenu') {\n setContextTarget(e as React.MouseEvent);\n }\n\n if (!shouldOpen) {\n setContextTarget(undefined);\n }\n\n setOpenState(prevOpen => {\n // More than one event (mouse, focus, keyboard) can request the Popover to close\n // We assume the first event is the correct one\n if (prevOpen !== shouldOpen) {\n onOpenChange?.(e, { open: shouldOpen });\n }\n\n return shouldOpen;\n });\n },\n [setOpenState, onOpenChange, setContextTarget],\n );\n\n return [open, setOpen] as const;\n}\n\n/**\n * Creates and sets the necessary trigger, target and content refs used by Popover\n */\nfunction usePopoverRefs(\n state: Pick<PopoverState, 'size' | 'contextTarget'> & Pick<PopoverProps, 'positioning' | 'openOnContext' | 'noArrow'>,\n) {\n const popperOptions = {\n position: 'above' as const,\n align: 'center' as const,\n target: state.openOnContext ? state.contextTarget : undefined,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n // no reason to render arrow when covering the target\n if (popperOptions.coverTarget) {\n state.noArrow = true;\n }\n\n if (!state.noArrow) {\n popperOptions.offset = mergeArrowOffset(popperOptions.offset, arrowHeights[state.size]);\n }\n\n const { targetRef: triggerRef, containerRef: contentRef, arrowRef } = usePopper(popperOptions);\n\n return {\n triggerRef,\n contentRef,\n arrowRef,\n } as const;\n}\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { PopoverSurfaceProps } from './PopoverSurface.types';
|
2
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
3
|
+
/**
|
4
|
+
* PopoverSurface component renders react children in a positioned box
|
5
|
+
*/
|
6
|
+
export declare const PopoverSurface: ForwardRefComponent<PopoverSurfaceProps>;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { usePopoverSurface_unstable } from './usePopoverSurface';
|
3
|
+
import { renderPopoverSurface_unstable } from './renderPopoverSurface';
|
4
|
+
import { usePopoverSurfaceStyles_unstable } from './usePopoverSurfaceStyles';
|
5
|
+
/**
|
6
|
+
* PopoverSurface component renders react children in a positioned box
|
7
|
+
*/
|
8
|
+
|
9
|
+
export const PopoverSurface = /*#__PURE__*/React.forwardRef((props, ref) => {
|
10
|
+
const state = usePopoverSurface_unstable(props, ref);
|
11
|
+
usePopoverSurfaceStyles_unstable(state);
|
12
|
+
return renderPopoverSurface_unstable(state);
|
13
|
+
});
|
14
|
+
PopoverSurface.displayName = 'PopoverSurface';
|
15
|
+
//# sourceMappingURL=PopoverSurface.js.map
|