@fluentui/react-popover 9.0.0-rc.8 → 9.0.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.
Files changed (52) hide show
  1. package/CHANGELOG.json +499 -1
  2. package/CHANGELOG.md +136 -2
  3. package/Spec.md +5 -5
  4. package/dist/index.d.ts +93 -71
  5. package/lib/components/Popover/Popover.js.map +1 -1
  6. package/lib/components/Popover/Popover.types.js.map +1 -1
  7. package/lib/components/Popover/constants.js +10 -0
  8. package/lib/components/Popover/constants.js.map +1 -0
  9. package/lib/components/Popover/renderPopover.js +20 -16
  10. package/lib/components/Popover/renderPopover.js.map +1 -1
  11. package/lib/components/Popover/usePopover.js +18 -16
  12. package/lib/components/Popover/usePopover.js.map +1 -1
  13. package/lib/components/PopoverSurface/PopoverSurface.js.map +1 -1
  14. package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
  15. package/lib/components/PopoverSurface/renderPopoverSurface.js +1 -1
  16. package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
  17. package/lib/components/PopoverSurface/usePopoverSurface.js +5 -3
  18. package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -1
  19. package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +20 -25
  20. package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
  21. package/lib/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
  22. package/lib/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -1
  23. package/lib/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
  24. package/lib/components/PopoverTrigger/usePopoverTrigger.js +2 -2
  25. package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
  26. package/lib/index.js +4 -4
  27. package/lib/index.js.map +1 -1
  28. package/lib/popoverContext.js +2 -0
  29. package/lib/popoverContext.js.map +1 -1
  30. package/lib-commonjs/components/Popover/Popover.js.map +1 -1
  31. package/lib-commonjs/components/Popover/constants.js +17 -0
  32. package/lib-commonjs/components/Popover/constants.js.map +1 -0
  33. package/lib-commonjs/components/Popover/renderPopover.js +20 -16
  34. package/lib-commonjs/components/Popover/renderPopover.js.map +1 -1
  35. package/lib-commonjs/components/Popover/usePopover.js +18 -15
  36. package/lib-commonjs/components/Popover/usePopover.js.map +1 -1
  37. package/lib-commonjs/components/PopoverSurface/PopoverSurface.js.map +1 -1
  38. package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +1 -1
  39. package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
  40. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +5 -3
  41. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -1
  42. package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +21 -26
  43. package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
  44. package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
  45. package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
  46. package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +2 -2
  47. package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
  48. package/lib-commonjs/index.js +92 -5
  49. package/lib-commonjs/index.js.map +1 -1
  50. package/lib-commonjs/popoverContext.js +3 -1
  51. package/lib-commonjs/popoverContext.js.map +1 -1
  52. package/package.json +15 -15
package/Spec.md CHANGED
@@ -344,7 +344,7 @@ Default popover
344
344
 
345
345
  // Expected Markup
346
346
  <div id="container">
347
- <button aria-haspopup="dialog">Trigger</button>
347
+ <button aria-expanded="false">Trigger</button>
348
348
  </div>
349
349
 
350
350
  // on document.body
@@ -370,7 +370,7 @@ Popover that traps focus
370
370
 
371
371
  // Expected Markup
372
372
  <div id="container">
373
- <button aria-haspopup="dialog">Trigger</button>
373
+ <button aria-expanded="false">Trigger</button>
374
374
  </div>
375
375
 
376
376
  // on document.body
@@ -396,7 +396,7 @@ Inline popover
396
396
 
397
397
  // Expected Markup
398
398
  <div id="container">
399
- <button aria-haspopup="dialog">Trigger</button>
399
+ <button aria-expanded="false">Trigger</button>
400
400
  <div>
401
401
  {/** content */}
402
402
  </div>
@@ -498,7 +498,7 @@ Accessible markup is divided into two scenarios:
498
498
 
