@fluentui/react-popover 9.0.0-alpha.8 → 9.0.0-nightly.f81b28ceb3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. package/CHANGELOG.json +1800 -1
  2. package/CHANGELOG.md +566 -2
  3. package/Spec.md +6 -6
  4. package/dist/react-popover.d.ts +59 -77
  5. package/lib/Popover.js.map +1 -1
  6. package/lib/PopoverSurface.js.map +1 -1
  7. package/lib/PopoverTrigger.js.map +1 -1
  8. package/lib/common/isConformant.d.ts +1 -1
  9. package/lib/common/isConformant.js +9 -5
  10. package/lib/common/isConformant.js.map +1 -1
  11. package/lib/common/mockUsePopoverContext.d.ts +1 -1
  12. package/lib/common/mockUsePopoverContext.js +28 -6
  13. package/lib/common/mockUsePopoverContext.js.map +1 -1
  14. package/lib/components/Popover/Popover.d.ts +2 -2
  15. package/lib/components/Popover/Popover.js +4 -3
  16. package/lib/components/Popover/Popover.js.map +1 -1
  17. package/lib/components/Popover/Popover.types.d.ts +24 -33
  18. package/lib/components/Popover/Popover.types.js.map +1 -1
  19. package/lib/components/Popover/index.js.map +1 -1
  20. package/lib/components/Popover/renderPopover.d.ts +1 -1
  21. package/lib/components/Popover/renderPopover.js +29 -17
  22. package/lib/components/Popover/renderPopover.js.map +1 -1
  23. package/lib/components/Popover/usePopover.d.ts +2 -3
  24. package/lib/components/Popover/usePopover.js +110 -88
  25. package/lib/components/Popover/usePopover.js.map +1 -1
  26. package/lib/components/PopoverSurface/PopoverSurface.d.ts +3 -3
  27. package/lib/components/PopoverSurface/PopoverSurface.js +5 -4
  28. package/lib/components/PopoverSurface/PopoverSurface.js.map +1 -1
  29. package/lib/components/PopoverSurface/PopoverSurface.types.d.ts +9 -18
  30. package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
  31. package/lib/components/PopoverSurface/index.js.map +1 -1
  32. package/lib/components/PopoverSurface/renderPopoverSurface.d.ts +1 -1
  33. package/lib/components/PopoverSurface/renderPopoverSurface.js +18 -10
  34. package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
  35. package/lib/components/PopoverSurface/usePopoverSurface.d.ts +4 -4
  36. package/lib/components/PopoverSurface/usePopoverSurface.js +94 -54
  37. package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -1
  38. package/lib/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +2 -2
  39. package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +88 -64
  40. package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
  41. package/lib/components/PopoverTrigger/PopoverTrigger.d.ts +2 -2
  42. package/lib/components/PopoverTrigger/PopoverTrigger.js +4 -3
  43. package/lib/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
  44. package/lib/components/PopoverTrigger/PopoverTrigger.types.d.ts +3 -4
  45. package/lib/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -1
  46. package/lib/components/PopoverTrigger/index.js.map +1 -1
  47. package/lib/components/PopoverTrigger/renderPopoverTrigger.d.ts +1 -1
  48. package/lib/components/PopoverTrigger/renderPopoverTrigger.js +1 -1
  49. package/lib/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
  50. package/lib/components/PopoverTrigger/usePopoverTrigger.d.ts +2 -3
  51. package/lib/components/PopoverTrigger/usePopoverTrigger.js +83 -60
  52. package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
  53. package/lib/index.js.map +1 -1
  54. package/lib/popoverContext.d.ts +4 -5
  55. package/lib/popoverContext.js +19 -12
  56. package/lib/popoverContext.js.map +1 -1
  57. package/lib/tsdoc-metadata.json +1 -1
  58. package/lib-commonjs/Popover.js +7 -2
  59. package/lib-commonjs/Popover.js.map +1 -1
  60. package/lib-commonjs/PopoverSurface.js +7 -2
  61. package/lib-commonjs/PopoverSurface.js.map +1 -1
  62. package/lib-commonjs/PopoverTrigger.js +7 -2
  63. package/lib-commonjs/PopoverTrigger.js.map +1 -1
  64. package/lib-commonjs/common/isConformant.d.ts +1 -1
  65. package/lib-commonjs/common/isConformant.js +18 -7
  66. package/lib-commonjs/common/isConformant.js.map +1 -1
  67. package/lib-commonjs/common/mockUsePopoverContext.d.ts +1 -1
  68. package/lib-commonjs/common/mockUsePopoverContext.js +38 -9
  69. package/lib-commonjs/common/mockUsePopoverContext.js.map +1 -1
  70. package/lib-commonjs/components/Popover/Popover.d.ts +2 -2
  71. package/lib-commonjs/components/Popover/Popover.js +14 -6
  72. package/lib-commonjs/components/Popover/Popover.js.map +1 -1
  73. package/lib-commonjs/components/Popover/Popover.types.d.ts +24 -33
  74. package/lib-commonjs/components/Popover/Popover.types.js +4 -1
  75. package/lib-commonjs/components/Popover/Popover.types.js.map +1 -1
  76. package/lib-commonjs/components/Popover/index.js +10 -2
  77. package/lib-commonjs/components/Popover/index.js.map +1 -1
  78. package/lib-commonjs/components/Popover/renderPopover.d.ts +1 -1
  79. package/lib-commonjs/components/Popover/renderPopover.js +39 -20
  80. package/lib-commonjs/components/Popover/renderPopover.js.map +1 -1
  81. package/lib-commonjs/components/Popover/usePopover.d.ts +2 -3
  82. package/lib-commonjs/components/Popover/usePopover.js +127 -93
  83. package/lib-commonjs/components/Popover/usePopover.js.map +1 -1
  84. package/lib-commonjs/components/PopoverSurface/PopoverSurface.d.ts +3 -3
  85. package/lib-commonjs/components/PopoverSurface/PopoverSurface.js +18 -9
  86. package/lib-commonjs/components/PopoverSurface/PopoverSurface.js.map +1 -1
  87. package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.d.ts +9 -18
  88. package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.js +4 -1
  89. package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
  90. package/lib-commonjs/components/PopoverSurface/index.js +11 -2
  91. package/lib-commonjs/components/PopoverSurface/index.js.map +1 -1
  92. package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.d.ts +1 -1
  93. package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +32 -14
  94. package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
  95. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.d.ts +4 -4
  96. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +110 -60
  97. package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -1
  98. package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +2 -2
  99. package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +95 -65
  100. package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
  101. package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.d.ts +2 -2
  102. package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js +14 -6
  103. package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
  104. package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.d.ts +3 -4
  105. package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.js +4 -1
  106. package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -1
  107. package/lib-commonjs/components/PopoverTrigger/index.js +10 -2
  108. package/lib-commonjs/components/PopoverTrigger/index.js.map +1 -1
  109. package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.d.ts +1 -1
  110. package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js +7 -2
  111. package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
  112. package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.d.ts +2 -3
  113. package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +98 -65
  114. package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
  115. package/lib-commonjs/index.js +10 -2
  116. package/lib-commonjs/index.js.map +1 -1
  117. package/lib-commonjs/popoverContext.d.ts +4 -5
  118. package/lib-commonjs/popoverContext.js +28 -14
  119. package/lib-commonjs/popoverContext.js.map +1 -1
  120. package/package.json +18 -15
  121. package/.storybook/main.js +0 -11
  122. package/.storybook/preview.js +0 -4
  123. package/bundle-size/Popover.fixture.js +0 -7
  124. package/config/api-extractor.json +0 -3
  125. package/config/tests.js +0 -7
  126. package/e2e/Popover.e2e.ts +0 -139
  127. package/etc/react-popover.api.md +0 -135
  128. package/just.config.ts +0 -3
  129. package/lib/Popover.stories.d.ts +0 -62
  130. package/lib/Popover.stories.js +0 -114
  131. package/lib/Popover.stories.js.map +0 -1
  132. package/lib/components/Popover/getOffsetWithArrow.d.ts +0 -7
  133. package/lib/components/Popover/getOffsetWithArrow.js +0 -34
  134. package/lib/components/Popover/getOffsetWithArrow.js.map +0 -1
  135. package/lib-amd/Popover.d.ts +0 -1
  136. package/lib-amd/Popover.js +0 -6
  137. package/lib-amd/Popover.js.map +0 -1
  138. package/lib-amd/Popover.stories.d.ts +0 -62
  139. package/lib-amd/Popover.stories.js +0 -121
  140. package/lib-amd/Popover.stories.js.map +0 -1
  141. package/lib-amd/PopoverSurface.d.ts +0 -1
  142. package/lib-amd/PopoverSurface.js +0 -6
  143. package/lib-amd/PopoverSurface.js.map +0 -1
  144. package/lib-amd/PopoverTrigger.d.ts +0 -1
  145. package/lib-amd/PopoverTrigger.js +0 -6
  146. package/lib-amd/PopoverTrigger.js.map +0 -1
  147. package/lib-amd/common/isConformant.d.ts +0 -4
  148. package/lib-amd/common/isConformant.js +0 -14
  149. package/lib-amd/common/isConformant.js.map +0 -1
  150. package/lib-amd/common/mockUsePopoverContext.d.ts +0 -7
  151. package/lib-amd/common/mockUsePopoverContext.js +0 -20
  152. package/lib-amd/common/mockUsePopoverContext.js.map +0 -1
  153. package/lib-amd/components/Popover/Popover.d.ts +0 -6
  154. package/lib-amd/components/Popover/Popover.js +0 -15
  155. package/lib-amd/components/Popover/Popover.js.map +0 -1
  156. package/lib-amd/components/Popover/Popover.types.d.ts +0 -109
  157. package/lib-amd/components/Popover/Popover.types.js +0 -5
  158. package/lib-amd/components/Popover/Popover.types.js.map +0 -1
  159. package/lib-amd/components/Popover/getOffsetWithArrow.d.ts +0 -7
  160. package/lib-amd/components/Popover/getOffsetWithArrow.js +0 -40
  161. package/lib-amd/components/Popover/getOffsetWithArrow.js.map +0 -1
  162. package/lib-amd/components/Popover/index.d.ts +0 -4
  163. package/lib-amd/components/Popover/index.js +0 -9
  164. package/lib-amd/components/Popover/index.js.map +0 -1
  165. package/lib-amd/components/Popover/renderPopover.d.ts +0 -5
  166. package/lib-amd/components/Popover/renderPopover.js +0 -29
  167. package/lib-amd/components/Popover/renderPopover.js.map +0 -1
  168. package/lib-amd/components/Popover/usePopover.d.ts +0 -11
  169. package/lib-amd/components/Popover/usePopover.js +0 -112
  170. package/lib-amd/components/Popover/usePopover.js.map +0 -1
  171. package/lib-amd/components/PopoverSurface/PopoverSurface.d.ts +0 -6
  172. package/lib-amd/components/PopoverSurface/PopoverSurface.js +0 -15
  173. package/lib-amd/components/PopoverSurface/PopoverSurface.js.map +0 -1
  174. package/lib-amd/components/PopoverSurface/PopoverSurface.types.d.ts +0 -30
  175. package/lib-amd/components/PopoverSurface/PopoverSurface.types.js +0 -5
  176. package/lib-amd/components/PopoverSurface/PopoverSurface.types.js.map +0 -1
  177. package/lib-amd/components/PopoverSurface/index.d.ts +0 -5
  178. package/lib-amd/components/PopoverSurface/index.js +0 -10
  179. package/lib-amd/components/PopoverSurface/index.js.map +0 -1
  180. package/lib-amd/components/PopoverSurface/renderPopoverSurface.d.ts +0 -5
  181. package/lib-amd/components/PopoverSurface/renderPopoverSurface.js +0 -21
  182. package/lib-amd/components/PopoverSurface/renderPopoverSurface.js.map +0 -1
  183. package/lib-amd/components/PopoverSurface/usePopoverSurface.d.ts +0 -13
  184. package/lib-amd/components/PopoverSurface/usePopoverSurface.js +0 -69
  185. package/lib-amd/components/PopoverSurface/usePopoverSurface.js.map +0 -1
  186. package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +0 -7
  187. package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js +0 -81
  188. package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js.map +0 -1
  189. package/lib-amd/components/PopoverTrigger/PopoverTrigger.d.ts +0 -6
  190. package/lib-amd/components/PopoverTrigger/PopoverTrigger.js +0 -15
  191. package/lib-amd/components/PopoverTrigger/PopoverTrigger.js.map +0 -1
  192. package/lib-amd/components/PopoverTrigger/PopoverTrigger.types.d.ts +0 -12
  193. package/lib-amd/components/PopoverTrigger/PopoverTrigger.types.js +0 -5
  194. package/lib-amd/components/PopoverTrigger/PopoverTrigger.types.js.map +0 -1
  195. package/lib-amd/components/PopoverTrigger/index.d.ts +0 -4
  196. package/lib-amd/components/PopoverTrigger/index.js +0 -9
  197. package/lib-amd/components/PopoverTrigger/index.js.map +0 -1
  198. package/lib-amd/components/PopoverTrigger/renderPopoverTrigger.d.ts +0 -5
  199. package/lib-amd/components/PopoverTrigger/renderPopoverTrigger.js +0 -13
  200. package/lib-amd/components/PopoverTrigger/renderPopoverTrigger.js.map +0 -1
  201. package/lib-amd/components/PopoverTrigger/usePopoverTrigger.d.ts +0 -11
  202. package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js +0 -75
  203. package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js.map +0 -1
  204. package/lib-amd/index.d.ts +0 -4
  205. package/lib-amd/index.js +0 -9
  206. package/lib-amd/index.js.map +0 -1
  207. package/lib-amd/popoverContext.d.ts +0 -9
  208. package/lib-amd/popoverContext.js +0 -22
  209. package/lib-amd/popoverContext.js.map +0 -1
  210. package/lib-commonjs/Popover.stories.d.ts +0 -62
  211. package/lib-commonjs/Popover.stories.js +0 -122
  212. package/lib-commonjs/Popover.stories.js.map +0 -1
  213. package/lib-commonjs/components/Popover/getOffsetWithArrow.d.ts +0 -7
  214. package/lib-commonjs/components/Popover/getOffsetWithArrow.js +0 -38
  215. package/lib-commonjs/components/Popover/getOffsetWithArrow.js.map +0 -1
  216. package/src/components/Popover/Popover.types.ts +0 -124
  217. package/src/components/PopoverSurface/PopoverSurface.types.ts +0 -36
  218. package/src/components/PopoverTrigger/PopoverTrigger.types.ts +0 -13
