@fluentui/react-popover 9.0.0-alpha.40 → 9.0.0-alpha.44

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 (59) hide show
  1. package/CHANGELOG.json +67 -1
  2. package/CHANGELOG.md +39 -2
  3. package/dist/react-popover.d.ts +35 -46
  4. package/lib/common/isConformant.js +2 -0
  5. package/lib/common/isConformant.js.map +1 -1
  6. package/lib/components/Popover/Popover.types.d.ts +13 -20
  7. package/lib/components/Popover/Popover.types.js.map +1 -1
  8. package/lib/components/Popover/usePopover.js +42 -55
  9. package/lib/components/Popover/usePopover.js.map +1 -1
  10. package/lib/components/PopoverSurface/PopoverSurface.d.ts +1 -1
  11. package/lib/components/PopoverSurface/PopoverSurface.js.map +1 -1
  12. package/lib/components/PopoverSurface/PopoverSurface.types.d.ts +7 -15
  13. package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
  14. package/lib/components/PopoverSurface/renderPopoverSurface.js +4 -3
  15. package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
  16. package/lib/components/PopoverSurface/usePopoverSurface.d.ts +4 -3
  17. package/lib/components/PopoverSurface/usePopoverSurface.js +24 -15
  18. package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -1
  19. package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +1 -1
  20. package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
  21. package/lib/components/PopoverTrigger/usePopoverTrigger.js +13 -16
  22. package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
  23. package/lib-amd/common/isConformant.js +2 -0
  24. package/lib-amd/common/isConformant.js.map +1 -1
  25. package/lib-amd/components/Popover/Popover.types.d.ts +13 -20
  26. package/lib-amd/components/Popover/Popover.types.js.map +1 -1
  27. package/lib-amd/components/Popover/usePopover.js +30 -40
  28. package/lib-amd/components/Popover/usePopover.js.map +1 -1
  29. package/lib-amd/components/PopoverSurface/PopoverSurface.d.ts +1 -1
  30. package/lib-amd/components/PopoverSurface/PopoverSurface.js.map +1 -1
  31. package/lib-amd/components/PopoverSurface/PopoverSurface.types.d.ts +7 -15
  32. package/lib-amd/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
  33. package/lib-amd/components/PopoverSurface/renderPopoverSurface.js +3 -3
  34. package/lib-amd/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
  35. package/lib-amd/components/PopoverSurface/usePopoverSurface.d.ts +4 -3
  36. package/lib-amd/components/PopoverSurface/usePopoverSurface.js +12 -10
  37. package/lib-amd/components/PopoverSurface/usePopoverSurface.js.map +1 -1
  38. package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js +1 -1
  39. package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
  40. package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js +8 -11
  41. package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
  42. package/lib-commonjs/common/isConformant.js +2 -0
  43. package/lib-commonjs/common/isConformant.js.map +1 -1
  44. package/lib-commonjs/components/Popover/Popover.types.d.ts +13 -20
  45. package/lib-commonjs/components/Popover/usePopover.js +41 -54
  46. package/lib-commonjs/components/Popover/usePopover.js.map +1 -1
  47. package/lib-commonjs/components/PopoverSurface/PopoverSurface.d.ts +1 -1
  48. package/lib-commonjs/components/PopoverSurface/PopoverSurface.js.map +1 -1
  49. package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.d.ts +7 -15
  50. package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +5 -3
  51. package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
  52. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.d.ts +4 -3
  53. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +25 -16
  54. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -1
  55. package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +1 -1
  56. package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
  57. package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +13 -16
  58. package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
  59. package/package.json +10 -10
package/CHANGELOG.json CHANGED
@@ -2,7 +2,73 @@
2
2
  "name": "@fluentui/react-popover",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 10 Sep 2021 16:29:54 GMT",
