@fluentui/react-popover 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.11
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +935 -25
- package/CHANGELOG.md +297 -80
- package/Spec.md +20 -0
- package/dist/{react-popover.d.ts → index.d.ts} +117 -71
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/Popover.js.map +1 -1
- package/lib/PopoverSurface.js.map +1 -1
- package/lib/PopoverTrigger.js.map +1 -1
- package/lib/components/Popover/Popover.js +5 -5
- package/lib/components/Popover/Popover.js.map +1 -1
- package/lib/components/Popover/Popover.types.js.map +1 -1
- package/lib/components/Popover/index.js.map +1 -1
- package/lib/components/Popover/renderPopover.js +30 -26
- package/lib/components/Popover/renderPopover.js.map +1 -1
- package/lib/components/Popover/usePopover.js +118 -56
- package/lib/components/Popover/usePopover.js.map +1 -1
- package/lib/components/PopoverSurface/PopoverSurface.js +7 -7
- package/lib/components/PopoverSurface/PopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
- package/lib/components/PopoverSurface/index.js.map +1 -1
- package/lib/components/PopoverSurface/renderPopoverSurface.js +13 -13
- package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurface.js +40 -64
- package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +36 -22
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib/components/PopoverTrigger/PopoverTrigger.js +6 -5
- package/lib/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
- package/lib/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -1
- package/lib/components/PopoverTrigger/index.js.map +1 -1
- package/lib/components/PopoverTrigger/renderPopoverTrigger.js +1 -1
- package/lib/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
- package/lib/components/PopoverTrigger/usePopoverTrigger.js +40 -55
- package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/popoverContext.js +7 -9
- package/lib/popoverContext.js.map +1 -1
- package/lib-commonjs/Popover.js +1 -1
- package/lib-commonjs/Popover.js.map +1 -1
- package/lib-commonjs/PopoverSurface.js +1 -1
- package/lib-commonjs/PopoverSurface.js.map +1 -1
- package/lib-commonjs/PopoverTrigger.js +1 -1
- package/lib-commonjs/PopoverTrigger.js.map +1 -1
- package/lib-commonjs/components/Popover/Popover.js +5 -5
- package/lib-commonjs/components/Popover/Popover.js.map +1 -1
- package/lib-commonjs/components/Popover/Popover.types.js.map +1 -1
- package/lib-commonjs/components/Popover/index.js +1 -1
- package/lib-commonjs/components/Popover/index.js.map +1 -1
- package/lib-commonjs/components/Popover/renderPopover.js +34 -30
- package/lib-commonjs/components/Popover/renderPopover.js.map +1 -1
- package/lib-commonjs/components/Popover/usePopover.js +125 -63
- package/lib-commonjs/components/Popover/usePopover.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.js +8 -8
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/index.js +1 -1
- package/lib-commonjs/components/PopoverSurface/index.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +18 -20
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +44 -70
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +40 -24
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js +6 -5
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/index.js +1 -1
- package/lib-commonjs/components/PopoverTrigger/index.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js +3 -3
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +45 -61
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib-commonjs/index.js +92 -5
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/popoverContext.js +9 -11
- package/lib-commonjs/popoverContext.js.map +1 -1
- package/package.json +23 -27
- package/lib/Popover.d.ts +0 -1
- package/lib/PopoverSurface.d.ts +0 -1
- package/lib/PopoverTrigger.d.ts +0 -1
- package/lib/common/isConformant.d.ts +0 -4
- package/lib/common/isConformant.js +0 -13
- package/lib/common/isConformant.js.map +0 -1
- package/lib/common/mockUsePopoverContext.d.ts +0 -7
- package/lib/common/mockUsePopoverContext.js +0 -38
- package/lib/common/mockUsePopoverContext.js.map +0 -1
- package/lib/components/Popover/Popover.d.ts +0 -6
- package/lib/components/Popover/Popover.types.d.ts +0 -100
- package/lib/components/Popover/index.d.ts +0 -4
- package/lib/components/Popover/renderPopover.d.ts +0 -5
- package/lib/components/Popover/usePopover.d.ts +0 -10
- package/lib/components/PopoverSurface/PopoverSurface.d.ts +0 -6
- package/lib/components/PopoverSurface/PopoverSurface.types.d.ts +0 -21
- package/lib/components/PopoverSurface/index.d.ts +0 -5
- package/lib/components/PopoverSurface/renderPopoverSurface.d.ts +0 -5
- package/lib/components/PopoverSurface/usePopoverSurface.d.ts +0 -13
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +0 -7
- package/lib/components/PopoverTrigger/PopoverTrigger.d.ts +0 -6
- package/lib/components/PopoverTrigger/PopoverTrigger.types.d.ts +0 -11
- package/lib/components/PopoverTrigger/index.d.ts +0 -4
- package/lib/components/PopoverTrigger/renderPopoverTrigger.d.ts +0 -5
- package/lib/components/PopoverTrigger/usePopoverTrigger.d.ts +0 -10
- package/lib/index.d.ts +0 -4
- package/lib/popoverContext.d.ts +0 -8
- package/lib-commonjs/Popover.d.ts +0 -1
- package/lib-commonjs/PopoverSurface.d.ts +0 -1
- package/lib-commonjs/PopoverTrigger.d.ts +0 -1
- package/lib-commonjs/common/isConformant.d.ts +0 -4
- package/lib-commonjs/common/isConformant.js +0 -24
- package/lib-commonjs/common/isConformant.js.map +0 -1
- package/lib-commonjs/common/mockUsePopoverContext.d.ts +0 -7
- package/lib-commonjs/common/mockUsePopoverContext.js +0 -49
- package/lib-commonjs/common/mockUsePopoverContext.js.map +0 -1
- package/lib-commonjs/components/Popover/Popover.d.ts +0 -6
- package/lib-commonjs/components/Popover/Popover.types.d.ts +0 -100
- package/lib-commonjs/components/Popover/index.d.ts +0 -4
- package/lib-commonjs/components/Popover/renderPopover.d.ts +0 -5
- package/lib-commonjs/components/Popover/usePopover.d.ts +0 -10
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.d.ts +0 -6
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.d.ts +0 -21
- package/lib-commonjs/components/PopoverSurface/index.d.ts +0 -5
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.d.ts +0 -5
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.d.ts +0 -13
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +0 -7
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.d.ts +0 -6
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.d.ts +0 -11
- package/lib-commonjs/components/PopoverTrigger/index.d.ts +0 -4
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.d.ts +0 -5
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.d.ts +0 -10
- package/lib-commonjs/index.d.ts +0 -4
- package/lib-commonjs/popoverContext.d.ts +0 -8
@@ -1,83 +1,145 @@
|
|
1
|
-
import { __assign } from "tslib";
|
2
1
|
import * as React from 'react';
|
3
2
|
import { useControllableState, useEventCallback, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
|
4
3
|
import { useFluent } from '@fluentui/react-shared-contexts';
|
5
|
-
import {
|
4
|
+
import { usePositioning, resolvePositioningShorthand, mergeArrowOffset, usePositioningMouseTarget } from '@fluentui/react-positioning';
|
6
5
|
import { elementContains } from '@fluentui/react-portal';
|
6
|
+
import { useFocusFinders } from '@fluentui/react-tabster';
|
7
7
|
import { arrowHeights } from '../PopoverSurface/index';
|
8
8
|
/**
|
9
9
|
* Create the state required to render Popover.
|
10
10
|
*
|
11
11
|
* The returned state can be modified with hooks such as usePopoverStyles,
|
12
|
-
* before being passed to
|
12
|
+
* before being passed to renderPopover_unstable.
|
13
13
|
*
|
14
14
|
* @param props - props from this instance of Popover
|
15
15
|
*/
|
16
16
|
|
17
|
-
export
|
18
|
-
var _a
|
19
|
-
contextTarget = _a[0],
|
20
|
-
setContextTarget = _a[1];
|
17
|
+
export const usePopover_unstable = props => {
|
18
|
+
var _a;
|
21
19
|
|
22
|
-
|
20
|
+
const [contextTarget, setContextTarget] = usePositioningMouseTarget();
|
21
|
+
const initialState = {
|
23
22
|
size: 'medium',
|
24
|
-
contextTarget
|
25
|
-
setContextTarget
|
26
|
-
|
23
|
+
contextTarget,
|
24
|
+
setContextTarget,
|
25
|
+
...props
|
26
|
+
};
|
27
|
+
const children = React.Children.toArray(props.children);
|
28
|
+
|
29
|
+
if (process.env.NODE_ENV !== 'production') {
|
30
|
+
if (children.length === 0) {
|
31
|
+
// eslint-disable-next-line no-console
|
32
|
+
console.warn('Popover must contain at least one child');
|
33
|
+
}
|
34
|
+
|
35
|
+
if (children.length > 2) {
|
36
|
+
// eslint-disable-next-line no-console
|
37
|
+
console.warn('Popover must contain at most two children');
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
let popoverTrigger = undefined;
|
42
|
+
let popoverSurface = undefined;
|
43
|
+
|
44
|
+
if (children.length === 2) {
|
45
|
+
popoverTrigger = children[0];
|
46
|
+
popoverSurface = children[1];
|
47
|
+
} else if (children.length === 1) {
|
48
|
+
popoverSurface = children[0];
|
49
|
+
}
|
50
|
+
|
51
|
+
const [open, setOpenState] = useOpenState(initialState);
|
52
|
+
const setOpenTimeoutRef = React.useRef(0);
|
53
|
+
const setOpen = useEventCallback((e, shouldOpen) => {
|
54
|
+
var _a;
|
55
|
+
|
56
|
+
clearTimeout(setOpenTimeoutRef.current);
|
27
57
|
|
28
|
-
|
29
|
-
|
30
|
-
|
58
|
+
if (!(e instanceof Event) && e.persist) {
|
59
|
+
// < React 17 still uses pooled synthetic events
|
60
|
+
e.persist();
|
61
|
+
}
|
31
62
|
|
32
|
-
|
33
|
-
|
63
|
+
if (e.type === 'mouseleave') {
|
64
|
+
// FIXME leaking Node timeout type
|
65
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
66
|
+
// @ts-ignore
|
67
|
+
setOpenTimeoutRef.current = setTimeout(() => {
|
68
|
+
setOpenState(e, shouldOpen);
|
69
|
+
}, (_a = props.mouseLeaveDelay) !== null && _a !== void 0 ? _a : 500);
|
70
|
+
} else {
|
71
|
+
setOpenState(e, shouldOpen);
|
72
|
+
}
|
73
|
+
}); // Clear timeout on unmount
|
74
|
+
// Setting state after a component unmounts can cause memory leaks
|
75
|
+
|
76
|
+
React.useEffect(() => {
|
77
|
+
return () => {
|
78
|
+
clearTimeout(setOpenTimeoutRef.current);
|
79
|
+
};
|
80
|
+
}, []);
|
81
|
+
const toggleOpen = React.useCallback(e => {
|
82
|
+
setOpen(e, !open);
|
83
|
+
}, [setOpen, open]);
|
84
|
+
const positioningRefs = usePopoverRefs(initialState);
|
85
|
+
const {
|
86
|
+
targetDocument
|
87
|
+
} = useFluent();
|
34
88
|
useOnClickOutside({
|
35
89
|
contains: elementContains,
|
36
90
|
element: targetDocument,
|
37
|
-
callback:
|
38
|
-
|
39
|
-
},
|
40
|
-
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
91
|
+
callback: ev => setOpen(ev, false),
|
92
|
+
refs: [positioningRefs.triggerRef, positioningRefs.contentRef],
|
41
93
|
disabled: !open
|
42
|
-
});
|
94
|
+
}); // only close on scroll for context, or when closeOnScroll is specified
|
95
|
+
|
96
|
+
const closeOnScroll = initialState.openOnContext || initialState.closeOnScroll;
|
43
97
|
useOnScrollOutside({
|
44
98
|
contains: elementContains,
|
45
99
|
element: targetDocument,
|
46
|
-
callback:
|
47
|
-
|
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
|
100
|
+
callback: ev => setOpen(ev, false),
|
101
|
+
refs: [positioningRefs.triggerRef, positioningRefs.contentRef],
|
102
|
+
disabled: !open || !closeOnScroll
|
57
103
|
});
|
104
|
+
const {
|
105
|
+
findFirstFocusable
|
106
|
+
} = useFocusFinders();
|
107
|
+
React.useEffect(() => {
|
108
|
+
if (open && positioningRefs.contentRef.current) {
|
109
|
+
const firstFocusable = findFirstFocusable(positioningRefs.contentRef.current);
|
110
|
+
firstFocusable === null || firstFocusable === void 0 ? void 0 : firstFocusable.focus();
|
111
|
+
}
|
112
|
+
}, [findFirstFocusable, open, positioningRefs.contentRef]);
|
113
|
+
return { ...initialState,
|
114
|
+
...positioningRefs,
|
115
|
+
popoverTrigger,
|
116
|
+
popoverSurface,
|
117
|
+
open,
|
118
|
+
setOpen,
|
119
|
+
toggleOpen,
|
120
|
+
setContextTarget,
|
121
|
+
contextTarget,
|
122
|
+
inline: (_a = props.inline) !== null && _a !== void 0 ? _a : false
|
123
|
+
};
|
58
124
|
};
|
59
125
|
/**
|
60
126
|
* Creates and manages the Popover open state
|
61
127
|
*/
|
62
128
|
|
63
129
|
function useOpenState(state) {
|
64
|
-
|
130
|
+
const onOpenChange = useEventCallback((e, data) => {
|
65
131
|
var _a;
|
66
132
|
|
67
133
|
return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
|
68
134
|
});
|
69
|
-
|
70
|
-
var _a = useControllableState({
|
135
|
+
const [open, setOpenState] = useControllableState({
|
71
136
|
state: state.open,
|
72
137
|
defaultState: state.defaultOpen,
|
73
138
|
initialState: false
|
74
|
-
})
|
75
|
-
open = _a[0],
|
76
|
-
setOpenState = _a[1];
|
77
|
-
|
139
|
+
});
|
78
140
|
state.open = open !== undefined ? open : state.open;
|
79
|
-
|
80
|
-
|
141
|
+
const setContextTarget = state.setContextTarget;
|
142
|
+
const setOpen = React.useCallback((e, shouldOpen) => {
|
81
143
|
if (shouldOpen && e.type === 'contextmenu') {
|
82
144
|
setContextTarget(e);
|
83
145
|
}
|
@@ -86,7 +148,7 @@ function useOpenState(state) {
|
|
86
148
|
setContextTarget(undefined);
|
87
149
|
}
|
88
150
|
|
89
|
-
setOpenState(
|
151
|
+
setOpenState(prevOpen => {
|
90
152
|
// More than one event (mouse, focus, keyboard) can request the Popover to close
|
91
153
|
// We assume the first event is the correct one
|
92
154
|
if (prevOpen !== shouldOpen) {
|
@@ -106,30 +168,30 @@ function useOpenState(state) {
|
|
106
168
|
|
107
169
|
|
108
170
|
function usePopoverRefs(state) {
|
109
|
-
|
171
|
+
const positioningOptions = {
|
110
172
|
position: 'above',
|
111
173
|
align: 'center',
|
112
|
-
target: state.openOnContext ? state.contextTarget : undefined
|
113
|
-
|
114
|
-
|
174
|
+
target: state.openOnContext ? state.contextTarget : undefined,
|
175
|
+
...resolvePositioningShorthand(state.positioning)
|
176
|
+
}; // no reason to render arrow when covering the target
|
115
177
|
|
116
|
-
if (
|
178
|
+
if (positioningOptions.coverTarget) {
|
117
179
|
state.noArrow = true;
|
118
180
|
}
|
119
181
|
|
120
182
|
if (!state.noArrow) {
|
121
|
-
|
183
|
+
positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeights[state.size]);
|
122
184
|
}
|
123
185
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
186
|
+
const {
|
187
|
+
targetRef: triggerRef,
|
188
|
+
containerRef: contentRef,
|
189
|
+
arrowRef
|
190
|
+
} = usePositioning(positioningOptions);
|
129
191
|
return {
|
130
|
-
triggerRef
|
131
|
-
contentRef
|
132
|
-
arrowRef
|
192
|
+
triggerRef,
|
193
|
+
contentRef,
|
194
|
+
arrowRef
|
133
195
|
};
|
134
196
|
}
|
135
197
|
//# sourceMappingURL=usePopover.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/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,YAAT,QAA6B,yBAA7B;AAGA;;;;;;;AAOG;;AACH,OAAO,IAAM,UAAU,GAAG,UAAC,KAAD,EAAoB;AACtC,MAAA,EAAA,GAAoC,oBAAoB,EAAxD;AAAA,MAAC,aAAa,GAAA,EAAA,CAAA,CAAA,CAAd;AAAA,MAAgB,gBAAgB,GAAA,EAAA,CAAA,CAAA,CAAhC;;AACN,MAAM,YAAY,GAAG,QAAA,CAAA;AACnB,IAAA,IAAI,EAAE,QADa;AAEnB,IAAA,aAAa,EAAA,aAFM;AAGnB,IAAA,gBAAgB,EAAA;AAHG,GAAA,EAIhB,KAJgB,CAArB;;AAOM,MAAA,EAAA,GAAkB,YAAY,CAAC,YAAD,CAA9B;AAAA,MAAC,I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D,EAAe,YAAf,EAA6B,gBAA7B,CApBc,CAAhB;AAuBA,SAAO,CAAC,IAAD,EAAO,OAAP,CAAP;AACD;AAED;;AAEG;;;AACH,SAAS,cAAT,CACE,KADF,EACuH;AAErH,QAAM,kBAAkB,GAAG;AACzB,IAAA,QAAQ,EAAE,OADe;AAEzB,IAAA,KAAK,EAAE,QAFkB;AAGzB,IAAA,MAAM,EAAE,KAAK,CAAC,aAAN,GAAsB,KAAK,CAAC,aAA5B,GAA4C,SAH3B;AAIzB,OAAG,2BAA2B,CAAC,KAAK,CAAC,WAAP;AAJL,GAA3B,CAFqH,CASrH;;AACA,MAAI,kBAAkB,CAAC,WAAvB,EAAoC;AAClC,IAAA,KAAK,CAAC,OAAN,GAAgB,IAAhB;AACD;;AAED,MAAI,CAAC,KAAK,CAAC,OAAX,EAAoB;AAClB,IAAA,kBAAkB,CAAC,MAAnB,GAA4B,gBAAgB,CAAC,kBAAkB,CAAC,MAApB,EAA4B,YAAY,CAAC,KAAK,CAAC,IAAP,CAAxC,CAA5C;AACD;;AAED,QAAM;AAAE,IAAA,SAAS,EAAE,UAAb;AAAyB,IAAA,YAAY,EAAE,UAAvC;AAAmD,IAAA;AAAnD,MAAgE,cAAc,CAAC,kBAAD,CAApF;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 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';\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'> & Pick<PopoverProps, 'positioning' | 'openOnContext' | 'noArrow'>,\n) {\n const positioningOptions = {\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 (positioningOptions.coverTarget) {\n state.noArrow = true;\n }\n\n if (!state.noArrow) {\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,15 +1,15 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
2
|
+
import { usePopoverSurface_unstable } from './usePopoverSurface';
|
3
|
+
import { renderPopoverSurface_unstable } from './renderPopoverSurface';
|
4
|
+
import { usePopoverSurfaceStyles_unstable } from './usePopoverSurfaceStyles';
|
5
5
|
/**
|
6
6
|
* PopoverSurface component renders react children in a positioned box
|
7
7
|
*/
|
8
8
|
|
9
|
-
export
|
10
|
-
|
11
|
-
|
12
|
-
return
|
9
|
+
export const PopoverSurface = /*#__PURE__*/React.forwardRef((props, ref) => {
|
10
|
+
const state = usePopoverSurface_unstable(props, ref);
|
11
|
+
usePopoverSurfaceStyles_unstable(state);
|
12
|
+
return renderPopoverSurface_unstable(state);
|
13
13
|
});
|
14
14
|
PopoverSurface.displayName = 'PopoverSurface';
|
15
15
|
//# sourceMappingURL=PopoverSurface.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
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 +1 @@
|
|
1
|
-
{"version":3,"file":"PopoverSurface.types.js","sourceRoot":"","sources":["
|
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' | 'noArrow' | 'size'> & {\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
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,27 +1,27 @@
|
|
1
|
-
import { __assign } from "tslib";
|
2
1
|
import * as React from 'react';
|
3
2
|
import { Portal } from '@fluentui/react-portal';
|
4
3
|
import { getSlots } from '@fluentui/react-utilities';
|
5
|
-
import { popoverSurfaceSlots } from './usePopoverSurface';
|
6
4
|
/**
|
7
5
|
* Render the final JSX of PopoverSurface
|
8
6
|
*/
|
9
7
|
|
10
|
-
export
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
export const renderPopoverSurface_unstable = state => {
|
9
|
+
const {
|
10
|
+
slots,
|
11
|
+
slotProps
|
12
|
+
} = getSlots(state);
|
13
|
+
const surface = /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
14
|
+
}, !state.noArrow && /*#__PURE__*/React.createElement("div", {
|
15
|
+
ref: state.arrowRef,
|
16
|
+
className: state.arrowClassName
|
17
|
+
}), slotProps.root.children);
|
15
18
|
|
16
|
-
if (
|
17
|
-
return
|
19
|
+
if (state.inline) {
|
20
|
+
return surface;
|
18
21
|
}
|
19
22
|
|
20
23
|
return /*#__PURE__*/React.createElement(Portal, {
|
21
24
|
mountNode: state.mountNode
|
22
|
-
},
|
23
|
-
ref: state.arrowRef,
|
24
|
-
className: state.arrowClassName
|
25
|
-
}), slotProps.root.children));
|
25
|
+
}, surface);
|
26
26
|
};
|
27
27
|
//# sourceMappingURL=renderPopoverSurface.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,6BAA6B,GAAI,KAAD,IAA+B;AAC1E,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAsB,KAAtB,CAArC;AAEA,QAAM,OAAO,gBACX,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,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;;AAOA,MAAI,KAAK,CAAC,MAAV,EAAkB;AAChB,WAAO,OAAP;AACD;;AAED,sBAAO,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO;AAAC,IAAA,SAAS,EAAE,KAAK,CAAC;AAAlB,GAAP,EAAqC,OAArC,CAAP;AACD,CAfM","sourcesContent":["import * as React from 'react';\nimport { Portal } from '@fluentui/react-portal';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { PopoverSurfaceSlots, PopoverSurfaceState } from './PopoverSurface.types';\n\n/**\n * Render the final JSX of PopoverSurface\n */\nexport const renderPopoverSurface_unstable = (state: PopoverSurfaceState) => {\n const { slots, slotProps } = getSlots<PopoverSurfaceSlots>(state);\n\n const surface = (\n <slots.root {...slotProps.root}>\n {!state.noArrow && <div ref={state.arrowRef} className={state.arrowClassName} />}\n {slotProps.root.children}\n </slots.root>\n );\n\n if (state.inline) {\n return surface;\n }\n\n return <Portal mountNode={state.mountNode}>{surface}</Portal>;\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,74 +1,57 @@
|
|
1
|
-
import { __assign } from "tslib";
|
2
|
-
import * as React from 'react';
|
3
1
|
import { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
export var popoverSurfaceSlots = ['root'];
|
2
|
+
import { useModalAttributes } from '@fluentui/react-tabster';
|
3
|
+
import { usePopoverContext_unstable } from '../../popoverContext';
|
7
4
|
/**
|
8
5
|
* Create the state required to render PopoverSurface.
|
9
6
|
*
|
10
|
-
* The returned state can be modified with hooks such as
|
11
|
-
* before being passed to
|
7
|
+
* The returned state can be modified with hooks such as usePopoverSurfaceStyles_unstable,
|
8
|
+
* before being passed to renderPopoverSurface_unstable.
|
12
9
|
*
|
13
10
|
* @param props - props from this instance of PopoverSurface
|
14
11
|
* @param ref - reference to root HTMLDivElement of PopoverSurface
|
15
12
|
*/
|
16
13
|
|
17
|
-
export
|
18
|
-
|
19
|
-
|
14
|
+
export const usePopoverSurface_unstable = (props, ref) => {
|
15
|
+
const contentRef = usePopoverContext_unstable(context => context.contentRef);
|
16
|
+
const openOnHover = usePopoverContext_unstable(context => context.openOnHover);
|
17
|
+
const setOpen = usePopoverContext_unstable(context => context.setOpen);
|
18
|
+
const mountNode = usePopoverContext_unstable(context => context.mountNode);
|
19
|
+
const arrowRef = usePopoverContext_unstable(context => context.arrowRef);
|
20
|
+
const size = usePopoverContext_unstable(context => context.size);
|
21
|
+
const noArrow = usePopoverContext_unstable(context => context.noArrow);
|
22
|
+
const appearance = usePopoverContext_unstable(context => context.appearance);
|
23
|
+
const trapFocus = usePopoverContext_unstable(context => context.trapFocus);
|
24
|
+
const inline = usePopoverContext_unstable(context => context.inline);
|
25
|
+
const {
|
26
|
+
modalAttributes
|
27
|
+
} = useModalAttributes({
|
28
|
+
trapFocus
|
20
29
|
});
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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,
|
30
|
+
const state = {
|
31
|
+
inline,
|
32
|
+
appearance,
|
33
|
+
noArrow,
|
34
|
+
size,
|
35
|
+
arrowRef,
|
36
|
+
mountNode,
|
58
37
|
components: {
|
59
38
|
root: 'div'
|
60
39
|
},
|
61
|
-
root: getNativeElementProps('div',
|
40
|
+
root: getNativeElementProps('div', {
|
62
41
|
ref: useMergedRefs(ref, contentRef),
|
63
|
-
role: 'dialog'
|
64
|
-
|
42
|
+
role: trapFocus ? 'dialog' : 'complementary',
|
43
|
+
'aria-modal': trapFocus ? true : undefined,
|
44
|
+
...modalAttributes,
|
45
|
+
...props
|
46
|
+
})
|
65
47
|
};
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
48
|
+
const {
|
49
|
+
onMouseEnter: onMouseEnterOriginal,
|
50
|
+
onMouseLeave: onMouseLeaveOriginal,
|
51
|
+
onKeyDown: onKeyDownOriginal
|
52
|
+
} = state.root;
|
70
53
|
|
71
|
-
state.root.onMouseEnter =
|
54
|
+
state.root.onMouseEnter = e => {
|
72
55
|
if (openOnHover) {
|
73
56
|
setOpen(e, true);
|
74
57
|
}
|
@@ -76,7 +59,7 @@ export var usePopoverSurface = function (props, ref) {
|
|
76
59
|
onMouseEnterOriginal === null || onMouseEnterOriginal === void 0 ? void 0 : onMouseEnterOriginal(e);
|
77
60
|
};
|
78
61
|
|
79
|
-
state.root.onMouseLeave =
|
62
|
+
state.root.onMouseLeave = e => {
|
80
63
|
if (openOnHover) {
|
81
64
|
setOpen(e, false);
|
82
65
|
}
|
@@ -84,7 +67,7 @@ export var usePopoverSurface = function (props, ref) {
|
|
84
67
|
onMouseLeaveOriginal === null || onMouseLeaveOriginal === void 0 ? void 0 : onMouseLeaveOriginal(e);
|
85
68
|
};
|
86
69
|
|
87
|
-
state.root.onKeyDown =
|
70
|
+
state.root.onKeyDown = e => {
|
88
71
|
var _a; // only close if the event happened inside the current popover
|
89
72
|
// If using a stack of inline popovers, the user should call `stopPropagation` to avoid dismissing the entire stack
|
90
73
|
|
@@ -96,13 +79,6 @@ export var usePopoverSurface = function (props, ref) {
|
|
96
79
|
onKeyDownOriginal === null || onKeyDownOriginal === void 0 ? void 0 : onKeyDownOriginal(e);
|
97
80
|
};
|
98
81
|
|
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
82
|
return state;
|
107
83
|
};
|
108
84
|
//# sourceMappingURL=usePopoverSurface.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/PopoverSurface/usePopoverSurface.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,EAAgC,aAAhC,QAAqD,2BAArD;AACA,SAAS,kBAAT,QAAmC,yBAAnC;AACA,SAAS,0BAAT,QAA2C,sBAA3C;AAGA;;;;;;;;AAQG;;AACH,OAAO,MAAM,0BAA0B,GAAG,CACxC,KADwC,EAExC,GAFwC,KAGjB;AACvB,QAAM,UAAU,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,UAApB,CAA7C;AACA,QAAM,WAAW,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,WAApB,CAA9C;AACA,QAAM,OAAO,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,OAApB,CAA1C;AACA,QAAM,SAAS,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,SAApB,CAA5C;AACA,QAAM,QAAQ,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,QAApB,CAA3C;AACA,QAAM,IAAI,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,IAApB,CAAvC;AACA,QAAM,OAAO,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,OAApB,CAA1C;AACA,QAAM,UAAU,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,UAApB,CAA7C;AACA,QAAM,SAAS,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,SAApB,CAA5C;AACA,QAAM,MAAM,GAAG,0BAA0B,CAAC,OAAO,IAAI,OAAO,CAAC,MAApB,CAAzC;AACA,QAAM;AAAE,IAAA;AAAF,MAAsB,kBAAkB,CAAC;AAAE,IAAA;AAAF,GAAD,CAA9C;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A,QAAI,CAAC,CAAC,GAAF,KAAU,QAAV,KAAsB,CAAA,EAAA,GAAA,UAAU,CAAC,OAAX,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,KAAA,CAAlB,GAAkB,EAAA,CAAE,QAAF,CAAW,CAAC,CAAC,MAAb,CAAxC,CAAJ,EAAoF;AAClF,MAAA,OAAO,CAAC,CAAD,EAAI,KAAJ,CAAP;AACD;;AAED,IAAA,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAG,CAAH,CAAjB;AACD,GARD;;AAUA,SAAO,KAAP;AACD,CAnEM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';\nimport { useModalAttributes } from '@fluentui/react-tabster';\nimport { usePopoverContext_unstable } from '../../popoverContext';\nimport type { PopoverSurfaceProps, PopoverSurfaceState } from './PopoverSurface.types';\n\n/**\n * Create the state required to render PopoverSurface.\n *\n * The returned state can be modified with hooks such as usePopoverSurfaceStyles_unstable,\n * before being passed to renderPopoverSurface_unstable.\n *\n * @param props - props from this instance of PopoverSurface\n * @param ref - reference to root HTMLDivElement of PopoverSurface\n */\nexport const usePopoverSurface_unstable = (\n props: PopoverSurfaceProps,\n ref: React.Ref<HTMLDivElement>,\n): PopoverSurfaceState => {\n const contentRef = usePopoverContext_unstable(context => context.contentRef);\n const openOnHover = usePopoverContext_unstable(context => context.openOnHover);\n const setOpen = usePopoverContext_unstable(context => context.setOpen);\n const mountNode = usePopoverContext_unstable(context => context.mountNode);\n const arrowRef = usePopoverContext_unstable(context => context.arrowRef);\n const size = usePopoverContext_unstable(context => context.size);\n const noArrow = usePopoverContext_unstable(context => context.noArrow);\n const appearance = usePopoverContext_unstable(context => context.appearance);\n const trapFocus = usePopoverContext_unstable(context => context.trapFocus);\n const inline = usePopoverContext_unstable(context => context.inline);\n const { modalAttributes } = useModalAttributes({ trapFocus });\n\n const state: PopoverSurfaceState = {\n inline,\n appearance,\n noArrow,\n size,\n arrowRef,\n mountNode,\n components: {\n root: 'div',\n },\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, contentRef),\n role: trapFocus ? 'dialog' : 'complementary',\n 'aria-modal': trapFocus ? true : undefined,\n ...modalAttributes,\n ...props,\n }),\n };\n\n const {\n onMouseEnter: onMouseEnterOriginal,\n onMouseLeave: onMouseLeaveOriginal,\n onKeyDown: onKeyDownOriginal,\n } = state.root;\n state.root.onMouseEnter = (e: React.MouseEvent<HTMLDivElement>) => {\n if (openOnHover) {\n setOpen(e, true);\n }\n\n onMouseEnterOriginal?.(e);\n };\n\n state.root.onMouseLeave = (e: React.MouseEvent<HTMLDivElement>) => {\n if (openOnHover) {\n setOpen(e, false);\n }\n\n onMouseLeaveOriginal?.(e);\n };\n\n state.root.onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n // only close if the event happened inside the current popover\n // If using a stack of inline popovers, the user should call `stopPropagation` to avoid dismissing the entire stack\n if (e.key === 'Escape' && contentRef.current?.contains(e.target as HTMLDivElement)) {\n setOpen(e, false);\n }\n\n onKeyDownOriginal?.(e);\n };\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|