@@ -1,14 +1,10 @@
1
+ import { __assign } from "tslib";
1
2
  import * as React from 'react';
2
- import { makeMergeProps, useControllableValue, useEventCallback, useOnClickOutside, useOnScrollOutside, } from '@fluentui/react-utilities';
3
+ import { useControllableState, useEventCallback, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
3
4
  import { useFluent } from '@fluentui/react-shared-contexts';
4
- import { usePopper, createVirtualElementFromClick } from '@fluentui/react-positioning';
5
+ import { usePopper, resolvePositioningShorthand, mergeArrowOffset, usePopperMouseTarget } from '@fluentui/react-positioning';
5
6
  import { elementContains } from '@fluentui/react-portal';
6
7
  import { arrowHeights } from '../PopoverSurface/index';
7
- import { getOffsetWithArrow } from './getOffsetWithArrow';
8
- /**
9
- * Names of the shorthand properties in PopoverProps
10
- */
11
- var mergeProps = makeMergeProps({});
12
8
  /**
13
9
  * Create the state required to render Popover.
14
10
  *
@@ -16,98 +12,124 @@ var mergeProps = makeMergeProps({});
16
12
  * before being passed to renderPopover.
17
13
  *
18
14
  * @param props - props from this instance of Popover
19
- * @param defaultProps - (optional) default prop values provided by the implementing type
20
15
  */
21
- export var usePopover = function (props, defaultProps) {
22
- var state = mergeProps({
23
- size: 'medium',
24
- open: undefined,
25
- setOpen: function () { return null; },
26
- triggerRef: { current: null },
27
- contentRef: { current: null },
28
- arrowRef: { current: null },
29
- children: null,
30
- position: 'above',
31
- align: 'center',
32
- setContextTarget: function () { return null; },
33
- contextTarget: undefined,
34
- }, defaultProps, props);
35
- // no reason to render arrow when covering the target
36
- if (state.coverTarget) {
37
- state.noArrow = true;
38
- }
39
- var _a = React.useState(), contextTarget = _a[0], setContextTarget = _a[1];
40
- state.setContextTarget = setContextTarget;
41
- state.contextTarget = contextTarget;
42
- useOpenState(state);
43
- usePopoverRefs(state);
44
- var targetDocument = useFluent().targetDocument;
45
- useOnClickOutside({
46
- contains: elementContains,
47
- element: targetDocument,
48
- callback: function (ev) { return state.setOpen(ev, false); },
49
- refs: [state.triggerRef, state.contentRef],
50
- disabled: !state.open,
51
- });
52
- useOnScrollOutside({
53
- contains: elementContains,
54
- element: targetDocument,
55
- callback: function (ev) { return state.setOpen(ev, false); },
56
- refs: [state.triggerRef, state.contentRef],
57
- disabled: !state.open || !state.openOnContext,
58
- });
59
- return state;
16
+
17
+ export var usePopover = function (props) {
18
+ var _a = usePopperMouseTarget(),
19
+ contextTarget = _a[0],
20
+ setContextTarget = _a[1];
21
+
22
+ var initialState = __assign({
23
+ size: 'medium',
24
+ contextTarget: contextTarget,
25
+ setContextTarget: setContextTarget
26
+ }, props);
27
+
28
+ var _b = useOpenState(initialState),
29
+ open = _b[0],
30
+ setOpen = _b[1];
31
+
32
+ var popperRefs = usePopoverRefs(initialState);
33
+ var targetDocument = useFluent().targetDocument;
34
+ useOnClickOutside({
35
+ contains: elementContains,
36
+ element: targetDocument,
37
+ callback: function (ev) {
38
+ return setOpen(ev, false);
39
+ },
40
+ refs: [popperRefs.triggerRef, popperRefs.contentRef],
41
+ disabled: !open
42
+ });
43
+ useOnScrollOutside({
44
+ contains: elementContains,
45
+ element: targetDocument,
46
+ callback: function (ev) {
47
+ return setOpen(ev, false);
48
+ },
49
+ refs: [popperRefs.triggerRef, popperRefs.contentRef],
50
+ disabled: !open || !initialState.openOnContext
51
+ });
52
+ return __assign(__assign(__assign({}, initialState), popperRefs), {
53
+ open: open,
54
+ setOpen: setOpen,
55
+ setContextTarget: setContextTarget,
56
+ contextTarget: contextTarget
57
+ });
60
58
  };
61
59
  /**
62
60
  * Creates and manages the Popover open state
63
- * @param state Popover state
64
61
  */
62
+
65
63
  function useOpenState(state) {
66
- var onOpenChange = useEventCallback(function (e, data) { var _a; return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data); });
67
- var _a = useControllableValue(state.open, state.defaultOpen), open = _a[0], setOpen = _a[1];
68
- state.open = open !== undefined ? open : state.open;
69
- var setContextTarget = state.setContextTarget;
70
- state.setOpen = React.useCallback(function (e, shouldOpen) {
71
- if (shouldOpen && e.type === 'contextmenu') {
72
- var virtualElement = createVirtualElementFromClick(e.nativeEvent);
73
- setContextTarget(virtualElement);
74
- }
75
- if (!shouldOpen) {
76
- setContextTarget(undefined);
77
- }
78
- setOpen(function (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, { open: shouldOpen });
83
- }
84
- return shouldOpen;
64
+ var onOpenChange = useEventCallback(function (e, data) {
65
+ var _a;
66
+
67
+ return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
68
+ });
69
+
70
+ var _a = useControllableState({
71
+ state: state.open,
72
+ defaultState: state.defaultOpen,
73
+ initialState: false
74
+ }),
75
+ open = _a[0],
76
+ setOpenState = _a[1];
77
+
78
+ state.open = open !== undefined ? open : state.open;
79
+ var setContextTarget = state.setContextTarget;
80
+ var setOpen = React.useCallback(function (e, shouldOpen) {
81
+ if (shouldOpen && e.type === 'contextmenu') {
82
+ setContextTarget(e);
83
+ }
84
+
85
+ if (!shouldOpen) {
86
+ setContextTarget(undefined);
87
+ }
88
+
89
+ setOpenState(function (prevOpen) {
90
+ // More than one event (mouse, focus, keyboard) can request the Popover to close
91
+ // We assume the first event is the correct one
92
+ if (prevOpen !== shouldOpen) {
93
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(e, {
94
+ open: shouldOpen
85
95
  });
86
- }, [setOpen, onOpenChange, setContextTarget]);
87
- return state;
96
+ }
97
+
98
+ return shouldOpen;
99
+ });
100
+ }, [setOpenState, onOpenChange, setContextTarget]);
101
+ return [open, setOpen];
88
102
  }
89
103
  /**
90
104
  * Creates and sets the necessary trigger, target and content refs used by Popover
91
- * @param state Popover state
92
105
  */
106
+
107
+
93
108
  function usePopoverRefs(state) {
94
- if (!state.noArrow) {
95
- state.offset = getOffsetWithArrow(state.offset, arrowHeights[state.size]);
96
- }
97
- if (!state.target && state.openOnContext && state.contextTarget) {
98
- state.target = state.contextTarget;
99
- }
100
- var _a = usePopper({
101
- align: state.align,
102
- position: state.position,
103
- target: state.target,
104
- coverTarget: state.coverTarget,
105
- offset: state.offset,
106
- arrowPadding: arrowHeights[state.size],
107
- }), triggerRef = _a.targetRef, contentRef = _a.containerRef, arrowRef = _a.arrowRef;
108
- state.contentRef = contentRef;
109
- state.triggerRef = triggerRef;
110
- state.arrowRef = arrowRef;
111
- return state;
109
+ var popperOptions = __assign({
110
+ position: 'above',
111
+ align: 'center',
112
+ target: state.openOnContext ? state.contextTarget : undefined
113
+ }, resolvePositioningShorthand(state.positioning)); // no reason to render arrow when covering the target
114
+
115
+
116
+ if (popperOptions.coverTarget) {
117
+ state.noArrow = true;
118
+ }
119
+
120
+ if (!state.noArrow) {
121
+ popperOptions.offset = mergeArrowOffset(popperOptions.offset, arrowHeights[state.size]);
122
+ }
123
+
124
+ var _a = usePopper(popperOptions),
125
+ triggerRef = _a.targetRef,
126
+ contentRef = _a.containerRef,
127
+ arrowRef = _a.arrowRef;
128
+
129
+ return {
130
+ triggerRef: triggerRef,
131
+ contentRef: contentRef,
132
+ arrowRef: arrowRef
133
+ };
112
134
  }
113
135
  //# sourceMappingURL=usePopover.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePopover.js","sourceRoot":"../src/","sources":["components/Popover/usePopover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAwB,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAC7G,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EA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AAK,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAE1B,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import * as React from 'react';\nimport {\n makeMergeProps,\n useControllableValue,\n useEventCallback,\n useOnClickOutside,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent } from '@fluentui/react-shared-contexts';\nimport { usePopper, PopperVirtualElement, createVirtualElementFromClick } from '@fluentui/react-positioning';\nimport { elementContains } from '@fluentui/react-portal';\nimport { PopoverProps, PopoverState } from './Popover.types';\nimport { arrowHeights } from '../PopoverSurface/index';\nimport { getOffsetWithArrow } from './getOffsetWithArrow';\n\n/**\n * Names of the shorthand properties in PopoverProps\n */\nconst mergeProps = makeMergeProps<PopoverState>({});\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.\n *\n * @param props - props from this instance of Popover\n * @param defaultProps - (optional) default prop values provided by the implementing type\n */\nexport const usePopover = (props: PopoverProps, defaultProps?: PopoverProps): PopoverState => {\n const state = mergeProps(\n {\n size: 'medium',\n open: (undefined as unknown) as boolean, // mergeProps typings require this\n setOpen: () => null,\n triggerRef: { current: null },\n contentRef: { current: null },\n arrowRef: { current: null },\n children: null,\n position: 'above',\n align: 'center',\n setContextTarget: () => null,\n contextTarget: undefined,\n },\n defaultProps,\n props,\n );\n\n // no reason to render arrow when covering the target\n if (state.coverTarget) {\n state.noArrow = true;\n }\n\n const [contextTarget, setContextTarget] = React.useState<PopperVirtualElement>();\n state.setContextTarget = setContextTarget;\n state.contextTarget = contextTarget;\n\n useOpenState(state);\n usePopoverRefs(state);\n\n const { targetDocument } = useFluent();\n useOnClickOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => state.setOpen(ev, false),\n refs: [state.triggerRef, state.contentRef],\n disabled: !state.open,\n });\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => state.setOpen(ev, false),\n refs: [state.triggerRef, state.contentRef],\n disabled: !state.open || !state.openOnContext,\n });\n\n return state;\n};\n\n/**\n * Creates and manages the Popover open state\n * @param state Popover state\n */\nfunction useOpenState(state: PopoverState): PopoverState {\n const onOpenChange: PopoverState['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const [open, setOpen] = useControllableValue(state.open, state.defaultOpen);\n state.open = open !== undefined ? open : state.open;\n const setContextTarget = state.setContextTarget;\n\n state.setOpen = React.useCallback(\n (e, shouldOpen) => {\n if (shouldOpen && e.type === 'contextmenu') {\n const virtualElement = createVirtualElementFromClick((e as React.MouseEvent).nativeEvent);\n setContextTarget(virtualElement);\n }\n\n if (!shouldOpen) {\n setContextTarget(undefined);\n }\n\n setOpen(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 [setOpen, onOpenChange, setContextTarget],\n );\n\n return state;\n}\n\n/**\n * Creates and sets the necessary trigger, target and content refs used by Popover\n * @param state Popover state\n */\nfunction usePopoverRefs(state: PopoverState): PopoverState {\n if (!state.noArrow) {\n state.offset = getOffsetWithArrow(state.offset, arrowHeights[state.size]);\n }\n\n if (!state.target && state.openOnContext && state.contextTarget) {\n state.target = state.contextTarget;\n }\n\n const { targetRef: triggerRef, containerRef: contentRef, arrowRef } = usePopper({\n align: state.align,\n position: state.position,\n target: state.target,\n coverTarget: state.coverTarget,\n offset: state.offset,\n arrowPadding: arrowHeights[state.size],\n });\n\n state.contentRef = contentRef;\n state.triggerRef = triggerRef;\n state.arrowRef = arrowRef;\n\n return state;\n}\n"]}
1
+ {"version":3,"sources":["../../../src/components/Popover/usePopover.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SACE,oBADF,EAEE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,CAAC,KAAK,CAAC,IAAP,CAAnC,CAAvC;AACD;;AAEK,MAAA,EAAA,GAAgE,SAAS,CAAC,aAAD,CAAzE;AAAA,MAAa,UAAU,GAAA,EAAA,CAAA,SAAvB;AAAA,MAAuC,UAAU,GAAA,EAAA,CAAA,YAAjD;AAAA,MAAmD,QAAQ,GAAA,EAAA,CAAA,QAA3D;;AAEN,SAAO;AACL,IAAA,UAAU,EAAA,UADL;AAEL,IAAA,UAAU,EAAA,UAFL;AAGL,IAAA,QAAQ,EAAA;AAHH,GAAP;AAKD","sourceRoot":""}
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import { PopoverSurfaceProps } from './PopoverSurface.types';
1
+ import type { PopoverSurfaceProps } from './PopoverSurface.types';
2
+ import type { ForwardRefComponent } from '@fluentui/react-utilities';
3
3
  /**
4
4
  * PopoverSurface component renders react children in a positioned box
5
5
  */
6
- export declare const PopoverSurface: React.ForwardRefExoticComponent<PopoverSurfaceProps & React.RefAttributes<HTMLElement>>;
6
+ export declare const PopoverSurface: ForwardRefComponent<PopoverSurfaceProps>;
@@ -5,10 +5,11 @@ import { usePopoverSurfaceStyles } from './usePopoverSurfaceStyles';
5
5
  /**
6
6
  * PopoverSurface component renders react children in a positioned box
7
7
  */
8
- export var PopoverSurface = React.forwardRef(function (props, ref) {
9
- var state = usePopoverSurface(props, ref);
10
- usePopoverSurfaceStyles(state);
11
- return renderPopoverSurface(state);
8
+
9
+ export var PopoverSurface = /*#__PURE__*/React.forwardRef(function (props, ref) {
10
+ var state = usePopoverSurface(props, ref);
11
+ usePopoverSurfaceStyles(state);
12
+ return renderPopoverSurface(state);
12
13
  });
13
14
  PopoverSurface.displayName = 'PopoverSurface';
14
15
  //# sourceMappingURL=PopoverSurface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,IAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAAmC,UAAC,KAAK,EAAE,GAAG;IAC1F,IAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE5C,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEH,cAAc,CAAC,WAAW,GAAG,gBAAgB,CAAC","sourcesContent":["import * as React from 'react';\nimport { usePopoverSurface } from './usePopoverSurface';\nimport { PopoverSurfaceProps } from './PopoverSurface.types';\nimport { renderPopoverSurface } from './renderPopoverSurface';\nimport { usePopoverSurfaceStyles } from './usePopoverSurfaceStyles';\n\n/**\n * PopoverSurface component renders react children in a positioned box\n */\nexport const PopoverSurface = React.forwardRef<HTMLElement, PopoverSurfaceProps>((props, ref) => {\n const state = usePopoverSurface(props, ref);\n\n usePopoverSurfaceStyles(state);\n return renderPopoverSurface(state);\n});\n\nPopoverSurface.displayName = 'PopoverSurface';\n"]}
1
+ {"version":3,"sources":["../../../src/components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,iBAAT,QAAkC,qBAAlC;AACA,SAAS,oBAAT,QAAqC,wBAArC;AACA,SAAS,uBAAT,QAAwC,2BAAxC;AAIA;;AAEG;;AACH,OAAO,IAAM,cAAc,gBAA6C,KAAK,CAAC,UAAN,CAAiB,UAAC,KAAD,EAAQ,GAAR,EAAW;AAClG,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAD,EAAQ,GAAR,CAA/B;AAEA,EAAA,uBAAuB,CAAC,KAAD,CAAvB;AACA,SAAO,oBAAoB,CAAC,KAAD,CAA3B;AACD,CALuE,CAAjE;AAOP,cAAc,CAAC,WAAf,GAA6B,gBAA7B","sourceRoot":""}
@@ -1,30 +1,21 @@
1
- import * as React from 'react';
2
- import { ComponentProps, ComponentState } from '@fluentui/react-utilities';
3
- import { PopoverContextValue } from '../../popoverContext';
1
+ import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities';
2
+ import type { PopoverContextValue } from '../../popoverContext';
4
3
  /**
5
4
  * PopoverSurface Props
6
5
  */
7
- export interface PopoverSurfaceProps extends ComponentProps, React.HTMLAttributes<HTMLElement> {
8
- }
6
+ export declare type PopoverSurfaceProps = ComponentProps<PopoverSurfaceSlots>;
9
7
  /**
10
- * Names of the shorthand properties in PopoverSurfaceProps
8
+ * Names of the slots in PopoverSurfaceProps
11
9
  */
12
- export declare type PopoverSurfaceShorthandProps = never;
13
- /**
14
- * Names of PopoverSurfaceProps that have a default value in usePopoverSurface
15
- */
16
- export declare type PopoverSurfaceDefaultedProps = never;
10
+ export declare type PopoverSurfaceSlots = {
11
+ root: IntrinsicShorthandProps<'div'>;
12
+ };
17
13
  /**
18
14
  * PopoverSurface State
19
15
  */
20
- export interface PopoverSurfaceState extends ComponentState<PopoverSurfaceProps, PopoverSurfaceShorthandProps, PopoverSurfaceDefaultedProps>, Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'brand' | 'inverted'> {
21
- ref: React.Ref<HTMLElement>;
22
- /**
23
- * Ref to the arrow element
24
- */
25
- arrowRef?: React.Ref<HTMLDivElement>;
16
+ export declare type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> & Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'appearance' | 'arrowRef'> & {
26
17
  /**
27
18
  * CSS class for the arrow element
28
19
  */
29
20
  arrowClassName?: string;
30
- }
21
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"PopoverSurface.types.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { ComponentProps, ComponentState } from '@fluentui/react-utilities';\nimport { PopoverContextValue } from '../../popoverContext';\n\n/**\n * PopoverSurface Props\n */\nexport interface PopoverSurfaceProps extends ComponentProps, React.HTMLAttributes<HTMLElement> {}\n\n/**\n * Names of the shorthand properties in PopoverSurfaceProps\n */\nexport type PopoverSurfaceShorthandProps = never;\n\n/**\n * Names of PopoverSurfaceProps that have a default value in usePopoverSurface\n */\nexport type PopoverSurfaceDefaultedProps = never;\n\n/**\n * PopoverSurface State\n */\nexport interface PopoverSurfaceState\n extends ComponentState<PopoverSurfaceProps, PopoverSurfaceShorthandProps, PopoverSurfaceDefaultedProps>,\n Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'brand' | 'inverted'> {\n ref: React.Ref<HTMLElement>;\n /**\n * Ref to the arrow element\n */\n arrowRef?: React.Ref<HTMLDivElement>;\n\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n}\n"]}
1
+ {"version":3,"file":"PopoverSurface.types.js","sourceRoot":"","sources":["../../../src/components/PopoverSurface/PopoverSurface.types.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/PopoverSurface/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './PopoverSurface';\nexport * from './PopoverSurface.types';\nexport * from './renderPopoverSurface';\nexport * from './usePopoverSurface';\nexport * from './usePopoverSurfaceStyles';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/PopoverSurface/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { PopoverSurfaceState } from './PopoverSurface.types';
1
+ import type { PopoverSurfaceState } from './PopoverSurface.types';
2
2
  /**
3
3
  * Render the final JSX of PopoverSurface
4
4
  */
@@ -1,19 +1,27 @@
1
1
  import { __assign } from "tslib";
2
2
  import * as React from 'react';
3
- import { getSlots } from '@fluentui/react-utilities';
4
3
  import { Portal } from '@fluentui/react-portal';
4
+ import { getSlots } from '@fluentui/react-utilities';
5
+ import { popoverSurfaceSlots } from './usePopoverSurface';
5
6
  /**
6
7
  * Render the final JSX of PopoverSurface
7
8
  */
9
+
8
10
  export var renderPopoverSurface = function (state) {
9
- var _a = getSlots(state), slots = _a.slots, slotProps = _a.slotProps;
10
- // TODO should hidden Popovers be supported ?
11
- if (!state.open) {
12
- return null;
13
- }
14
- return (React.createElement(Portal, { mountNode: state.mountNode },
15
- React.createElement(slots.root, __assign({}, slotProps.root),
16
- !state.noArrow && React.createElement("div", { ref: state.arrowRef, className: state.arrowClassName }),
17
- state.children)));
11
+ var _a = getSlots(state, popoverSurfaceSlots),
12
+ slots = _a.slots,
13
+ slotProps = _a.slotProps; // TODO should hidden Popovers be supported ?
14
+
15
+
16
+ if (!state.open) {
17
+ return null;
18
+ }
19
+
20
+ return /*#__PURE__*/React.createElement(Portal, {
21
+ mountNode: state.mountNode
22
+ }, /*#__PURE__*/React.createElement(slots.root, __assign({}, slotProps.root), !state.noArrow && /*#__PURE__*/React.createElement("div", {
23
+ ref: state.arrowRef,
24
+ className: state.arrowClassName
25
+ }), slotProps.root.children));
18
26
  };
19
27
  //# sourceMappingURL=renderPopoverSurface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderPopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD;;GAEG;AACH,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAAC,KAA0B;IACvD,IAAA,KAAuB,QAAQ,CAAC,KAAK,CAAC,EAApC,KAAK,WAAA,EAAE,SAAS,eAAoB,CAAC;IAE7C,6CAA6C;IAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,oBAAC,MAAM,IAAC,SAAS,EAAE,KAAK,CAAC,SAAS;QAChC,oBAAC,KAAK,CAAC,IAAI,eAAK,SAAS,CAAC,IAAI;YAC3B,CAAC,KAAK,CAAC,OAAO,IAAI,6BAAK,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,cAAc,GAAI;YAC/E,KAAK,CAAC,QAAQ,CACJ,CACN,CACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { Portal } from '@fluentui/react-portal';\nimport { PopoverSurfaceState } from './PopoverSurface.types';\n\n/**\n * Render the final JSX of PopoverSurface\n */\nexport const renderPopoverSurface = (state: PopoverSurfaceState) => {\n const { slots, slotProps } = getSlots(state);\n\n // TODO should hidden Popovers be supported ?\n if (!state.open) {\n return null;\n }\n\n return (\n <Portal mountNode={state.mountNode}>\n <slots.root {...slotProps.root}>\n {!state.noArrow && <div ref={state.arrowRef} className={state.arrowClassName} />}\n {state.children}\n </slots.root>\n </Portal>\n );\n};\n"]}
1
+ {"version":3,"sources":["../../../src/components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAEA,SAAS,mBAAT,QAAoC,qBAApC;AAEA;;AAEG;;AACH,OAAO,IAAM,oBAAoB,GAAG,UAAC,KAAD,EAA2B;AACvD,MAAA,EAAA,GAAuB,QAAQ,CAAsB,KAAtB,EAA6B,mBAA7B,CAA/B;AAAA,MAAE,KAAK,GAAA,EAAA,CAAA,KAAP;AAAA,MAAS,SAAS,GAAA,EAAA,CAAA,SAAlB,CADuD,CAG7D;;;AACA,MAAI,CAAC,KAAK,CAAC,IAAX,EAAiB;AACf,WAAO,IAAP;AACD;;AAED,sBACE,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO;AAAC,IAAA,SAAS,EAAE,KAAK,CAAC;AAAlB,GAAP,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,IAAf,CAAX,EACG,CAAC,KAAK,CAAC,OAAP,iBAAkB,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAK,IAAA,GAAG,EAAE,KAAK,CAAC,QAAhB;AAA0B,IAAA,SAAS,EAAE,KAAK,CAAC;AAA3C,GAAA,CADrB,EAEG,SAAS,CAAC,IAAV,CAAe,QAFlB,CADF,CADF;AAQD,CAhBM","sourceRoot":""}
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { PopoverSurfaceProps, PopoverSurfaceState } from './PopoverSurface.types';
2
+ import type { PopoverSurfaceProps, PopoverSurfaceSlots, PopoverSurfaceState } from './PopoverSurface.types';
3
+ export declare const popoverSurfaceSlots: Array<keyof PopoverSurfaceSlots>;
3
4
  /**
4
5
  * Create the state required to render PopoverSurface.
5
6
  *
@@ -7,7 +8,6 @@ import { PopoverSurfaceProps, PopoverSurfaceState } from './PopoverSurface.types
7
8
  * before being passed to renderPopoverSurface.
8
9
  *
9
10
  * @param props - props from this instance of PopoverSurface
10
- * @param ref - reference to root HTMLElement of PopoverSurface
11
- * @param defaultProps - (optional) default prop values provided by the implementing type
11
+ * @param ref - reference to root HTMLDivElement of PopoverSurface
12
12
  */
13
- export declare const usePopoverSurface: (props: PopoverSurfaceProps, ref: React.Ref<HTMLElement>, defaultProps?: PopoverSurfaceProps | undefined) => PopoverSurfaceState;
13
+ export declare const usePopoverSurface: (props: PopoverSurfaceProps, ref: React.Ref<HTMLDivElement>) => PopoverSurfaceState;
@@ -1,9 +1,9 @@
1
1
  import { __assign } from "tslib";
2
2
  import * as React from 'react';
3
- import { makeMergeProps, useMergedRefs } from '@fluentui/react-utilities';
3
+ import { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';
4
4
  import { useFocusFinders, useModalAttributes } from '@fluentui/react-tabster';
5
5
  import { usePopoverContext } from '../../popoverContext';
6
- var mergeProps = makeMergeProps({});
6
+ export var popoverSurfaceSlots = ['root'];
7
7
  /**
8
8
  * Create the state required to render PopoverSurface.
9
9
  *
@@ -11,58 +11,98 @@ var mergeProps = makeMergeProps({});
11
11
  * before being passed to renderPopoverSurface.
12
12
  *
13
13
  * @param props - props from this instance of PopoverSurface
14
- * @param ref - reference to root HTMLElement of PopoverSurface
15
- * @param defaultProps - (optional) default prop values provided by the implementing type
14
+ * @param ref - reference to root HTMLDivElement of PopoverSurface
16
15
  */
17
- export var usePopoverSurface = function (props, ref, defaultProps) {
18
- var contentRef = usePopoverContext(function (context) { return context.contentRef; });
19
- var open = usePopoverContext(function (context) { return context.open; });
20
- var openOnHover = usePopoverContext(function (context) { return context.openOnHover; });
21
- var setOpen = usePopoverContext(function (context) { return context.setOpen; });
22
- var mountNode = usePopoverContext(function (context) { return context.mountNode; });
23
- var arrowRef = usePopoverContext(function (context) { return context.arrowRef; });
24
- var size = usePopoverContext(function (context) { return context.size; });
25
- var noArrow = usePopoverContext(function (context) { return context.noArrow; });
26
- var brand = usePopoverContext(function (context) { return context.brand; });
27
- var inverted = usePopoverContext(function (context) { return context.inverted; });
28
- var trapFocus = usePopoverContext(function (context) { return context.trapFocus; });
29
- var modalAttributes = useModalAttributes({ trapFocus: trapFocus }).modalAttributes;
30
- var state = mergeProps(__assign({ brand: brand,
31
- inverted: inverted,
32
- noArrow: noArrow,
33
- size: size,
34
- arrowRef: arrowRef,
35
- open: open,
36
- mountNode: mountNode, role: 'dialog', ref: useMergedRefs(ref, contentRef) }, modalAttributes), defaultProps, props);
37
- var onMouseEnterOriginal = state.onMouseEnter, onMouseLeaveOriginal = state.onMouseLeave, onKeyDownOriginal = state.onKeyDown;
38
- state.onMouseEnter = function (e) {
39
- if (openOnHover) {
40
- setOpen(e, true);
41
- }
42
- onMouseEnterOriginal === null || onMouseEnterOriginal === void 0 ? void 0 : onMouseEnterOriginal(e);
43
- };
44
- state.onMouseLeave = function (e) {
45
- if (openOnHover) {
46
- setOpen(e, false);
47
- }
48
- onMouseLeaveOriginal === null || onMouseLeaveOriginal === void 0 ? void 0 : onMouseLeaveOriginal(e);
49
- };
50
- state.onKeyDown = function (e) {
51
- var _a;
52
- // only close if the event happened inside the current popover
53
- // If using a stack of inline popovers, the user should call `stopPropagation` to avoid dismissing the entire stack
54
- if (e.key === 'Escape' && ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
55
- setOpen(e, false);
56
- }
57
- onKeyDownOriginal === null || onKeyDownOriginal === void 0 ? void 0 : onKeyDownOriginal(e);
58
- };
59
- var findFirstFocusable = useFocusFinders().findFirstFocusable;
60
- React.useEffect(function () {
61
- if (state.open && contentRef.current) {
62
- var firstFocusable = findFirstFocusable(contentRef.current);
63
- firstFocusable === null || firstFocusable === void 0 ? void 0 : firstFocusable.focus();
64
- }
65
- }, [contentRef, findFirstFocusable, state.open]);
66
- return state;
16
+
17
+ export var usePopoverSurface = function (props, ref) {
18
+ var contentRef = usePopoverContext(function (context) {
19
+ return context.contentRef;
20
+ });
21
+ var open = usePopoverContext(function (context) {
22
+ return context.open;
23
+ });
24
+ var openOnHover = usePopoverContext(function (context) {
25
+ return context.openOnHover;
26
+ });
27
+ var setOpen = usePopoverContext(function (context) {
28
+ return context.setOpen;
29
+ });
30
+ var mountNode = usePopoverContext(function (context) {
31
+ return context.mountNode;
32
+ });
33
+ var arrowRef = usePopoverContext(function (context) {
34
+ return context.arrowRef;
35
+ });
36
+ var size = usePopoverContext(function (context) {
37
+ return context.size;
38
+ });
39
+ var noArrow = usePopoverContext(function (context) {
40
+ return context.noArrow;
41
+ });
42
+ var appearance = usePopoverContext(function (context) {
43
+ return context.appearance;
44
+ });
45
+ var trapFocus = usePopoverContext(function (context) {
46
+ return context.trapFocus;
47
+ });
48
+ var modalAttributes = useModalAttributes({
49
+ trapFocus: trapFocus
50
+ }).modalAttributes;
51
+ var state = {
52
+ appearance: appearance,
53
+ noArrow: noArrow,
54
+ size: size,
55
+ arrowRef: arrowRef,
56
+ open: open,
57
+ mountNode: mountNode,
58
+ components: {
59
+ root: 'div'
60
+ },
61
+ root: getNativeElementProps('div', __assign(__assign({
62
+ ref: useMergedRefs(ref, contentRef),
63
+ role: 'dialog'
64
+ }, modalAttributes), props))
65
+ };
66
+ var _a = state.root,
67
+ onMouseEnterOriginal = _a.onMouseEnter,
68
+ onMouseLeaveOriginal = _a.onMouseLeave,
69
+ onKeyDownOriginal = _a.onKeyDown;
70
+
71
+ state.root.onMouseEnter = function (e) {
72
+ if (openOnHover) {
73
+ setOpen(e, true);
74
+ }
75
+
76
+ onMouseEnterOriginal === null || onMouseEnterOriginal === void 0 ? void 0 : onMouseEnterOriginal(e);
77
+ };
78
+
79
+ state.root.onMouseLeave = function (e) {
80
+ if (openOnHover) {
81
+ setOpen(e, false);
82
+ }
83
+
84
+ onMouseLeaveOriginal === null || onMouseLeaveOriginal === void 0 ? void 0 : onMouseLeaveOriginal(e);
85
+ };
86
+
87
+ state.root.onKeyDown = function (e) {
88
+ var _a; // only close if the event happened inside the current popover
89
+ // If using a stack of inline popovers, the user should call `stopPropagation` to avoid dismissing the entire stack
90
+
91
+
92
+ if (e.key === 'Escape' && ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
93
+ setOpen(e, false);
94
+ }
95
+
96
+ onKeyDownOriginal === null || onKeyDownOriginal === void 0 ? void 0 : onKeyDownOriginal(e);
97
+ };
98
+
99
+ var findFirstFocusable = useFocusFinders().findFirstFocusable;
100
+ React.useEffect(function () {
101
+ if (state.open && contentRef.current) {
102
+ var firstFocusable = findFirstFocusable(contentRef.current);
103
+ firstFocusable === null || firstFocusable === void 0 ? void 0 : firstFocusable.focus();
104
+ }
105
+ }, [contentRef, findFirstFocusable, state.open]);
106
+ return state;
67
107
  };
68
108
  //# sourceMappingURL=usePopoverSurface.js.map