@fluentui/react-popover 9.0.0-nightly.b5b7401007.0 → 9.0.0-rc.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +425 -29
- package/CHANGELOG.md +104 -20
- package/dist/react-popover.d.ts +31 -20
- 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.d.ts +2 -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.d.ts +1 -1
- package/lib/components/Popover/renderPopover.js +27 -25
- package/lib/components/Popover/renderPopover.js.map +1 -1
- package/lib/components/Popover/usePopover.d.ts +2 -2
- package/lib/components/Popover/usePopover.js +42 -53
- 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.d.ts +2 -2
- package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
- package/lib/components/PopoverSurface/index.js.map +1 -1
- package/lib/components/PopoverSurface/renderPopoverSurface.d.ts +1 -1
- package/lib/components/PopoverSurface/renderPopoverSurface.js +7 -8
- package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurface.d.ts +4 -5
- package/lib/components/PopoverSurface/usePopoverSurface.js +44 -58
- package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +2 -1
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +34 -22
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib/components/PopoverTrigger/PopoverTrigger.d.ts +2 -1
- package/lib/components/PopoverTrigger/PopoverTrigger.js +6 -5
- package/lib/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
- package/lib/components/PopoverTrigger/PopoverTrigger.types.d.ts +9 -2
- package/lib/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -1
- package/lib/components/PopoverTrigger/index.js.map +1 -1
- package/lib/components/PopoverTrigger/renderPopoverTrigger.d.ts +1 -1
- package/lib/components/PopoverTrigger/renderPopoverTrigger.js +1 -1
- package/lib/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
- package/lib/components/PopoverTrigger/usePopoverTrigger.d.ts +2 -2
- package/lib/components/PopoverTrigger/usePopoverTrigger.js +39 -54
- package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/popoverContext.d.ts +1 -1
- package/lib/popoverContext.js +3 -7
- 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.d.ts +2 -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.d.ts +1 -1
- package/lib-commonjs/components/Popover/renderPopover.js +31 -29
- package/lib-commonjs/components/Popover/renderPopover.js.map +1 -1
- package/lib-commonjs/components/Popover/usePopover.d.ts +2 -2
- package/lib-commonjs/components/Popover/usePopover.js +50 -62
- 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.d.ts +2 -2
- 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.d.ts +1 -1
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +12 -15
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.d.ts +4 -5
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +50 -65
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +2 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +38 -24
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.d.ts +2 -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.d.ts +9 -2
- 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.d.ts +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.d.ts +2 -2
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +44 -60
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib-commonjs/index.js +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/popoverContext.d.ts +1 -1
- package/lib-commonjs/popoverContext.js +5 -9
- package/lib-commonjs/popoverContext.js.map +1 -1
- package/package.json +13 -15
- 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-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
@@ -1,55 +1,48 @@
|
|
1
|
-
import { __assign } from "tslib";
|
2
1
|
import * as React from 'react';
|
3
|
-
import {
|
2
|
+
import { applyTriggerPropsToChildren, getTriggerChild, shouldPreventDefaultOnKeyDown, useMergedRefs, useMergedEventCallbacks, useEventCallback } from '@fluentui/react-utilities';
|
4
3
|
import { useModalAttributes } from '@fluentui/react-tabster';
|
5
|
-
import {
|
4
|
+
import { usePopoverContext_unstable } from '../../popoverContext';
|
6
5
|
/**
|
7
6
|
* Create the state required to render PopoverTrigger.
|
8
7
|
*
|
9
8
|
* The returned state can be modified with hooks such as usePopoverTriggerStyles,
|
10
|
-
* before being passed to
|
9
|
+
* before being passed to renderPopoverTrigger_unstable.
|
11
10
|
*
|
12
11
|
* @param props - props from this instance of PopoverTrigger
|
13
12
|
*/
|
14
13
|
|
15
|
-
export
|
16
|
-
var
|
17
|
-
return context.setOpen;
|
18
|
-
});
|
19
|
-
var open = usePopoverContext(function (context) {
|
20
|
-
return context.open;
|
21
|
-
});
|
22
|
-
var triggerRef = usePopoverContext(function (context) {
|
23
|
-
return context.triggerRef;
|
24
|
-
});
|
25
|
-
var openOnHover = usePopoverContext(function (context) {
|
26
|
-
return context.openOnHover;
|
27
|
-
});
|
28
|
-
var openOnContext = usePopoverContext(function (context) {
|
29
|
-
return context.openOnContext;
|
30
|
-
});
|
31
|
-
var triggerAttributes = useModalAttributes().triggerAttributes;
|
32
|
-
var onContextMenu = useEventCallback(function (e) {
|
33
|
-
var _a, _b;
|
14
|
+
export const usePopoverTrigger_unstable = props => {
|
15
|
+
var _a, _b, _c, _d, _e;
|
34
16
|
|
17
|
+
const {
|
18
|
+
children
|
19
|
+
} = props;
|
20
|
+
const child = /*#__PURE__*/React.isValidElement(children) ? getTriggerChild(children) : undefined;
|
21
|
+
const setOpen = usePopoverContext_unstable(context => context.setOpen);
|
22
|
+
const open = usePopoverContext_unstable(context => context.open);
|
23
|
+
const triggerRef = usePopoverContext_unstable(context => context.triggerRef);
|
24
|
+
const openOnHover = usePopoverContext_unstable(context => context.openOnHover);
|
25
|
+
const openOnContext = usePopoverContext_unstable(context => context.openOnContext);
|
26
|
+
const trapFocus = usePopoverContext_unstable(context => context.trapFocus);
|
27
|
+
const {
|
28
|
+
triggerAttributes
|
29
|
+
} = useModalAttributes();
|
30
|
+
|
31
|
+
const onContextMenu = e => {
|
35
32
|
if (openOnContext) {
|
36
33
|
e.preventDefault();
|
37
34
|
setOpen(e, true);
|
38
35
|
}
|
36
|
+
};
|
39
37
|
|
40
|
-
|
41
|
-
});
|
42
|
-
var onClick = useEventCallback(function (e) {
|
43
|
-
var _a, _b;
|
44
|
-
|
38
|
+
const onClick = e => {
|
45
39
|
if (!openOnContext) {
|
46
40
|
setOpen(e, !open);
|
47
41
|
}
|
42
|
+
};
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
var onKeyDown = useEventCallback(function (e) {
|
52
|
-
var _a, _b, _c;
|
44
|
+
const onKeyDown = e => {
|
45
|
+
var _a;
|
53
46
|
|
54
47
|
if (shouldPreventDefaultOnKeyDown(e) && (e.key === ' ' || e.key === 'Enter')) {
|
55
48
|
e.preventDefault();
|
@@ -59,39 +52,31 @@ export var usePopoverTrigger = function (props) {
|
|
59
52
|
if (e.key === 'Escape') {
|
60
53
|
setOpen(e, false);
|
61
54
|
}
|
55
|
+
};
|
62
56
|
|
63
|
-
|
64
|
-
});
|
65
|
-
var onMouseEnter = useEventCallback(function (e) {
|
66
|
-
var _a, _b;
|
67
|
-
|
57
|
+
const onMouseEnter = useEventCallback(e => {
|
68
58
|
if (openOnHover) {
|
69
59
|
setOpen(e, true);
|
70
60
|
}
|
71
|
-
|
72
|
-
(_b = (_a = child.props) === null || _a === void 0 ? void 0 : _a.onMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
73
61
|
});
|
74
|
-
var onMouseLeave = useEventCallback(function (e) {
|
75
|
-
var _a, _b;
|
76
62
|
|
63
|
+
const onMouseLeave = e => {
|
77
64
|
if (openOnHover) {
|
78
65
|
setOpen(e, false);
|
79
66
|
}
|
67
|
+
};
|
80
68
|
|
81
|
-
(_b = (_a = child.props) === null || _a === void 0 ? void 0 : _a.onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
82
|
-
});
|
83
|
-
var child = React.Children.only(props.children);
|
84
69
|
return {
|
85
|
-
children:
|
86
|
-
'aria-haspopup': 'true'
|
87
|
-
|
88
|
-
onClick: onClick,
|
89
|
-
onMouseEnter: onMouseEnter,
|
90
|
-
onKeyDown: onKeyDown,
|
91
|
-
onMouseLeave: onMouseLeave,
|
92
|
-
onContextMenu: onContextMenu,
|
93
|
-
ref: useMergedRefs(child.ref
|
94
|
-
})
|
70
|
+
children: applyTriggerPropsToChildren(props.children, { ...triggerAttributes,
|
71
|
+
'aria-haspopup': trapFocus ? 'dialog' : 'true',
|
72
|
+
...(child === null || child === void 0 ? void 0 : child.props),
|
73
|
+
onClick: useMergedEventCallbacks((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.onClick, onClick),
|
74
|
+
onMouseEnter: useMergedEventCallbacks((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.onMouseEnter, onMouseEnter),
|
75
|
+
onKeyDown: useMergedEventCallbacks((_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c.onKeyDown, onKeyDown),
|
76
|
+
onMouseLeave: useMergedEventCallbacks((_d = child === null || child === void 0 ? void 0 : child.props) === null || _d === void 0 ? void 0 : _d.onMouseLeave, onMouseLeave),
|
77
|
+
onContextMenu: useMergedEventCallbacks((_e = child === null || child === void 0 ? void 0 : child.props) === null || _e === void 0 ? void 0 : _e.onContextMenu, onContextMenu),
|
78
|
+
ref: useMergedRefs(triggerRef, child === null || child === void 0 ? void 0 : child.ref)
|
79
|
+
})
|
95
80
|
};
|
96
81
|
};
|
97
82
|
//# sourceMappingURL=usePopoverTrigger.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/PopoverTrigger/usePopoverTrigger.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from 'react';\nimport {\n applyTriggerPropsToChildren,\n getTriggerChild,\n shouldPreventDefaultOnKeyDown,\n useMergedRefs,\n useMergedEventCallbacks,\n useEventCallback,\n} from '@fluentui/react-utilities';\nimport { useModalAttributes } from '@fluentui/react-tabster';\nimport { usePopoverContext_unstable } from '../../popoverContext';\nimport type { PopoverTriggerChildProps, PopoverTriggerProps, PopoverTriggerState } from './PopoverTrigger.types';\n\n/**\n * Create the state required to render PopoverTrigger.\n *\n * The returned state can be modified with hooks such as usePopoverTriggerStyles,\n * before being passed to renderPopoverTrigger_unstable.\n *\n * @param props - props from this instance of PopoverTrigger\n */\nexport const usePopoverTrigger_unstable = (props: PopoverTriggerProps): PopoverTriggerState => {\n const { children } = props;\n const child = React.isValidElement(children) ? getTriggerChild(children) : undefined;\n\n const setOpen = usePopoverContext_unstable(context => context.setOpen);\n const open = usePopoverContext_unstable(context => context.open);\n const triggerRef = usePopoverContext_unstable(context => context.triggerRef);\n const openOnHover = usePopoverContext_unstable(context => context.openOnHover);\n const openOnContext = usePopoverContext_unstable(context => context.openOnContext);\n const trapFocus = usePopoverContext_unstable(context => context.trapFocus);\n const { triggerAttributes } = useModalAttributes();\n\n const onContextMenu = (e: React.MouseEvent<HTMLElement>) => {\n if (openOnContext) {\n e.preventDefault();\n setOpen(e, true);\n }\n };\n\n const onClick = (e: React.MouseEvent<HTMLElement>) => {\n if (!openOnContext) {\n setOpen(e, !open);\n }\n };\n\n const onKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {\n if (shouldPreventDefaultOnKeyDown(e) && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n (e.target as HTMLElement)?.click();\n }\n\n if (e.key === 'Escape') {\n setOpen(e, false);\n }\n };\n\n const onMouseEnter = useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (openOnHover) {\n setOpen(e, true);\n }\n });\n\n const onMouseLeave = (e: React.MouseEvent<HTMLElement>) => {\n if (openOnHover) {\n setOpen(e, false);\n }\n };\n\n return {\n children: applyTriggerPropsToChildren<PopoverTriggerChildProps>(props.children, {\n ...triggerAttributes,\n 'aria-haspopup': trapFocus ? 'dialog' : 'true',\n ...child?.props,\n onClick: useMergedEventCallbacks(child?.props?.onClick, onClick),\n onMouseEnter: useMergedEventCallbacks(child?.props?.onMouseEnter, onMouseEnter),\n onKeyDown: useMergedEventCallbacks(child?.props?.onKeyDown, onKeyDown),\n onMouseLeave: useMergedEventCallbacks(child?.props?.onMouseLeave, onMouseLeave),\n onContextMenu: useMergedEventCallbacks(child?.props?.onContextMenu, onContextMenu),\n ref: useMergedRefs(triggerRef, child?.ref),\n }),\n };\n};\n"],"sourceRoot":"../src/"}
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './Popover';\nexport * from './PopoverSurface';\nexport * from './popoverContext';\nexport * from './PopoverTrigger';\n"]}
|
package/lib/popoverContext.d.ts
CHANGED
@@ -5,4 +5,4 @@ export declare const PopoverContext: Context<PopoverContextValue>;
|
|
5
5
|
* Context shared between Popover and its children components
|
6
6
|
*/
|
7
7
|
export declare type PopoverContextValue = Pick<PopoverState, 'open' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'noArrow' | 'arrowRef' | 'size' | 'appearance' | 'trapFocus'>;
|
8
|
-
export declare const
|
8
|
+
export declare const usePopoverContext_unstable: <T>(selector: ContextSelector<PopoverContextValue, T>) => T;
|
package/lib/popoverContext.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
import { createContext, useContextSelector } from '@fluentui/react-context-selector';
|
2
|
-
export
|
2
|
+
export const PopoverContext = /*#__PURE__*/createContext({
|
3
3
|
open: false,
|
4
|
-
setOpen:
|
5
|
-
return null;
|
6
|
-
},
|
4
|
+
setOpen: () => null,
|
7
5
|
triggerRef: {
|
8
6
|
current: null
|
9
7
|
},
|
@@ -18,7 +16,5 @@ export var PopoverContext = /*#__PURE__*/createContext({
|
|
18
16
|
size: 'medium',
|
19
17
|
trapFocus: false
|
20
18
|
});
|
21
|
-
export
|
22
|
-
return useContextSelector(PopoverContext, selector);
|
23
|
-
};
|
19
|
+
export const usePopoverContext_unstable = selector => useContextSelector(PopoverContext, selector);
|
24
20
|
//# sourceMappingURL=popoverContext.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["popoverContext.ts"],"names":[],"mappings":"AAAA,SAAS,aAAT,EAAwB,kBAAxB,QAAkD,kCAAlD;AAIA,OAAO,MAAM,cAAc,gBAAiC,aAAa,CAAsB;AAC7F,EAAA,IAAI,EAAE,KADuF;AAE7F,EAAA,OAAO,EAAE,MAAM,IAF8E;AAG7F,EAAA,UAAU,EAAE;AAAE,IAAA,OAAO,EAAE;AAAX,GAHiF;AAI7F,EAAA,UAAU,EAAE;AAAE,IAAA,OAAO,EAAE;AAAX,GAJiF;AAK7F,EAAA,QAAQ,EAAE;AAAE,IAAA,OAAO,EAAE;AAAX,GALmF;AAM7F,EAAA,aAAa,EAAE,KAN8E;AAO7F,EAAA,WAAW,EAAE,KAPgF;AAQ7F,EAAA,IAAI,EAAE,QARuF;AAS7F,EAAA,SAAS,EAAE;AATkF,CAAtB,CAAlE;AA+BP,OAAO,MAAM,0BAA0B,GAAO,QAAJ,IACxC,kBAAkB,CAAC,cAAD,EAAiB,QAAjB,CADb","sourcesContent":["import { createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport type { ContextSelector, Context } from '@fluentui/react-context-selector';\nimport type { PopoverState } from './components/Popover/index';\n\nexport const PopoverContext: Context<PopoverContextValue> = createContext<PopoverContextValue>({\n open: false,\n setOpen: () => null,\n triggerRef: { current: null },\n contentRef: { current: null },\n arrowRef: { current: null },\n openOnContext: false,\n openOnHover: false,\n size: 'medium',\n trapFocus: false,\n});\n\n/**\n * Context shared between Popover and its children components\n */\nexport type PopoverContextValue = Pick<\n PopoverState,\n | 'open'\n | 'setOpen'\n | 'triggerRef'\n | 'contentRef'\n | 'openOnHover'\n | 'openOnContext'\n | 'mountNode'\n | 'noArrow'\n | 'arrowRef'\n | 'size'\n | 'appearance'\n | 'trapFocus'\n>;\n\nexport const usePopoverContext_unstable = <T>(selector: ContextSelector<PopoverContextValue, T>): T =>\n useContextSelector(PopoverContext, selector);\n"],"sourceRoot":"../src/"}
|
package/lib-commonjs/Popover.js
CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
|
7
|
-
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
8
|
|
9
9
|
tslib_1.__exportStar(require("./components/Popover/index"), exports);
|
10
10
|
//# sourceMappingURL=Popover.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["Popover.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,4BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/Popover/index';\n"],"sourceRoot":"../src/"}
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
|
7
|
-
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
8
|
|
9
9
|
tslib_1.__exportStar(require("./components/PopoverSurface/index"), exports);
|
10
10
|
//# sourceMappingURL=PopoverSurface.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["PopoverSurface.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mCAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/PopoverSurface/index';\n"],"sourceRoot":"../src/"}
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
|
7
|
-
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
8
|
|
9
9
|
tslib_1.__exportStar(require("./components/PopoverTrigger/index"), exports);
|
10
10
|
//# sourceMappingURL=PopoverTrigger.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["PopoverTrigger.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mCAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/PopoverTrigger/index';\n"],"sourceRoot":"../src/"}
|
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.Popover = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const usePopover_1 = /*#__PURE__*/require("./usePopover");
|
9
9
|
|
10
|
-
|
10
|
+
const renderPopover_1 = /*#__PURE__*/require("./renderPopover");
|
11
11
|
/**
|
12
12
|
* Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.
|
13
13
|
*/
|
14
14
|
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
return renderPopover_1.
|
16
|
+
const Popover = props => {
|
17
|
+
const state = usePopover_1.usePopover_unstable(props);
|
18
|
+
return renderPopover_1.renderPopover_unstable(state);
|
19
19
|
};
|
20
20
|
|
21
21
|
exports.Popover = Popover;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/Popover/Popover.tsx"],"names":[],"mappings":";;;;;;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,OAAO,GAA2B,KAAK,IAAG;AACrD,QAAM,KAAK,GAAG,YAAA,CAAA,mBAAA,CAAoB,KAApB,CAAd;AAEA,SAAO,eAAA,CAAA,sBAAA,CAAuB,KAAvB,CAAP;AACD,CAJM;;AAAM,OAAA,CAAA,OAAA,GAAO,OAAP;AAMb,OAAA,CAAA,OAAA,CAAQ,WAAR,GAAsB,SAAtB","sourcesContent":["import * as React from 'react';\nimport { usePopover_unstable } from './usePopover';\nimport { renderPopover_unstable } from './renderPopover';\nimport type { PopoverProps } from './Popover.types';\n\n/**\n * Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.\n */\nexport const Popover: React.FC<PopoverProps> = props => {\n const state = usePopover_unstable(props);\n\n return renderPopover_unstable(state);\n};\n\nPopover.displayName = 'Popover';\n"],"sourceRoot":"../src/"}
|
@@ -5,7 +5,7 @@ import type { PortalProps } from '@fluentui/react-portal';
|
|
5
5
|
* Determines popover padding and arrow size
|
6
6
|
*/
|
7
7
|
export declare type PopoverSize = 'small' | 'medium' | 'large';
|
8
|
-
|
8
|
+
declare type PopoverCommons = Pick<PortalProps, 'mountNode'> & {
|
9
9
|
/**
|
10
10
|
* Controls the opening of the Popover
|
11
11
|
*/
|
@@ -100,3 +100,4 @@ export declare type OnOpenChangeData = {
|
|
100
100
|
* The supported events that will trigger open/close of the menu
|
101
101
|
*/
|
102
102
|
export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement> | React.FocusEvent<HTMLElement>;
|
103
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":""}
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/Popover/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,WAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Popover';\nexport * from './Popover.types';\nexport * from './renderPopover';\nexport * from './usePopover';\n"],"sourceRoot":"../src/"}
|
@@ -3,46 +3,48 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.renderPopover_unstable = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
|
-
|
10
|
+
const popoverContext_1 = /*#__PURE__*/require("../../popoverContext");
|
11
11
|
/**
|
12
12
|
* Render the final JSX of Popover
|
13
13
|
*/
|
14
14
|
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
const renderPopover_unstable = state => {
|
17
|
+
const {
|
18
|
+
open,
|
19
|
+
setOpen,
|
20
|
+
triggerRef,
|
21
|
+
contentRef,
|
22
|
+
openOnContext,
|
23
|
+
openOnHover,
|
24
|
+
mountNode,
|
25
|
+
arrowRef,
|
26
|
+
size,
|
27
|
+
noArrow,
|
28
|
+
appearance,
|
29
|
+
trapFocus
|
30
|
+
} = state;
|
29
31
|
return React.createElement(popoverContext_1.PopoverContext.Provider, {
|
30
32
|
value: {
|
31
|
-
open
|
32
|
-
setOpen
|
33
|
-
triggerRef
|
34
|
-
contentRef
|
35
|
-
openOnHover
|
36
|
-
openOnContext
|
37
|
-
mountNode
|
38
|
-
arrowRef
|
39
|
-
size
|
40
|
-
noArrow
|
41
|
-
appearance
|
42
|
-
trapFocus
|
33
|
+
open,
|
34
|
+
setOpen,
|
35
|
+
triggerRef,
|
36
|
+
contentRef,
|
37
|
+
openOnHover,
|
38
|
+
openOnContext,
|
39
|
+
mountNode,
|
40
|
+
arrowRef,
|
41
|
+
size,
|
42
|
+
noArrow,
|
43
|
+
appearance,
|
44
|
+
trapFocus
|
43
45
|
}
|
44
46
|
}, state.children);
|
45
47
|
};
|
46
48
|
|
47
|
-
exports.
|
49
|
+
exports.renderPopover_unstable = renderPopover_unstable;
|
48
50
|
//# sourceMappingURL=renderPopover.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/Popover/renderPopover.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,gBAAA,gBAAA,OAAA,CAAA,sBAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,sBAAsB,GAAI,KAAD,IAAwB;AAC5D,QAAM;AACJ,IAAA,IADI;AAEJ,IAAA,OAFI;AAGJ,IAAA,UAHI;AAIJ,IAAA,UAJI;AAKJ,IAAA,aALI;AAMJ,IAAA,WANI;AAOJ,IAAA,SAPI;AAQJ,IAAA,QARI;AASJ,IAAA,IATI;AAUJ,IAAA,OAVI;AAWJ,IAAA,UAXI;AAYJ,IAAA;AAZI,MAaF,KAbJ;AAeA,SACE,KAAA,CAAA,aAAA,CAAC,gBAAA,CAAA,cAAA,CAAe,QAAhB,EAAwB;AACtB,IAAA,KAAK,EAAE;AACL,MAAA,IADK;AAEL,MAAA,OAFK;AAGL,MAAA,UAHK;AAIL,MAAA,UAJK;AAKL,MAAA,WALK;AAML,MAAA,aANK;AAOL,MAAA,SAPK;AAQL,MAAA,QARK;AASL,MAAA,IATK;AAUL,MAAA,OAVK;AAWL,MAAA,UAXK;AAYL,MAAA;AAZK;AADe,GAAxB,EAgBG,KAAK,CAAC,QAhBT,CADF;AAoBD,CApCM;;AAAM,OAAA,CAAA,sBAAA,GAAsB,sBAAtB","sourcesContent":["import * as React from 'react';\nimport { PopoverContext } from '../../popoverContext';\nimport type { PopoverState } from './Popover.types';\n\n/**\n * Render the final JSX of Popover\n */\nexport const renderPopover_unstable = (state: PopoverState) => {\n const {\n open,\n setOpen,\n triggerRef,\n contentRef,\n openOnContext,\n openOnHover,\n mountNode,\n arrowRef,\n size,\n noArrow,\n appearance,\n trapFocus,\n } = state;\n\n return (\n <PopoverContext.Provider\n value={{\n open,\n setOpen,\n triggerRef,\n contentRef,\n openOnHover,\n openOnContext,\n mountNode,\n arrowRef,\n size,\n noArrow,\n appearance,\n trapFocus,\n }}\n >\n {state.children}\n </PopoverContext.Provider>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -3,8 +3,8 @@ import type { PopoverProps, PopoverState } from './Popover.types';
|
|
3
3
|
* Create the state required to render Popover.
|
4
4
|
*
|
5
5
|
* The returned state can be modified with hooks such as usePopoverStyles,
|
6
|
-
* before being passed to
|
6
|
+
* before being passed to renderPopover_unstable.
|
7
7
|
*
|
8
8
|
* @param props - props from this instance of Popover
|
9
9
|
*/
|
10
|
-
export declare const
|
10
|
+
export declare const usePopover_unstable: (props: PopoverProps) => PopoverState;
|
@@ -3,97 +3,85 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.usePopover_unstable = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
|
-
|
10
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
11
11
|
|
12
|
-
|
12
|
+
const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
|
13
13
|
|
14
|
-
|
14
|
+
const react_positioning_1 = /*#__PURE__*/require("@fluentui/react-positioning");
|
15
15
|
|
16
|
-
|
16
|
+
const react_portal_1 = /*#__PURE__*/require("@fluentui/react-portal");
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
var index_1 = /*#__PURE__*/require("../PopoverSurface/index");
|
18
|
+
const index_1 = /*#__PURE__*/require("../PopoverSurface/index");
|
21
19
|
/**
|
22
20
|
* Create the state required to render Popover.
|
23
21
|
*
|
24
22
|
* The returned state can be modified with hooks such as usePopoverStyles,
|
25
|
-
* before being passed to
|
23
|
+
* before being passed to renderPopover_unstable.
|
26
24
|
*
|
27
25
|
* @param props - props from this instance of Popover
|
28
26
|
*/
|
29
27
|
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
setContextTarget = _a[1];
|
35
|
-
|
36
|
-
var initialState = tslib_1.__assign({
|
29
|
+
const usePopover_unstable = props => {
|
30
|
+
const [contextTarget, setContextTarget] = react_positioning_1.usePopperMouseTarget();
|
31
|
+
const initialState = {
|
37
32
|
size: 'medium',
|
38
|
-
contextTarget
|
39
|
-
setContextTarget
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
var targetDocument = react_shared_contexts_1.useFluent().targetDocument;
|
33
|
+
contextTarget,
|
34
|
+
setContextTarget,
|
35
|
+
...props
|
36
|
+
};
|
37
|
+
const [open, setOpen] = useOpenState(initialState);
|
38
|
+
const popperRefs = usePopoverRefs(initialState);
|
39
|
+
const {
|
40
|
+
targetDocument
|
41
|
+
} = react_shared_contexts_1.useFluent();
|
48
42
|
react_utilities_1.useOnClickOutside({
|
49
43
|
contains: react_portal_1.elementContains,
|
50
44
|
element: targetDocument,
|
51
|
-
callback:
|
52
|
-
return setOpen(ev, false);
|
53
|
-
},
|
45
|
+
callback: ev => setOpen(ev, false),
|
54
46
|
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
55
47
|
disabled: !open
|
56
48
|
});
|
57
49
|
react_utilities_1.useOnScrollOutside({
|
58
50
|
contains: react_portal_1.elementContains,
|
59
51
|
element: targetDocument,
|
60
|
-
callback:
|
61
|
-
return setOpen(ev, false);
|
62
|
-
},
|
52
|
+
callback: ev => setOpen(ev, false),
|
63
53
|
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
64
|
-
disabled: !open || !initialState.openOnContext
|
65
|
-
|
66
|
-
return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, initialState), popperRefs), {
|
67
|
-
open: open,
|
68
|
-
setOpen: setOpen,
|
69
|
-
setContextTarget: setContextTarget,
|
70
|
-
contextTarget: contextTarget
|
54
|
+
disabled: !open || !initialState.openOnContext // only close on scroll for context
|
55
|
+
|
71
56
|
});
|
57
|
+
return { ...initialState,
|
58
|
+
...popperRefs,
|
59
|
+
open,
|
60
|
+
setOpen,
|
61
|
+
setContextTarget,
|
62
|
+
contextTarget
|
63
|
+
};
|
72
64
|
};
|
73
65
|
|
74
|
-
exports.
|
66
|
+
exports.usePopover_unstable = usePopover_unstable;
|
75
67
|
/**
|
76
68
|
* Creates and manages the Popover open state
|
77
69
|
*/
|
78
70
|
|
79
71
|
function useOpenState(state) {
|
80
|
-
|
72
|
+
const onOpenChange = react_utilities_1.useEventCallback((e, data) => {
|
81
73
|
var _a;
|
82
74
|
|
83
75
|
return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
|
84
76
|
});
|
85
|
-
|
86
|
-
var _a = react_utilities_1.useControllableState({
|
77
|
+
const [open, setOpenState] = react_utilities_1.useControllableState({
|
87
78
|
state: state.open,
|
88
79
|
defaultState: state.defaultOpen,
|
89
80
|
initialState: false
|
90
|
-
})
|
91
|
-
open = _a[0],
|
92
|
-
setOpenState = _a[1];
|
93
|
-
|
81
|
+
});
|
94
82
|
state.open = open !== undefined ? open : state.open;
|
95
|
-
|
96
|
-
|
83
|
+
const setContextTarget = state.setContextTarget;
|
84
|
+
const setOpen = React.useCallback((e, shouldOpen) => {
|
97
85
|
if (shouldOpen && e.type === 'contextmenu') {
|
98
86
|
setContextTarget(e);
|
99
87
|
}
|
@@ -102,7 +90,7 @@ function useOpenState(state) {
|
|
102
90
|
setContextTarget(undefined);
|
103
91
|
}
|
104
92
|
|
105
|
-
setOpenState(
|
93
|
+
setOpenState(prevOpen => {
|
106
94
|
// More than one event (mouse, focus, keyboard) can request the Popover to close
|
107
95
|
// We assume the first event is the correct one
|
108
96
|
if (prevOpen !== shouldOpen) {
|
@@ -122,12 +110,12 @@ function useOpenState(state) {
|
|
122
110
|
|
123
111
|
|
124
112
|
function usePopoverRefs(state) {
|
125
|
-
|
113
|
+
const popperOptions = {
|
126
114
|
position: 'above',
|
127
115
|
align: 'center',
|
128
|
-
target: state.openOnContext ? state.contextTarget : undefined
|
129
|
-
|
130
|
-
|
116
|
+
target: state.openOnContext ? state.contextTarget : undefined,
|
117
|
+
...react_positioning_1.resolvePositioningShorthand(state.positioning)
|
118
|
+
}; // no reason to render arrow when covering the target
|
131
119
|
|
132
120
|
if (popperOptions.coverTarget) {
|
133
121
|
state.noArrow = true;
|
@@ -137,15 +125,15 @@ function usePopoverRefs(state) {
|
|
137
125
|
popperOptions.offset = react_positioning_1.mergeArrowOffset(popperOptions.offset, index_1.arrowHeights[state.size]);
|
138
126
|
}
|
139
127
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
128
|
+
const {
|
129
|
+
targetRef: triggerRef,
|
130
|
+
containerRef: contentRef,
|
131
|
+
arrowRef
|
132
|
+
} = react_positioning_1.usePopper(popperOptions);
|
145
133
|
return {
|
146
|
-
triggerRef
|
147
|
-
contentRef
|
148
|
-
arrowRef
|
134
|
+
triggerRef,
|
135
|
+
contentRef,
|
136
|
+
arrowRef
|
149
137
|
};
|
150
138
|
}
|
151
139
|
//# sourceMappingURL=usePopover.js.map
|