5
+ "date": "Fri, 17 Sep 2021 07:32:57 GMT",
6
+ "tag": "@fluentui/react-popover_v9.0.0-alpha.44",
7
+ "version": "9.0.0-alpha.44",
8
+ "comments": {
9
+ "prerelease": [
10
+ {
11
+ "author": "Humberto.Morimoto@microsoft.com",
12
+ "package": "@fluentui/react-popover",
13
+ "commit": "90d71a0914acbb73a0365d60a85237e3d58ef575",
14
+ "comment": "Bump @fluentui/react-popover to v9.0.0-alpha.44"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Thu, 16 Sep 2021 07:38:39 GMT",
21
+ "tag": "@fluentui/react-popover_v9.0.0-alpha.43",
22
+ "version": "9.0.0-alpha.43",
23
+ "comments": {
24
+ "prerelease": [
25
+ {
26
+ "author": "behowell@microsoft.com",
27
+ "package": "@fluentui/react-popover",
28
+ "comment": "Fix typings in React.forwardRef",
29
+ "commit": "fbe41e2877a20ce0f3c01b5188e17c12f941cc4c"
30
+ },
31
+ {
32
+ "author": "behowell@microsoft.com",
33
+ "package": "@fluentui/react-popover",
34
+ "commit": "fbe41e2877a20ce0f3c01b5188e17c12f941cc4c",
35
+ "comment": "Bump @fluentui/react-popover to v9.0.0-alpha.43"
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ {
41
+ "date": "Tue, 14 Sep 2021 20:09:02 GMT",
42
+ "tag": "@fluentui/react-popover_v9.0.0-alpha.42",
43
+ "version": "9.0.0-alpha.42",
44
+ "comments": {
45
+ "prerelease": [
46
+ {
47
+ "author": "bsunderhus@microsoft.com",
48
+ "package": "@fluentui/react-popover",
49
+ "commit": "10495c31fb5c5cf48b4665601a75a0cfabb6a03c",
50
+ "comment": "Bump @fluentui/react-popover to v9.0.0-alpha.42"
51
+ }
52
+ ]
53
+ }
54
+ },
55
+ {
56
+ "date": "Tue, 14 Sep 2021 07:38:18 GMT",
57
+ "tag": "@fluentui/react-popover_v9.0.0-alpha.41",
58
+ "version": "9.0.0-alpha.41",
59
+ "comments": {
60
+ "prerelease": [
61
+ {
62
+ "author": "lingfangao@hotmail.com",
63
+ "package": "@fluentui/react-popover",
64
+ "comment": "refactor(Popover): Remove mergeProps and migrate to simple slots",
65
+ "commit": "fe05da92ddc2742135a689b7b990f8152bd752c3"
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ {
71
+ "date": "Fri, 10 Sep 2021 16:31:53 GMT",
6
72
  "tag": "@fluentui/react-popover_v9.0.0-alpha.40",
7
73
  "version": "9.0.0-alpha.40",
8
74
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,49 @@
1
1
  # Change Log - @fluentui/react-popover
2
2
 
3
- This log was last generated on Fri, 10 Sep 2021 16:29:54 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 17 Sep 2021 07:32:57 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0-alpha.44](https://github.com/microsoft/fluentui/tree/@fluentui/react-popover_v9.0.0-alpha.44)
8
+
9
+ Fri, 17 Sep 2021 07:32:57 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-popover_v9.0.0-alpha.43..@fluentui/react-popover_v9.0.0-alpha.44)
11
+
12
+ ### Changes
13
+
14
+ - Bump @fluentui/react-popover to v9.0.0-alpha.44 ([PR #19840](https://github.com/microsoft/fluentui/pull/19840) by Humberto.Morimoto@microsoft.com)
15
+
16
+ ## [9.0.0-alpha.43](https://github.com/microsoft/fluentui/tree/@fluentui/react-popover_v9.0.0-alpha.43)
17
+
18
+ Thu, 16 Sep 2021 07:38:39 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-popover_v9.0.0-alpha.42..@fluentui/react-popover_v9.0.0-alpha.43)
20
+
21
+ ### Changes
22
+
23
+ - Fix typings in React.forwardRef ([PR #19815](https://github.com/microsoft/fluentui/pull/19815) by behowell@microsoft.com)
24
+ - Bump @fluentui/react-popover to v9.0.0-alpha.43 ([PR #19815](https://github.com/microsoft/fluentui/pull/19815) by behowell@microsoft.com)
25
+
26
+ ## [9.0.0-alpha.42](https://github.com/microsoft/fluentui/tree/@fluentui/react-popover_v9.0.0-alpha.42)
27
+
28
+ Tue, 14 Sep 2021 20:09:02 GMT
29
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-popover_v9.0.0-alpha.41..@fluentui/react-popover_v9.0.0-alpha.42)
30
+
31
+ ### Changes
32
+
33
+ - Bump @fluentui/react-popover to v9.0.0-alpha.42 ([PR #19155](https://github.com/microsoft/fluentui/pull/19155) by bsunderhus@microsoft.com)
34
+
35
+ ## [9.0.0-alpha.41](https://github.com/microsoft/fluentui/tree/@fluentui/react-popover_v9.0.0-alpha.41)
36
+
37
+ Tue, 14 Sep 2021 07:38:18 GMT
38
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-popover_v9.0.0-alpha.40..@fluentui/react-popover_v9.0.0-alpha.41)
39
+
40
+ ### Changes
41
+
42
+ - refactor(Popover): Remove mergeProps and migrate to simple slots ([PR #19605](https://github.com/microsoft/fluentui/pull/19605) by lingfangao@hotmail.com)
43
+
7
44
  ## [9.0.0-alpha.40](https://github.com/microsoft/fluentui/tree/@fluentui/react-popover_v9.0.0-alpha.40)
8
45
 
9
- Fri, 10 Sep 2021 16:29:54 GMT
46
+ Fri, 10 Sep 2021 16:31:53 GMT
10
47
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-popover_v9.0.0-alpha.39..@fluentui/react-popover_v9.0.0-alpha.40)
11
48
 
12
49
  ### Changes
@@ -1,11 +1,13 @@
1
- import type { ComponentPropsCompat } from '@fluentui/react-utilities';
2
- import type { ComponentStateCompat } from '@fluentui/react-utilities';
1
+ import type { ComponentProps } from '@fluentui/react-utilities';
2
+ import type { ComponentState } from '@fluentui/react-utilities';
3
3
  import type { Context } from '@fluentui/react-context-selector';
4
4
  import type { ContextSelector } from '@fluentui/react-context-selector';
5
+ import type { IntrinsicShorthandProps } from '@fluentui/react-utilities';
5
6
  import type { PopperVirtualElement } from '@fluentui/react-positioning';
6
7
  import type { PortalProps } from '@fluentui/react-portal';
7
8
  import type { PositioningShorthand } from '@fluentui/react-positioning';
8
9
  import * as React_2 from 'react';
10
+ import type { usePopperMouseTarget } from '@fluentui/react-positioning';
9
11
 
10
12
  export declare const arrowHeights: Record<PopoverSize, number>;
11
13
 
@@ -25,28 +27,11 @@ export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React_2.MouseE
25
27
  */
26
28
  export declare const Popover: React_2.FC<PopoverProps>;
27
29
 
28
- export declare const PopoverContext: Context<PopoverContextValue>;
29
-
30
- /**
31
- * Context shared between Popover and its children components
32
- */
33
- export declare interface PopoverContextValue extends Pick<PopoverState, 'open' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'noArrow' | 'arrowRef' | 'size' | 'brand' | 'inverted' | 'trapFocus'> {
34
- }
35
-
36
- /**
37
- * Names of PopoverProps that have a default value in usePopover
38
- */
39
- export declare type PopoverDefaultedProps = never;
40
-
41
- /**
42
- * Popover Props
43
- */
44
- export declare interface PopoverProps extends Pick<PortalProps, 'mountNode'> {
45
- children: React_2.ReactNode;
30
+ export declare interface PopoverCommons extends Pick<PortalProps, 'mountNode'> {
46
31
  /**
47
32
  * Controls the opening of the Popover
48
33
  */
49
- open?: boolean;
34
+ open: boolean;
50
35
  /**
51
36
  * Used to set the initial open state of the Popover in uncontrolled mode
52
37
  */
@@ -93,10 +78,24 @@ export declare interface PopoverProps extends Pick<PortalProps, 'mountNode'> {
93
78
  positioning?: PositioningShorthand;
94
79
  }
95
80
 
81
+ export declare const PopoverContext: Context<PopoverContextValue>;
82
+
83
+ /**
84
+ * Context shared between Popover and its children components
85
+ */
86
+ export declare interface PopoverContextValue extends Pick<PopoverState, 'open' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'noArrow' | 'arrowRef' | 'size' | 'brand' | 'inverted' | 'trapFocus'> {
87
+ }
88
+
96
89
  /**
97
- * Names of the shorthand properties in PopoverProps
90
+ * Popover Props
98
91
  */
99
- export declare type PopoverShorthandProps = never;
92
+ export declare interface PopoverProps extends Partial<PopoverCommons> {
93
+ /**
94
+ * Can contain two children including {@link PopoverTrigger} and {@link PopoverPopover}.
95
+ * Alternatively can only contain {@link PopoverPopover} if using a custom `target`.
96
+ */
97
+ children: [JSX.Element, JSX.Element] | JSX.Element;
98
+ }
100
99
 
101
100
  /**
102
101
  * Determines popover padding and arrow size
@@ -106,11 +105,7 @@ export declare type PopoverSize = 'small' | 'medium' | 'large';
106
105
  /**
107
106
  * Popover State
108
107
  */
109
- export declare interface PopoverState extends ComponentStateCompat<PopoverProps, PopoverShorthandProps, PopoverDefaultedProps> {
110
- /**
111
- * Open state of the Popover
112
- */
113
- open: boolean;
108
+ export declare interface PopoverState extends PopoverCommons, Pick<PopoverProps, 'children'> {
114
109
  /**
115
110
  * Callback to open/close the Popover
116
111
  */
@@ -134,40 +129,34 @@ export declare interface PopoverState extends ComponentStateCompat<PopoverProps,
134
129
  /**
135
130
  * A callback to set the target of the popper to the mouse click for context events
136
131
  */
137
- setContextTarget: React_2.Dispatch<PopperVirtualElement | undefined>;
132
+ setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];
138
133
  size: NonNullable<PopoverProps['size']>;
139
134
  }
140
135
 
141
136
  /**
142
137
  * PopoverSurface component renders react children in a positioned box
143
138
  */
144
- export declare const PopoverSurface: React_2.ForwardRefExoticComponent<PopoverSurfaceProps & React_2.RefAttributes<HTMLElement>>;
145
-
146
- /**
147
- * Names of PopoverSurfaceProps that have a default value in usePopoverSurface
148
- */
149
- export declare type PopoverSurfaceDefaultedProps = never;
139
+ export declare const PopoverSurface: React_2.ForwardRefExoticComponent<PopoverSurfaceProps & React_2.RefAttributes<HTMLDivElement>>;
150
140
 
151
141
  /**
152
142
  * PopoverSurface Props
153
143
  */
154
- export declare interface PopoverSurfaceProps extends ComponentPropsCompat, React_2.HTMLAttributes<HTMLElement> {
144
+ export declare interface PopoverSurfaceProps extends ComponentProps<PopoverSurfaceSlots> {
155
145
  }
156
146
 
157
147
  /**
158
- * Names of the shorthand properties in PopoverSurfaceProps
148
+ * Names of the slots in PopoverSurfaceProps
159
149
  */
160
- export declare type PopoverSurfaceShorthandProps = never;
150
+ export declare type PopoverSurfaceSlots = {
151
+ root: IntrinsicShorthandProps<'div'>;
152
+ };
153
+
154
+ export declare const popoverSurfaceSlots: Array<keyof PopoverSurfaceSlots>;
161
155
 
162
156
  /**
163
157
  * PopoverSurface State
164
158
  */
165
- export declare interface PopoverSurfaceState extends ComponentStateCompat<PopoverSurfaceProps, PopoverSurfaceShorthandProps, PopoverSurfaceDefaultedProps>, Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'brand' | 'inverted'> {
166
- ref: React_2.Ref<HTMLElement>;
167
- /**
168
- * Ref to the arrow element
169
- */
170
- arrowRef?: React_2.Ref<HTMLDivElement>;
159
+ export declare interface PopoverSurfaceState extends ComponentState<PopoverSurfaceSlots>, Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'brand' | 'inverted' | 'arrowRef'> {
171
160
  /**
172
161
  * CSS class for the arrow element
173
162
  */
@@ -227,10 +216,10 @@ export declare const usePopoverContext: <T>(selector: ContextSelector<PopoverCon
227
216
  * before being passed to renderPopoverSurface.
228
217
  *
229
218
  * @param props - props from this instance of PopoverSurface
230
- * @param ref - reference to root HTMLElement of PopoverSurface
219
+ * @param ref - reference to root HTMLDivElement of PopoverSurface
231
220
  * @param defaultProps - (optional) default prop values provided by the implementing type
232
221
  */
233
- export declare const usePopoverSurface: (props: PopoverSurfaceProps, ref: React_2.Ref<HTMLElement>, defaultProps?: PopoverSurfaceProps | undefined) => PopoverSurfaceState;
222
+ export declare const usePopoverSurface: (props: PopoverSurfaceProps, ref: React_2.Ref<HTMLDivElement>) => PopoverSurfaceState;
234
223
 
235
224
  /**
236
225
  * Apply styling to the PopoverSurface slots based on the state
@@ -4,6 +4,8 @@ export function isConformant(testInfo) {
4
4
  var defaultOptions = {
5
5
  asPropHandlesRef: true,
6
6
  componentPath: module.parent.filename.replace('.test', ''),
7
+ // TODO // https://github.com/microsoft/fluentui/issues/19522
8
+ skipAsPropTests: true,
7
9
  extraTests: makeStylesTests
8
10
  };
9
11
  baseIsConformant(defaultOptions, testInfo);
@@ -1 +1 @@
1
- {"version":3,"sources":["common/isConformant.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,IAAI,gBAAzB,QAAiD,6BAAjD;AAEA,OAAO,eAAP,MAA4B,yCAA5B;AAEA,OAAM,SAAU,YAAV,CACJ,QADI,EACqF;AAEzF,MAAM,cAAc,GAAyC;AAC3D,IAAA,gBAAgB,EAAE,IADyC;AAE3D,IAAA,aAAa,EAAE,MAAO,CAAC,MAAR,CAAgB,QAAhB,CAAyB,OAAzB,CAAiC,OAAjC,EAA0C,EAA1C,CAF4C;AAG3D,IAAA,UAAU,EAAE;AAH+C,GAA7D;AAMA,EAAA,gBAAgB,CAAC,cAAD,EAAiB,QAAjB,CAAhB;AACD","sourcesContent":["import { isConformant as baseIsConformant } from '@fluentui/react-conformance';\nimport type { IsConformantOptions, TestObject } from '@fluentui/react-conformance';\nimport makeStylesTests from '@fluentui/react-conformance-make-styles';\n\nexport function isConformant<TProps = {}>(\n testInfo: Omit<IsConformantOptions<TProps>, 'componentPath'> & { componentPath?: string },\n) {\n const defaultOptions: Partial<IsConformantOptions<TProps>> = {\n asPropHandlesRef: true,\n componentPath: module!.parent!.filename.replace('.test', ''),\n extraTests: makeStylesTests as TestObject<TProps>,\n };\n\n baseIsConformant(defaultOptions, testInfo);\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["common/isConformant.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,IAAI,gBAAzB,QAAiD,6BAAjD;AAEA,OAAO,eAAP,MAA4B,yCAA5B;AAEA,OAAM,SAAU,YAAV,CACJ,QADI,EACqF;AAEzF,MAAM,cAAc,GAAyC;AAC3D,IAAA,gBAAgB,EAAE,IADyC;AAE3D,IAAA,aAAa,EAAE,MAAO,CAAC,MAAR,CAAgB,QAAhB,CAAyB,OAAzB,CAAiC,OAAjC,EAA0C,EAA1C,CAF4C;AAG3D;AACA,IAAA,eAAe,EAAE,IAJ0C;AAK3D,IAAA,UAAU,EAAE;AAL+C,GAA7D;AAQA,EAAA,gBAAgB,CAAC,cAAD,EAAiB,QAAjB,CAAhB;AACD","sourcesContent":["import { isConformant as baseIsConformant } from '@fluentui/react-conformance';\nimport type { IsConformantOptions, TestObject } from '@fluentui/react-conformance';\nimport makeStylesTests from '@fluentui/react-conformance-make-styles';\n\nexport function isConformant<TProps = {}>(\n testInfo: Omit<IsConformantOptions<TProps>, 'componentPath'> & { componentPath?: string },\n) {\n const defaultOptions: Partial<IsConformantOptions<TProps>> = {\n asPropHandlesRef: true,\n componentPath: module!.parent!.filename.replace('.test', ''),\n // TODO // https://github.com/microsoft/fluentui/issues/19522\n skipAsPropTests: true,\n extraTests: makeStylesTests as TestObject<TProps>,\n };\n\n baseIsConformant(defaultOptions, testInfo);\n}\n"],"sourceRoot":"../src/"}
@@ -1,20 +1,15 @@
1
1
  import * as React from 'react';
2
- import type { PopperVirtualElement, PositioningShorthand } from '@fluentui/react-positioning';
2
+ import type { PopperVirtualElement, PositioningShorthand, usePopperMouseTarget } from '@fluentui/react-positioning';
3
3
  import type { PortalProps } from '@fluentui/react-portal';
4
- import type { ComponentStateCompat } from '@fluentui/react-utilities';
5
4
  /**
6
5
  * Determines popover padding and arrow size
7
6
  */
8
7
  export declare type PopoverSize = 'small' | 'medium' | 'large';
9
- /**
10
- * Popover Props
11
- */
12
- export interface PopoverProps extends Pick<PortalProps, 'mountNode'> {
13
- children: React.ReactNode;
8
+ export interface PopoverCommons extends Pick<PortalProps, 'mountNode'> {
14
9
  /**
15
10
  * Controls the opening of the Popover
16
11
  */
17
- open?: boolean;
12
+ open: boolean;
18
13
  /**
19
14
  * Used to set the initial open state of the Popover in uncontrolled mode
20
15
  */
@@ -61,21 +56,19 @@ export interface PopoverProps extends Pick<PortalProps, 'mountNode'> {
61
56
  positioning?: PositioningShorthand;
62
57
  }
63
58
  /**
64
- * Names of the shorthand properties in PopoverProps
65
- */
66
- export declare type PopoverShorthandProps = never;
67
- /**
68
- * Names of PopoverProps that have a default value in usePopover
59
+ * Popover Props
69
60
  */
70
- export declare type PopoverDefaultedProps = never;
61
+ export interface PopoverProps extends Partial<PopoverCommons> {
62
+ /**
63
+ * Can contain two children including {@link PopoverTrigger} and {@link PopoverPopover}.
64
+ * Alternatively can only contain {@link PopoverPopover} if using a custom `target`.
65
+ */
66
+ children: [JSX.Element, JSX.Element] | JSX.Element;
67
+ }
71
68
  /**
72
69
  * Popover State
73
70
  */
74
- export interface PopoverState extends ComponentStateCompat<PopoverProps, PopoverShorthandProps, PopoverDefaultedProps> {
75
- /**
76
- * Open state of the Popover
77
- */
78
- open: boolean;
71
+ export interface PopoverState extends PopoverCommons, Pick<PopoverProps, 'children'> {
79
72
  /**
80
73
  * Callback to open/close the Popover
81
74
  */
@@ -99,7 +92,7 @@ export interface PopoverState extends ComponentStateCompat<PopoverProps, Popover
99
92
  /**
100
93
  * A callback to set the target of the popper to the mouse click for context events
101
94
  */
102
- setContextTarget: React.Dispatch<PopperVirtualElement | undefined>;
95
+ setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];
103
96
  size: NonNullable<PopoverProps['size']>;
104
97
  }
105
98
  /**
@@ -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 } from '@fluentui/react-positioning';\nimport type { PortalProps } from '@fluentui/react-portal';\nimport type { ComponentStateCompat } from '@fluentui/react-utilities';\n\n/**\n * Determines popover padding and arrow size\n */\nexport type PopoverSize = 'small' | 'medium' | 'large';\n\n/**\n * Popover Props\n */\nexport interface PopoverProps extends Pick<PortalProps, 'mountNode'> {\n children: React.ReactNode;\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 * Uses brand colour as background\n * Mutually exclusive with `inverted`\n */\n brand?: boolean;\n /**\n * Inverts the foreground/background colour of the popover\n * Mutually exclusive with `brand`\n */\n inverted?: boolean;\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 * Names of the shorthand properties in PopoverProps\n */\nexport type PopoverShorthandProps = never;\n\n/**\n * Names of PopoverProps that have a default value in usePopover\n */\nexport type PopoverDefaultedProps = never;\n\n/**\n * Popover State\n */\nexport interface PopoverState extends ComponentStateCompat<PopoverProps, PopoverShorthandProps, PopoverDefaultedProps> {\n /**\n * Open state of the Popover\n */\n open: boolean;\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: React.Dispatch<PopperVirtualElement | undefined>;\n\n size: NonNullable<PopoverProps['size']>;\n}\n\n/**\n * Data attached to open/close events\n */\nexport interface OnOpenChangeData extends Pick<PopoverState, 'open'> {}\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 { 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\nexport interface PopoverCommons extends 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 * Uses brand colour as background\n * Mutually exclusive with `inverted`\n */\n brand?: boolean;\n /**\n * Inverts the foreground/background colour of the popover\n * Mutually exclusive with `brand`\n */\n inverted?: boolean;\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 interface PopoverProps extends Partial<PopoverCommons> {\n /**\n * Can contain two children including {@link PopoverTrigger} and {@link PopoverPopover}.\n * Alternatively can only contain {@link PopoverPopover} if using a custom `target`.\n */\n children: [JSX.Element, JSX.Element] | JSX.Element;\n}\n\n/**\n * Popover State\n */\nexport interface PopoverState extends PopoverCommons, 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 interface OnOpenChangeData extends Pick<PopoverState, 'open'> {}\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,15 +1,10 @@
1
1
  import { __assign } from "tslib";
2
2
  import * as React from 'react';
3
- import { makeMergeProps, useControllableValue, useEventCallback, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
3
+ import { useControllableState, useEventCallback, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
4
4
  import { useFluent } from '@fluentui/react-shared-contexts';
5
- import { usePopper, createVirtualElementFromClick, resolvePositioningShorthand, mergeArrowOffset } from '@fluentui/react-positioning';
5
+ import { usePopper, resolvePositioningShorthand, mergeArrowOffset, usePopperMouseTarget } from '@fluentui/react-positioning';
6
6
  import { elementContains } from '@fluentui/react-portal';
7
7
  import { arrowHeights } from '../PopoverSurface/index';
8
- /**
9
- * Names of the shorthand properties in PopoverProps
10
- */
11
-
12
- var mergeProps = /*#__PURE__*/makeMergeProps({});
13
8
  /**
14
9
  * Create the state required to render Popover.
15
10
  *
@@ -21,60 +16,49 @@ var mergeProps = /*#__PURE__*/makeMergeProps({});
21
16
  */
22
17
 
23
18
  export var usePopover = function (props, defaultProps) {
24
- var state = mergeProps({
25
- size: 'medium',
26
- open: undefined,
27
- setOpen: function () {
28
- return null;
29
- },
30
- triggerRef: {
31
- current: null
32
- },
33
- contentRef: {
34
- current: null
35
- },
36
- arrowRef: {
37
- current: null
38
- },
39
- children: null,
40
- setContextTarget: function () {
41
- return null;
42
- },
43
- contextTarget: undefined
44
- }, defaultProps, props);
45
-
46
- var _a = React.useState(),
19
+ var _a = usePopperMouseTarget(),
47
20
  contextTarget = _a[0],
48
21
  setContextTarget = _a[1];
49
22
 
50
- state.setContextTarget = setContextTarget;
51
- state.contextTarget = contextTarget;
52
- useOpenState(state);
53
- usePopoverRefs(state);
23
+ var initialState = __assign({
24
+ size: 'medium',
25
+ contextTarget: contextTarget,
26
+ setContextTarget: setContextTarget
27
+ }, props);
28
+
29
+ var _b = useOpenState(initialState),
30
+ open = _b[0],
31
+ setOpen = _b[1];
32
+
33
+ var popperRefs = usePopoverRefs(initialState);
54
34
  var targetDocument = useFluent().targetDocument;
55
35
  useOnClickOutside({
56
36
  contains: elementContains,
57
37
  element: targetDocument,
58
38
  callback: function (ev) {
59
- return state.setOpen(ev, false);
39
+ return setOpen(ev, false);
60
40
  },
61
- refs: [state.triggerRef, state.contentRef],
62
- disabled: !state.open
41
+ refs: [popperRefs.triggerRef, popperRefs.contentRef],
42
+ disabled: !open
63
43
  });
64
44
  useOnScrollOutside({
65
45
  contains: elementContains,
66
46
  element: targetDocument,
67
47
  callback: function (ev) {
68
- return state.setOpen(ev, false);
48
+ return setOpen(ev, false);
69
49
  },
70
- refs: [state.triggerRef, state.contentRef],
71
- disabled: !state.open || !state.openOnContext
50
+ refs: [popperRefs.triggerRef, popperRefs.contentRef],
51
+ disabled: !open || !initialState.openOnContext
52
+ });
53
+ return __assign(__assign(__assign({}, initialState), popperRefs), {
54
+ open: open,
55
+ setOpen: setOpen,
56
+ setContextTarget: setContextTarget,
57
+ contextTarget: contextTarget
72
58
  });
73
- return state;
74
59
  };
75
60
  /**
76
61
  * Creates and manages the Popover open state
77
- * @param state Popover state
78
62
  */
79
63
 
80
64
  function useOpenState(state) {
@@ -84,23 +68,26 @@ function useOpenState(state) {
84
68
  return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
85
69
  });
86
70
 
87
- var _a = useControllableValue(state.open, state.defaultOpen),
71
+ var _a = useControllableState({
72
+ state: state.open,
73
+ defaultState: state.defaultOpen,
74
+ initialState: false
75
+ }),
88
76
  open = _a[0],
89
- setOpen = _a[1];
77
+ setOpenState = _a[1];
90
78
 
91
79
  state.open = open !== undefined ? open : state.open;
92
80
  var setContextTarget = state.setContextTarget;
93
- state.setOpen = React.useCallback(function (e, shouldOpen) {
81
+ var setOpen = React.useCallback(function (e, shouldOpen) {
94
82
  if (shouldOpen && e.type === 'contextmenu') {
95
- var virtualElement = createVirtualElementFromClick(e.nativeEvent);
96
- setContextTarget(virtualElement);
83
+ setContextTarget(e);
97
84
  }
98
85
 
99
86
  if (!shouldOpen) {
100
87
  setContextTarget(undefined);
101
88
  }
102
89
 
103
- setOpen(function (prevOpen) {
90
+ setOpenState(function (prevOpen) {
104
91
  // More than one event (mouse, focus, keyboard) can request the Popover to close
105
92
  // We assume the first event is the correct one
106
93
  if (prevOpen !== shouldOpen) {
@@ -111,12 +98,11 @@ function useOpenState(state) {
111
98
 
112
99
  return shouldOpen;
113
100
  });
114
- }, [setOpen, onOpenChange, setContextTarget]);
115
- return state;
101
+ }, [setOpenState, onOpenChange, setContextTarget]);
102
+ return [open, setOpen];
116
103
  }
117
104
  /**
118
105
  * Creates and sets the necessary trigger, target and content refs used by Popover
119
- * @param state Popover state
120
106
  */
121
107
 
122
108
 
@@ -141,9 +127,10 @@ function usePopoverRefs(state) {
141
127
  contentRef = _a.containerRef,
142
128
  arrowRef = _a.arrowRef;
143
129
 
144
- state.contentRef = contentRef;
145
- state.triggerRef = triggerRef;
146
- state.arrowRef = arrowRef;
147
- return state;
130
+ return {
131
+ triggerRef: triggerRef,
132
+ contentRef: contentRef,
133
+ arrowRef: arrowRef
134
+ };
148
135
  }
149
136
  //# sourceMappingURL=usePopover.js.map