499
499
  ```tsx
500
500
  // Popover that does not trap focus
501
- <button aria-haspopup="dialog">Trigger</button>
501
+ <button aria-expanded="false">Trigger</button>
502
502
  <div role="complementary">
503
503
  No focus trap
504
504
  </div>
@@ -507,7 +507,7 @@ Accessible markup is divided into two scenarios:
507
507
  <div aria-hidden="true" /> // other content
508
508
  <div aria-hidden="true" /> // other content
509
509
  <div aria-hidden="true" className='fui-provider'>
510
- <button aria-haspopup="dialog">Trigger</button>
510
+ <button aria-expanded="false">Trigger</button>
511
511
  </div>
512
512
 
513
513
  <div role="dialog" aria-modal="true">
package/dist/index.d.ts CHANGED
@@ -1,18 +1,21 @@
1
1
  import type { ComponentProps } from '@fluentui/react-utilities';
2
2
  import type { ComponentState } from '@fluentui/react-utilities';
3
- import type { Context } from '@fluentui/react-context-selector';
4
3
  import type { ContextSelector } from '@fluentui/react-context-selector';
4
+ import { FC } from 'react';
5
5
  import type { FluentTriggerComponent } from '@fluentui/react-utilities';
6
6
  import type { ForwardRefComponent } from '@fluentui/react-utilities';
7
7
  import { JSXElementConstructor } from 'react';
8
- import type { PopperVirtualElement } from '@fluentui/react-positioning';
9
8
  import type { PortalProps } from '@fluentui/react-portal';
10
9
  import type { PositioningShorthand } from '@fluentui/react-positioning';
10
+ import type { PositioningVirtualElement } from '@fluentui/react-positioning';
11
+ import { Provider } from 'react';
12
+ import { ProviderProps } from 'react';
11
13
  import * as React_2 from 'react';
12
14
  import { ReactElement } from 'react';
13
15
  import type { Slot } from '@fluentui/react-utilities';
14
16
  import type { SlotClassNames } from '@fluentui/react-utilities';
15
- import type { usePopperMouseTarget } from '@fluentui/react-positioning';
17
+ import type { UseModalAttributesOptions } from '@fluentui/react-tabster';
18
+ import type { usePositioningMouseTarget } from '@fluentui/react-positioning';
16
19
 
17
20
  export declare const arrowHeights: Record<PopoverSize, number>;
18
21
 
@@ -26,89 +29,113 @@ export declare type OnOpenChangeData = {
26
29
  /**
27
30
  * The supported events that will trigger open/close of the menu
28
31
  */
29
- export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React_2.MouseEvent<HTMLElement> | React_2.KeyboardEvent<HTMLElement> | React_2.FocusEvent<HTMLElement>;
32
+ export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React_2.FocusEvent<HTMLElement> | React_2.KeyboardEvent<HTMLElement> | React_2.MouseEvent<HTMLElement>;
30
33
 
31
34
  /**
32
35
  * Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.
33
36
  */
34
37
  export declare const Popover: React_2.FC<PopoverProps>;
35
38
 
36
- declare type PopoverCommons = Pick<PortalProps, 'mountNode'> & {
39
+ /**
40
+ * Context shared between Popover and its children components
41
+ */
42
+ export declare type PopoverContextValue = Pick<PopoverState, 'open' | 'toggleOpen' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'withArrow' | 'arrowRef' | 'size' | 'appearance' | 'trapFocus' | 'legacyTrapFocus' | 'inline'>;
43
+
44
+ /**
45
+ * Popover Props
46
+ */
47
+ export declare type PopoverProps = Pick<PortalProps, 'mountNode'> & {
37
48
  /**
38
- * Popovers are rendered out of DOM order on `document.body` by default, use this to render the popover in DOM order
49
+ * A popover can appear styled with brand or inverted.
50
+ * When not specified, the default style is used.
39
51
  */
40
- inline: boolean;
52
+ appearance?: 'brand' | 'inverted';
41
53
  /**
42
- * Controls the opening of the Popover
54
+ * Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.
55
+ * Alternatively can only contain {@link PopoverSurface} if using a custom `target`.
43
56
  */
44
- open: boolean;
57
+ children: [JSX.Element, JSX.Element] | JSX.Element;
45
58
  /**
46
- * Used to set the initial open state of the Popover in uncontrolled mode
59
+ * Close when scroll outside of it
60
+ *
61
+ * @default false
47
62
  */
48
- defaultOpen?: boolean;
63
+ closeOnScroll?: boolean;
49
64
  /**
50
- * Call back when the component requests to change value
51
- * The `open` value is used as a hint when directly controlling the component
65
+ * Used to set the initial open state of the Popover in uncontrolled mode
66
+ *
67
+ * @default false
52
68
  */
53
- onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;
69
+ defaultOpen?: boolean;
54
70
  /**
55
- * Flag to open the Popover by hovering the trigger
71
+ * Popovers are rendered out of DOM order on `document.body` by default, use this to render the popover in DOM order
72
+ *
73
+ * @default false
56
74
  */
57
- openOnHover?: boolean;
75
+ inline?: boolean;
58
76
  /**
59
77
  * Sets the delay for closing popover on mouse leave
60
78
  */
61
79
  mouseLeaveDelay?: number;
62
80
  /**
63
- * Flag to open the Popover as a context menu. Disables all other interactions
81
+ * Display an arrow pointing to the target.
82
+ *
83
+ * @default false
64
84
  */
65
- openOnContext?: boolean;
85
+ withArrow?: boolean;
66
86
  /**
67
- * Do not display the arrow
87
+ * Call back when the component requests to change value
88
+ * The `open` value is used as a hint when directly controlling the component
68
89
  */
69
- noArrow?: boolean;
90
+ onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;
70
91
  /**
71
- * Determines popover padding and arrow size
72
- * @default medium
92
+ * Controls the opening of the Popover
93
+ *
94
+ * @default false
73
95
  */
74
- size?: PopoverSize;
96
+ open?: boolean;
75
97
  /**
76
- * A popover can appear styled with brand or inverted.
77
- * When not specified, the default style is used.
98
+ * Flag to open the Popover as a context menu. Disables all other interactions
99
+ *
100
+ * @default false
78
101
  */
79
- appearance?: 'brand' | 'inverted';
102
+ openOnContext?: boolean;
80
103
  /**
81
- * Should trap focus
104
+ * Flag to open the Popover by hovering the trigger
105
+ *
106
+ * @default false
82
107
  */
83
- trapFocus?: boolean;
108
+ openOnHover?: boolean;
84
109
  /**
85
110
  * Configures the position of the Popover
86
111
  */
87
112
  positioning?: PositioningShorthand;
88
113
  /**
89
- * Close when scroll outside of it
114
+ * Determines popover padding and arrow size
115
+ *
116
+ * @default medium
90
117
  */
91
- closeOnScroll?: boolean;
92
- };
93
-
94
- export declare const PopoverContext: Context<PopoverContextValue>;
95
-
96
- /**
97
- * Context shared between Popover and its children components
98
- */
99
- export declare type PopoverContextValue = Pick<PopoverState, 'toggleOpen' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'noArrow' | 'arrowRef' | 'size' | 'appearance' | 'trapFocus' | 'inline'>;
100
-
101
- /**
102
- * Popover Props
103
- */
104
- export declare type PopoverProps = Partial<PopoverCommons> & {
118
+ size?: PopoverSize;
105
119
  /**
106
- * Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.
107
- * Alternatively can only contain {@link PopoverSurface} if using a custom `target`.
120
+ * Should trap focus
121
+ *
122
+ * @default false
108
123
  */
109
- children: [JSX.Element, JSX.Element] | JSX.Element;
124
+ trapFocus?: UseModalAttributesOptions['trapFocus'];
125
+ /**
126
+ * Must be used with the `trapFocus` prop
127
+ * Enables older Fluent UI focus trap behavior where the user
128
+ * cannot tab into the window outside of the document. This is now
129
+ * non-standard behavior according to the [HTML dialog spec](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)
130
+ * where the focus trap involves setting outside elements inert.
131
+ *
132
+ * @default false
133
+ */
134
+ legacyTrapFocus?: UseModalAttributesOptions['legacyTrapFocus'];
110
135
  };
111
136
 
137
+ export declare const PopoverProvider: Provider<PopoverContextValue> & FC<ProviderProps<PopoverContextValue>>;
138
+
112
139
  /**
113
140
  * Determines popover padding and arrow size
114
141
  */
@@ -117,38 +144,38 @@ export declare type PopoverSize = 'small' | 'medium' | 'large';
117
144
  /**
118
145
  * Popover State
119
146
  */
120
- export declare type PopoverState = PopoverCommons & Pick<PopoverProps, 'children'> & {
147
+ export declare type PopoverState = Pick<PopoverProps, 'appearance' | 'mountNode' | 'onOpenChange' | 'openOnContext' | 'openOnHover' | 'trapFocus' | 'withArrow' | 'legacyTrapFocus'> & Required<Pick<PopoverProps, 'inline' | 'open'>> & Pick<PopoverProps, 'children'> & {
121
148
  /**
122
- * Callback to open/close the Popover
149
+ * Ref of the pointing arrow
123
150
  */
124
- setOpen: (e: OpenPopoverEvents, open: boolean) => void;
151
+ arrowRef: React_2.MutableRefObject<HTMLDivElement | null>;
125
152
  /**
126
- * Callback to toggle the open state of the Popover
153
+ * Ref of the PopoverSurface
127
154
  */
128
- toggleOpen: (e: OpenPopoverEvents) => void;
155
+ contentRef: React_2.MutableRefObject<HTMLElement | null>;
129
156
  /**
130
- * Ref of the PopoverTrigger
157
+ * Anchors the popper to the mouse click for context events
131
158
  */
132
- triggerRef: React_2.MutableRefObject<HTMLElement | null>;
159
+ contextTarget: PositioningVirtualElement | undefined;
160
+ popoverSurface: React_2.ReactElement | undefined;
161
+ popoverTrigger: React_2.ReactElement | undefined;
133
162
  /**
134
- * Ref of the PopoverSurface
163
+ * A callback to set the target of the popper to the mouse click for context events
135
164
  */
136
- contentRef: React_2.MutableRefObject<HTMLElement | null>;
165
+ setContextTarget: ReturnType<typeof usePositioningMouseTarget>[1];
137
166
  /**
138
- * Ref of the pointing arrow
167
+ * Callback to open/close the Popover
139
168
  */
140
- arrowRef: React_2.MutableRefObject<HTMLDivElement | null>;
169
+ setOpen: (e: OpenPopoverEvents, open: boolean) => void;
170
+ size: NonNullable<PopoverProps['size']>;
141
171
  /**
142
- * Anchors the popper to the mouse click for context events
172
+ * Callback to toggle the open state of the Popover
143
173
  */
144
- contextTarget: PopperVirtualElement | undefined;
174
+ toggleOpen: (e: OpenPopoverEvents) => void;
145
175
  /**
146
- * A callback to set the target of the popper to the mouse click for context events
176
+ * Ref of the PopoverTrigger
147
177
  */
148
- setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];
149
- size: NonNullable<PopoverProps['size']>;
150
- popoverTrigger: React_2.ReactElement | undefined;
151
- popoverSurface: React_2.ReactElement | undefined;
178
+ triggerRef: React_2.MutableRefObject<HTMLElement | null>;
152
179
  };
153
180
 
154
181
  /**
@@ -156,11 +183,6 @@ export declare type PopoverState = PopoverCommons & Pick<PopoverProps, 'children
156
183
  */
157
184
  export declare const PopoverSurface: ForwardRefComponent<PopoverSurfaceProps>;
158
185
 
159
- /**
160
- * @deprecated Use `popoverSurfaceClassNames.root` instead.
161
- */
162
- export declare const popoverSurfaceClassName = "fui-PopoverSurface";
163
-
164
186
  export declare const popoverSurfaceClassNames: SlotClassNames<PopoverSurfaceSlots>;
165
187
 
166
188
  /**
@@ -178,7 +200,7 @@ export declare type PopoverSurfaceSlots = {
178
200
  /**
179
201
  * PopoverSurface State
180
202
  */
181
- export declare type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> & Pick<PopoverContextValue, 'mountNode' | 'noArrow' | 'size' | 'appearance' | 'arrowRef' | 'inline'> & {
203
+ export declare type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> & Pick<PopoverContextValue, 'appearance' | 'arrowRef' | 'inline' | 'mountNode' | 'size' | 'withArrow'> & {
182
204
  /**
183
205
  * CSS class for the arrow element
184
206
  */
@@ -192,7 +214,7 @@ export declare const PopoverTrigger: React_2.FC<PopoverTriggerProps> & FluentTri
192
214
 
193
215
  export declare type PopoverTriggerChildProps = {
194
216
  ref?: React_2.Ref<never>;
195
- } & Pick<React_2.HTMLAttributes<HTMLElement>, 'aria-haspopup' | 'onClick' | 'onMouseEnter' | 'onKeyDown' | 'onMouseLeave' | 'onContextMenu'>;
217
+ } & Pick<React_2.HTMLAttributes<HTMLElement>, 'aria-expanded' | 'onClick' | 'onContextMenu' | 'onKeyDown' | 'onMouseEnter' | 'onMouseLeave'>;
196
218
 
197
219
  /**
198
220
  * PopoverTrigger Props
@@ -1 +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/"}
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;EACrD,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAD,CAAjC;EAEA,OAAO,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/"}
@@ -1 +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 * Popovers are rendered out of DOM order on `document.body` by default, use this to render the popover in DOM order\n */\n inline: boolean;\n\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 /**\n * Sets the delay for closing popover on mouse leave\n */\n mouseLeaveDelay?: number;\n\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 * Close when scroll outside of it\n */\n closeOnScroll?: boolean;\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 * Callback to toggle the open state of the Popover\n */\n toggleOpen: (e: OpenPopoverEvents) => 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 popoverTrigger: React.ReactElement | undefined;\n\n popoverSurface: React.ReactElement | undefined;\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"]}
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 {\n PositioningVirtualElement,\n PositioningShorthand,\n usePositioningMouseTarget,\n} from '@fluentui/react-positioning';\nimport type { PortalProps } from '@fluentui/react-portal';\nimport type { UseModalAttributesOptions } from '@fluentui/react-tabster';\n\n/**\n * Determines popover padding and arrow size\n */\nexport type PopoverSize = 'small' | 'medium' | 'large';\n\n/**\n * Popover Props\n */\nexport type PopoverProps = Pick<PortalProps, 'mountNode'> & {\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 * 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 * Close when scroll outside of it\n *\n * @default false\n */\n closeOnScroll?: boolean;\n\n /**\n * Used to set the initial open state of the Popover in uncontrolled mode\n *\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Popovers are rendered out of DOM order on `document.body` by default, use this to render the popover in DOM order\n *\n * @default false\n */\n inline?: boolean;\n\n /**\n * Sets the delay for closing popover on mouse leave\n */\n mouseLeaveDelay?: number;\n\n /**\n * Display an arrow pointing to the target.\n *\n * @default false\n */\n withArrow?: boolean;\n\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 /**\n * Controls the opening of the Popover\n *\n * @default false\n */\n open?: boolean;\n\n /**\n * Flag to open the Popover as a context menu. Disables all other interactions\n *\n * @default false\n */\n openOnContext?: boolean;\n\n /**\n * Flag to open the Popover by hovering the trigger\n *\n * @default false\n */\n openOnHover?: boolean;\n\n /**\n * Configures the position of the Popover\n */\n positioning?: PositioningShorthand;\n\n /**\n * Determines popover padding and arrow size\n *\n * @default medium\n */\n size?: PopoverSize;\n\n /**\n * Should trap focus\n *\n * @default false\n */\n trapFocus?: UseModalAttributesOptions['trapFocus'];\n\n /**\n * Must be used with the `trapFocus` prop\n * Enables older Fluent UI focus trap behavior where the user\n * cannot tab into the window outside of the document. This is now\n * non-standard behavior according to the [HTML dialog spec](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)\n * where the focus trap involves setting outside elements inert.\n *\n * @default false\n */\n legacyTrapFocus?: UseModalAttributesOptions['legacyTrapFocus'];\n};\n\n/**\n * Popover State\n */\nexport type PopoverState = Pick<\n PopoverProps,\n | 'appearance'\n | 'mountNode'\n | 'onOpenChange'\n | 'openOnContext'\n | 'openOnHover'\n | 'trapFocus'\n | 'withArrow'\n | 'legacyTrapFocus'\n> &\n Required<Pick<PopoverProps, 'inline' | 'open'>> &\n Pick<PopoverProps, 'children'> & {\n /**\n * Ref of the pointing arrow\n */\n arrowRef: React.MutableRefObject<HTMLDivElement | null>;\n\n /**\n * Ref of the PopoverSurface\n */\n contentRef: React.MutableRefObject<HTMLElement | null>;\n\n /**\n * Anchors the popper to the mouse click for context events\n */\n contextTarget: PositioningVirtualElement | undefined;\n\n popoverSurface: React.ReactElement | undefined;\n\n popoverTrigger: React.ReactElement | undefined;\n\n /**\n * A callback to set the target of the popper to the mouse click for context events\n */\n setContextTarget: ReturnType<typeof usePositioningMouseTarget>[1];\n\n /**\n * Callback to open/close the Popover\n */\n setOpen: (e: OpenPopoverEvents, open: boolean) => void;\n\n size: NonNullable<PopoverProps['size']>;\n\n /**\n * Callback to toggle the open state of the Popover\n */\n toggleOpen: (e: OpenPopoverEvents) => void;\n\n /**\n * Ref of the PopoverTrigger\n */\n triggerRef: React.MutableRefObject<HTMLElement | null>;\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.FocusEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>;\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @internal
3
+ * The default value of the tooltip's border radius (borderRadiusMedium).
4
+ *
5
+ * Unfortunately, Popper requires it to be specified as a variable instead of using CSS.
6
+ * While we could use getComputedStyle, that adds a performance penalty for something that
7
+ * will likely never change.
8
+ */
9
+ export const popoverSurfaceBorderRadius = 4;
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"../src/","sources":["components/Popover/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC","sourcesContent":["/**\n * @internal\n * The default value of the tooltip's border radius (borderRadiusMedium).\n *\n * Unfortunately, Popper requires it to be specified as a variable instead of using CSS.\n * While we could use getComputedStyle, that adds a performance penalty for something that\n * will likely never change.\n */\nexport const popoverSurfaceBorderRadius = 4;\n"]}
@@ -6,35 +6,39 @@ import { PopoverContext } from '../../popoverContext';
6
6
 
7
7
  export const renderPopover_unstable = state => {
8
8
  const {
9
- setOpen,
10
- toggleOpen,
11
- triggerRef,
9
+ appearance,
10
+ arrowRef,
12
11
  contentRef,
12
+ inline,
13
+ mountNode,
14
+ open,
13
15
  openOnContext,
14
16
  openOnHover,
15
- mountNode,
16
- arrowRef,
17
+ setOpen,
17
18
  size,
18
- noArrow,
19
- appearance,
19
+ toggleOpen,
20
20
  trapFocus,
21
- inline
21
+ triggerRef,
22
+ withArrow,
23
+ legacyTrapFocus
22
24
  } = state;
23
25
  return /*#__PURE__*/React.createElement(PopoverContext.Provider, {
24
26
  value: {
27
+ appearance,
28
+ arrowRef,
29
+ contentRef,
30
+ inline,
31
+ mountNode,
32
+ open,
33
+ openOnContext,
34
+ openOnHover,
25
35
  setOpen,
26
36
  toggleOpen,
27
37
  triggerRef,
28
- contentRef,
29
- openOnHover,
30
- openOnContext,
31
- mountNode,
32
- arrowRef,
33
38
  size,
34
- noArrow,
35
- appearance,
36
39
  trapFocus,
37
- inline
40
+ legacyTrapFocus,
41
+ withArrow
38
42
  }
39
43
  }, state.popoverTrigger, state.open && state.popoverSurface);
40
44
  };
@@ -1 +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,OADI;AAEJ,IAAA,UAFI;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,SAZI;AAaJ,IAAA;AAbI,MAcF,KAdJ;AAgBA,sBACE,KAAA,CAAA,aAAA,CAAC,cAAc,CAAC,QAAhB,EAAwB;AACtB,IAAA,KAAK,EAAE;AACL,MAAA,OADK;AAEL,MAAA,UAFK;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,SAZK;AAaL,MAAA;AAbK;AADe,GAAxB,EAiBG,KAAK,CAAC,cAjBT,EAkBG,KAAK,CAAC,IAAN,IAAc,KAAK,CAAC,cAlBvB,CADF;AAsBD,CAvCM","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 setOpen,\n toggleOpen,\n triggerRef,\n contentRef,\n openOnContext,\n openOnHover,\n mountNode,\n arrowRef,\n size,\n noArrow,\n appearance,\n trapFocus,\n inline,\n } = state;\n\n return (\n <PopoverContext.Provider\n value={{\n setOpen,\n toggleOpen,\n triggerRef,\n contentRef,\n openOnHover,\n openOnContext,\n mountNode,\n arrowRef,\n size,\n noArrow,\n appearance,\n trapFocus,\n inline,\n }}\n >\n {state.popoverTrigger}\n {state.open && state.popoverSurface}\n </PopoverContext.Provider>\n );\n};\n"],"sourceRoot":"../src/"}
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;EAC5D,MAAM;IACJ,UADI;IAEJ,QAFI;IAGJ,UAHI;IAIJ,MAJI;IAKJ,SALI;IAMJ,IANI;IAOJ,aAPI;IAQJ,WARI;IASJ,OATI;IAUJ,IAVI;IAWJ,UAXI;IAYJ,SAZI;IAaJ,UAbI;IAcJ,SAdI;IAeJ;EAfI,IAgBF,KAhBJ;EAkBA,oBACE,KAAA,CAAA,aAAA,CAAC,cAAc,CAAC,QAAhB,EAAwB;IACtB,KAAK,EAAE;MACL,UADK;MAEL,QAFK;MAGL,UAHK;MAIL,MAJK;MAKL,SALK;MAML,IANK;MAOL,aAPK;MAQL,WARK;MASL,OATK;MAUL,UAVK;MAWL,UAXK;MAYL,IAZK;MAaL,SAbK;MAcL,eAdK;MAeL;IAfK;EADe,CAAxB,EAmBG,KAAK,CAAC,cAnBT,EAoBG,KAAK,CAAC,IAAN,IAAc,KAAK,CAAC,cApBvB,CADF;AAwBD,CA3CM","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 appearance,\n arrowRef,\n contentRef,\n inline,\n mountNode,\n open,\n openOnContext,\n openOnHover,\n setOpen,\n size,\n toggleOpen,\n trapFocus,\n triggerRef,\n withArrow,\n legacyTrapFocus,\n } = state;\n\n return (\n <PopoverContext.Provider\n value={{\n appearance,\n arrowRef,\n contentRef,\n inline,\n mountNode,\n open,\n openOnContext,\n openOnHover,\n setOpen,\n toggleOpen,\n triggerRef,\n size,\n trapFocus,\n legacyTrapFocus,\n withArrow,\n }}\n >\n {state.popoverTrigger}\n {state.open && state.popoverSurface}\n </PopoverContext.Provider>\n );\n};\n"],"sourceRoot":"../src/"}
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react';
2
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';
3
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
4
+ import { usePositioning, resolvePositioningShorthand, mergeArrowOffset, usePositioningMouseTarget } from '@fluentui/react-positioning';
5
5
  import { elementContains } from '@fluentui/react-portal';
6
6
  import { useFocusFinders } from '@fluentui/react-tabster';
7
7
  import { arrowHeights } from '../PopoverSurface/index';
8
+ import { popoverSurfaceBorderRadius } from './constants';
8
9
  /**
9
10
  * Create the state required to render Popover.
10
11
  *
@@ -17,7 +18,7 @@ import { arrowHeights } from '../PopoverSurface/index';
17
18
  export const usePopover_unstable = props => {
18
19
  var _a;
19
20
 
20
- const [contextTarget, setContextTarget] = usePopperMouseTarget();
21
+ const [contextTarget, setContextTarget] = usePositioningMouseTarget();
21
22
  const initialState = {
22
23
  size: 'medium',
23
24
  contextTarget,
@@ -81,7 +82,7 @@ export const usePopover_unstable = props => {
81
82
  const toggleOpen = React.useCallback(e => {
82
83
  setOpen(e, !open);
83
84
  }, [setOpen, open]);
84
- const popperRefs = usePopoverRefs(initialState);
85
+ const positioningRefs = usePopoverRefs(initialState);
85
86
  const {
86
87
  targetDocument
87
88
  } = useFluent();
@@ -89,7 +90,7 @@ export const usePopover_unstable = props => {
89
90
  contains: elementContains,
90
91
  element: targetDocument,
91
92
  callback: ev => setOpen(ev, false),
92
- refs: [popperRefs.triggerRef, popperRefs.contentRef],
93
+ refs: [positioningRefs.triggerRef, positioningRefs.contentRef],
93
94
  disabled: !open
94
95
  }); // only close on scroll for context, or when closeOnScroll is specified
95
96
 
@@ -98,20 +99,20 @@ export const usePopover_unstable = props => {
98
99
  contains: elementContains,
99
100
  element: targetDocument,
100
101
  callback: ev => setOpen(ev, false),
101
- refs: [popperRefs.triggerRef, popperRefs.contentRef],
102
+ refs: [positioningRefs.triggerRef, positioningRefs.contentRef],
102
103
  disabled: !open || !closeOnScroll
103
104
  });
104
105
  const {
105
106
  findFirstFocusable
106
107
  } = useFocusFinders();
107
108
  React.useEffect(() => {
108
- if (open && popperRefs.contentRef.current) {
109
- const firstFocusable = findFirstFocusable(popperRefs.contentRef.current);
109
+ if (open && positioningRefs.contentRef.current) {
110
+ const firstFocusable = findFirstFocusable(positioningRefs.contentRef.current);
110
111
  firstFocusable === null || firstFocusable === void 0 ? void 0 : firstFocusable.focus();
111
112
  }
112
- }, [findFirstFocusable, open, popperRefs.contentRef]);
113
+ }, [findFirstFocusable, open, positioningRefs.contentRef]);
113
114
  return { ...initialState,
114
- ...popperRefs,
115
+ ...positioningRefs,
115
116
  popoverTrigger,
116
117
  popoverSurface,
117
118
  open,
@@ -168,26 +169,27 @@ function useOpenState(state) {
168
169
 
169
170
 
170
171
  function usePopoverRefs(state) {
171
- const popperOptions = {
172
+ const positioningOptions = {
172
173
  position: 'above',
173
174
  align: 'center',
175
+ arrowPadding: 2 * popoverSurfaceBorderRadius,
174
176
  target: state.openOnContext ? state.contextTarget : undefined,
175
177
  ...resolvePositioningShorthand(state.positioning)
176
178
  }; // no reason to render arrow when covering the target
177
179
 
178
- if (popperOptions.coverTarget) {
179
- state.noArrow = true;
180
+ if (positioningOptions.coverTarget) {
181
+ state.withArrow = false;
180
182
  }
181
183
 
182
- if (!state.noArrow) {
183
- popperOptions.offset = mergeArrowOffset(popperOptions.offset, arrowHeights[state.size]);
184
+ if (state.withArrow) {
185
+ positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeights[state.size]);
184
186
  }
185
187
 
186
188
  const {
187
189
  targetRef: triggerRef,
188
190
  containerRef: contentRef,
189
191
  arrowRef
190
- } = usePopper(popperOptions);
192
+ } = usePositioning(positioningOptions);
191
193
  return {
192
194
  triggerRef,
193
195
  contentRef,
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Popover/usePopover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SACE,oBADF,EAEE,gBAFF,EAGE,iBAHF,EAIE,kBAJF,QAKO,2BALP;AAMA,SAAS,SAAT,QAA0B,iCAA1B;AACA,SACE,SADF,EAEE,2BAFF,EAGE,gBAHF,EAIE,oBAJF,QAKO,6BALP;AAMA,SAAS,eAAT,QAAgC,wBAAhC;AACA,SAAS,eAAT,QAAgC,yBAAhC;AACA,SAAS,YAAT,QAA6B,yBAA7B;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OAAP,CAAP;AACD;AAED;;AAEG;;;AACH,SAAS,cAAT,CACE,KADF,EACuH;AAErH,QAAM,aAAa,GAAG;AACpB,IAAA,QAAQ,EAAE,OADU;AAEpB,IAAA,KAAK,EAAE,QAFa;AAGpB,IAAA,MAAM,EAAE,KAAK,CAAC,aAAN,GAAsB,KAAK,CAAC,aAA5B,GAA4C,SAHhC;AAIpB,OAAG,2BAA2B,CAAC,KAAK,CAAC,WAAP;AAJV,GAAtB,CAFqH,CASrH;;AACA,MAAI,aAAa,CAAC,WAAlB,EAA+B;AAC7B,IAAA,KAAK,CAAC,OAAN,GAAgB,IAAhB;AACD;;AAED,MAAI,CAAC,KAAK,CAAC,OAAX,EAAoB;AAClB,IAAA,aAAa,CAAC,MAAd,GAAuB,gBAAgB,CAAC,aAAa,CAAC,MAAf,EAAuB,YAAY,CAAC,KAAK,CAAC,IAAP,CAAnC,CAAvC;AACD;;AAED,QAAM;AAAE,IAAA,SAAS,EAAE,UAAb;AAAyB,IAAA,YAAY,EAAE,UAAvC;AAAmD,IAAA;AAAnD,MAAgE,SAAS,CAAC,aAAD,CAA/E;AAEA,SAAO;AACL,IAAA,UADK;AAEL,IAAA,UAFK;AAGL,IAAA;AAHK,GAAP;AAKD","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 { useFocusFinders } from '@fluentui/react-tabster';\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 children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at most two children');\n }\n }\n\n let popoverTrigger: React.ReactElement | undefined = undefined;\n let popoverSurface: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n popoverTrigger = children[0];\n popoverSurface = children[1];\n } else if (children.length === 1) {\n popoverSurface = children[0];\n }\n\n const [open, setOpenState] = useOpenState(initialState);\n\n const setOpenTimeoutRef = React.useRef(0);\n\n const setOpen = useEventCallback((e: OpenPopoverEvents, shouldOpen: boolean) => {\n clearTimeout(setOpenTimeoutRef.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave') {\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeoutRef.current = setTimeout(() => {\n setOpenState(e, shouldOpen);\n }, props.mouseLeaveDelay ?? 500);\n } else {\n setOpenState(e, shouldOpen);\n }\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeoutRef.current);\n };\n }, []);\n\n const toggleOpen = React.useCallback<PopoverState['toggleOpen']>(\n e => {\n setOpen(e, !open);\n },\n [setOpen, open],\n );\n\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\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = initialState.openOnContext || initialState.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [popperRefs.triggerRef, popperRefs.contentRef],\n disabled: !open || !closeOnScroll,\n });\n\n const { findFirstFocusable } = useFocusFinders();\n\n React.useEffect(() => {\n if (open && popperRefs.contentRef.current) {\n const firstFocusable = findFirstFocusable(popperRefs.contentRef.current);\n firstFocusable?.focus();\n }\n }, [findFirstFocusable, open, popperRefs.contentRef]);\n\n return {\n ...initialState,\n ...popperRefs,\n popoverTrigger,\n popoverSurface,\n open,\n setOpen,\n toggleOpen,\n setContextTarget,\n contextTarget,\n inline: props.inline ?? false,\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/"}
1
+ {"version":3,"sources":["components/Popover/usePopover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SACE,oBADF,EAEE,gBAFF,EAGE,iBAHF,EAIE,kBAJF,QAKO,2BALP;AAMA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SACE,cADF,EAEE,2BAFF,EAGE,gBAHF,EAIE,yBAJF,QAKO,6BALP;AAMA,SAAS,eAAT,QAAgC,wBAAhC;AACA,SAAS,eAAT,QAAgC,yBAAhC;AACA,SAAS,YAAT,QAA6B,yBAA7B;AAEA,SAAS,0BAAT,QAA2C,aAA3C;AAEA;;;;;;;AAOG;;AACH,OAAO,MAAM,mBAAmB,GAAI,KAAD,IAAsC;;;EACvE,MAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,yBAAyB,EAAnE;EACA,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,QADa;IAEnB,aAFmB;IAGnB,gBAHmB;IAInB,GAAG;EAJgB,CAArB;EAOA,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAN,CAAe,OAAf,CAAuB,KAAK,CAAC,QAA7B,CAAjB;;EAEA,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAI,QAAQ,CAAC,MAAT,KAAoB,CAAxB,EAA2B;MACzB;MACA,OAAO,CAAC,IAAR,CAAa,yC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{\n useControllableState,\n useEventCallback,\n useOnClickOutside,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n usePositioning,\n resolvePositioningShorthand,\n mergeArrowOffset,\n usePositioningMouseTarget,\n} from '@fluentui/react-positioning';\nimport { elementContains } from '@fluentui/react-portal';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { arrowHeights } from '../PopoverSurface/index';\nimport type { OpenPopoverEvents, PopoverProps, PopoverState } from './Popover.types';\nimport { popoverSurfaceBorderRadius } from './constants';\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] = usePositioningMouseTarget();\n const initialState = {\n size: 'medium',\n contextTarget,\n setContextTarget,\n ...props,\n } as const;\n\n const children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at most two children');\n }\n }\n\n let popoverTrigger: React.ReactElement | undefined = undefined;\n let popoverSurface: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n popoverTrigger = children[0];\n popoverSurface = children[1];\n } else if (children.length === 1) {\n popoverSurface = children[0];\n }\n\n const [open, setOpenState] = useOpenState(initialState);\n\n const setOpenTimeoutRef = React.useRef(0);\n\n const setOpen = useEventCallback((e: OpenPopoverEvents, shouldOpen: boolean) => {\n clearTimeout(setOpenTimeoutRef.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave') {\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeoutRef.current = setTimeout(() => {\n setOpenState(e, shouldOpen);\n }, props.mouseLeaveDelay ?? 500);\n } else {\n setOpenState(e, shouldOpen);\n }\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeoutRef.current);\n };\n }, []);\n\n const toggleOpen = React.useCallback<PopoverState['toggleOpen']>(\n e => {\n setOpen(e, !open);\n },\n [setOpen, open],\n );\n\n const positioningRefs = usePopoverRefs(initialState);\n\n const { targetDocument } = useFluent();\n useOnClickOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [positioningRefs.triggerRef, positioningRefs.contentRef],\n disabled: !open,\n });\n\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = initialState.openOnContext || initialState.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [positioningRefs.triggerRef, positioningRefs.contentRef],\n disabled: !open || !closeOnScroll,\n });\n\n const { findFirstFocusable } = useFocusFinders();\n\n React.useEffect(() => {\n if (open && positioningRefs.contentRef.current) {\n const firstFocusable = findFirstFocusable(positioningRefs.contentRef.current);\n firstFocusable?.focus();\n }\n }, [findFirstFocusable, open, positioningRefs.contentRef]);\n\n return {\n ...initialState,\n ...positioningRefs,\n popoverTrigger,\n popoverSurface,\n open,\n setOpen,\n toggleOpen,\n setContextTarget,\n contextTarget,\n inline: props.inline ?? false,\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'> &\n Pick<PopoverProps, 'positioning' | 'openOnContext' | 'withArrow'>,\n) {\n const positioningOptions = {\n position: 'above' as const,\n align: 'center' as const,\n arrowPadding: 2 * popoverSurfaceBorderRadius,\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 (positioningOptions.coverTarget) {\n state.withArrow = false;\n }\n\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeights[state.size]);\n }\n\n const { targetRef: triggerRef, containerRef: contentRef, arrowRef } = usePositioning(positioningOptions);\n\n return {\n triggerRef,\n contentRef,\n arrowRef,\n } as const;\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,0BAAT,QAA2C,qBAA3C;AACA,SAAS,6BAAT,QAA8C,wBAA9C;AACA,SAAS,gCAAT,QAAiD,2BAAjD;AAIA;;AAEG;;AACH,OAAO,MAAM,cAAc,gBAA6C,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;AACtG,QAAM,KAAK,GAAG,0BAA0B,CAAC,KAAD,EAAQ,GAAR,CAAxC;AAEA,EAAA,gCAAgC,CAAC,KAAD,CAAhC;AACA,SAAO,6BAA6B,CAAC,KAAD,CAApC;AACD,CALuE,CAAjE;AAOP,cAAc,CAAC,WAAf,GAA6B,gBAA7B","sourcesContent":["import * as React from 'react';\nimport { usePopoverSurface_unstable } from './usePopoverSurface';\nimport { renderPopoverSurface_unstable } from './renderPopoverSurface';\nimport { usePopoverSurfaceStyles_unstable } from './usePopoverSurfaceStyles';\nimport type { PopoverSurfaceProps } from './PopoverSurface.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * PopoverSurface component renders react children in a positioned box\n */\nexport const PopoverSurface: ForwardRefComponent<PopoverSurfaceProps> = React.forwardRef((props, ref) => {\n const state = usePopoverSurface_unstable(props, ref);\n\n usePopoverSurfaceStyles_unstable(state);\n return renderPopoverSurface_unstable(state);\n});\n\nPopoverSurface.displayName = 'PopoverSurface';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,0BAAT,QAA2C,qBAA3C;AACA,SAAS,6BAAT,QAA8C,wBAA9C;AACA,SAAS,gCAAT,QAAiD,2BAAjD;AAIA;;AAEG;;AACH,OAAO,MAAM,cAAc,gBAA6C,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;EACtG,MAAM,KAAK,GAAG,0BAA0B,CAAC,KAAD,EAAQ,GAAR,CAAxC;EAEA,gCAAgC,CAAC,KAAD,CAAhC;EACA,OAAO,6BAA6B,CAAC,KAAD,CAApC;AACD,CALuE,CAAjE;AAOP,cAAc,CAAC,WAAf,GAA6B,gBAA7B","sourcesContent":["import * as React from 'react';\nimport { usePopoverSurface_unstable } from './usePopoverSurface';\nimport { renderPopoverSurface_unstable } from './renderPopoverSurface';\nimport { usePopoverSurfaceStyles_unstable } from './usePopoverSurfaceStyles';\nimport type { PopoverSurfaceProps } from './PopoverSurface.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * PopoverSurface component renders react children in a positioned box\n */\nexport const PopoverSurface: ForwardRefComponent<PopoverSurfaceProps> = React.forwardRef((props, ref) => {\n const state = usePopoverSurface_unstable(props, ref);\n\n usePopoverSurfaceStyles_unstable(state);\n return renderPopoverSurface_unstable(state);\n});\n\nPopoverSurface.displayName = 'PopoverSurface';\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"PopoverSurface.types.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { PopoverContextValue } from '../../popoverContext';\n\n/**\n * PopoverSurface Props\n */\nexport type PopoverSurfaceProps = ComponentProps<PopoverSurfaceSlots>;\n\n/**\n * Names of the slots in PopoverSurfaceProps\n */\nexport type PopoverSurfaceSlots = {\n root: Slot<'div'>;\n};\n\n/**\n * PopoverSurface State\n */\nexport type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> &\n Pick<PopoverContextValue, 'mountNode' | 'noArrow' | 'size' | 'appearance' | 'arrowRef' | 'inline'> & {\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"]}
1
+ {"version":3,"file":"PopoverSurface.types.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { PopoverContextValue } from '../../popoverContext';\n\n/**\n * PopoverSurface Props\n */\nexport type PopoverSurfaceProps = ComponentProps<PopoverSurfaceSlots>;\n\n/**\n * Names of the slots in PopoverSurfaceProps\n */\nexport type PopoverSurfaceSlots = {\n root: Slot<'div'>;\n};\n\n/**\n * PopoverSurface State\n */\nexport type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> &\n Pick<PopoverContextValue, 'appearance' | 'arrowRef' | 'inline' | 'mountNode' | 'size' | 'withArrow'> & {\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"]}
@@ -11,7 +11,7 @@ export const renderPopoverSurface_unstable = state => {
11
11
  slotProps
12
12
  } = getSlots(state);
13
13
  const surface = /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
14
- }, !state.noArrow && /*#__PURE__*/React.createElement("div", {
14
+ }, state.withArrow && /*#__PURE__*/React.createElement("div", {
15
15
  ref: state.arrowRef,
16
16
  className: state.arrowClassName
17
17
  }), slotProps.root.children);