@fluentui/react-popover 9.3.1 → 9.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +105 -1
- package/CHANGELOG.md +31 -2
- package/lib/components/Popover/usePopover.js +3 -10
- package/lib/components/Popover/usePopover.js.map +1 -1
- package/lib-amd/Popover.js +6 -0
- package/lib-amd/Popover.js.map +1 -0
- package/lib-amd/PopoverSurface.js +6 -0
- package/lib-amd/PopoverSurface.js.map +1 -0
- package/lib-amd/PopoverTrigger.js +6 -0
- package/lib-amd/PopoverTrigger.js.map +1 -0
- package/lib-amd/components/Popover/Popover.js +15 -0
- package/lib-amd/components/Popover/Popover.js.map +1 -0
- package/lib-amd/components/Popover/Popover.types.js +5 -0
- package/lib-amd/components/Popover/Popover.types.js.map +1 -0
- package/lib-amd/components/Popover/constants.js +15 -0
- package/lib-amd/components/Popover/constants.js.map +1 -0
- package/lib-amd/components/Popover/index.js +9 -0
- package/lib-amd/components/Popover/index.js.map +1 -0
- package/lib-amd/components/Popover/renderPopover.js +32 -0
- package/lib-amd/components/Popover/renderPopover.js.map +1 -0
- package/lib-amd/components/Popover/usePopover.js +144 -0
- package/lib-amd/components/Popover/usePopover.js.map +1 -0
- package/lib-amd/components/PopoverSurface/PopoverSurface.js +15 -0
- package/lib-amd/components/PopoverSurface/PopoverSurface.js.map +1 -0
- package/lib-amd/components/PopoverSurface/PopoverSurface.types.js +5 -0
- package/lib-amd/components/PopoverSurface/PopoverSurface.types.js.map +1 -0
- package/lib-amd/components/PopoverSurface/index.js +10 -0
- package/lib-amd/components/PopoverSurface/index.js.map +1 -0
- package/lib-amd/components/PopoverSurface/renderPopoverSurface.js +20 -0
- package/lib-amd/components/PopoverSurface/renderPopoverSurface.js.map +1 -0
- package/lib-amd/components/PopoverSurface/usePopoverSurface.js +65 -0
- package/lib-amd/components/PopoverSurface/usePopoverSurface.js.map +1 -0
- package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js +44 -0
- package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -0
- package/lib-amd/components/PopoverTrigger/PopoverTrigger.js +17 -0
- package/lib-amd/components/PopoverTrigger/PopoverTrigger.js.map +1 -0
- package/lib-amd/components/PopoverTrigger/PopoverTrigger.types.js +5 -0
- package/lib-amd/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -0
- package/lib-amd/components/PopoverTrigger/index.js +9 -0
- package/lib-amd/components/PopoverTrigger/index.js.map +1 -0
- package/lib-amd/components/PopoverTrigger/renderPopoverTrigger.js +13 -0
- package/lib-amd/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -0
- package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js +61 -0
- package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js.map +1 -0
- package/lib-amd/index.js +20 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/popoverContext.js +28 -0
- package/lib-amd/popoverContext.js.map +1 -0
- package/lib-commonjs/components/Popover/usePopover.js +3 -10
- package/lib-commonjs/components/Popover/usePopover.js.map +1 -1
- package/package.json +9 -9
- package/Spec.md +0 -516
@@ -0,0 +1,20 @@
|
|
1
|
+
define(["require", "exports", "tslib", "react", "@fluentui/react-portal", "@fluentui/react-utilities"], function (require, exports, tslib_1, React, react_portal_1, react_utilities_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.renderPopoverSurface_unstable = void 0;
|
5
|
+
/**
|
6
|
+
* Render the final JSX of PopoverSurface
|
7
|
+
*/
|
8
|
+
var renderPopoverSurface_unstable = function (state) {
|
9
|
+
var _a = react_utilities_1.getSlots(state), slots = _a.slots, slotProps = _a.slotProps;
|
10
|
+
var surface = (React.createElement(slots.root, tslib_1.__assign({}, slotProps.root),
|
11
|
+
state.withArrow && React.createElement("div", { ref: state.arrowRef, className: state.arrowClassName }),
|
12
|
+
slotProps.root.children));
|
13
|
+
if (state.inline) {
|
14
|
+
return surface;
|
15
|
+
}
|
16
|
+
return React.createElement(react_portal_1.Portal, { mountNode: state.mountNode }, surface);
|
17
|
+
};
|
18
|
+
exports.renderPopoverSurface_unstable = renderPopoverSurface_unstable;
|
19
|
+
});
|
20
|
+
//# sourceMappingURL=renderPopoverSurface.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"renderPopoverSurface.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":";;;;IAKA;;OAEG;IACI,IAAM,6BAA6B,GAAG,UAAC,KAA0B;QAChE,IAAA,KAAuB,0BAAQ,CAAsB,KAAK,CAAC,EAAzD,KAAK,WAAA,EAAE,SAAS,eAAyC,CAAC;QAElE,IAAM,OAAO,GAAG,CACd,oBAAC,KAAK,CAAC,IAAI,uBAAK,SAAS,CAAC,IAAI;YAC3B,KAAK,CAAC,SAAS,IAAI,6BAAK,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,cAAc,GAAI;YAChF,SAAS,CAAC,IAAI,CAAC,QAAQ,CACb,CACd,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,EAAE;YAChB,OAAO,OAAO,CAAC;SAChB;QAED,OAAO,oBAAC,qBAAM,IAAC,SAAS,EAAE,KAAK,CAAC,SAAS,IAAG,OAAO,CAAU,CAAC;IAChE,CAAC,CAAC;IAfW,QAAA,6BAA6B,iCAexC","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.withArrow && <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"]}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
define(["require", "exports", "tslib", "@fluentui/react-utilities", "@fluentui/react-tabster", "../../popoverContext"], function (require, exports, tslib_1, react_utilities_1, react_tabster_1, popoverContext_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.usePopoverSurface_unstable = void 0;
|
5
|
+
/**
|
6
|
+
* Create the state required to render PopoverSurface.
|
7
|
+
*
|
8
|
+
* The returned state can be modified with hooks such as usePopoverSurfaceStyles_unstable,
|
9
|
+
* before being passed to renderPopoverSurface_unstable.
|
10
|
+
*
|
11
|
+
* @param props - props from this instance of PopoverSurface
|
12
|
+
* @param ref - reference to root HTMLDivElement of PopoverSurface
|
13
|
+
*/
|
14
|
+
var usePopoverSurface_unstable = function (props, ref) {
|
15
|
+
var contentRef = popoverContext_1.usePopoverContext_unstable(function (context) { return context.contentRef; });
|
16
|
+
var openOnHover = popoverContext_1.usePopoverContext_unstable(function (context) { return context.openOnHover; });
|
17
|
+
var setOpen = popoverContext_1.usePopoverContext_unstable(function (context) { return context.setOpen; });
|
18
|
+
var mountNode = popoverContext_1.usePopoverContext_unstable(function (context) { return context.mountNode; });
|
19
|
+
var arrowRef = popoverContext_1.usePopoverContext_unstable(function (context) { return context.arrowRef; });
|
20
|
+
var size = popoverContext_1.usePopoverContext_unstable(function (context) { return context.size; });
|
21
|
+
var withArrow = popoverContext_1.usePopoverContext_unstable(function (context) { return context.withArrow; });
|
22
|
+
var appearance = popoverContext_1.usePopoverContext_unstable(function (context) { return context.appearance; });
|
23
|
+
var trapFocus = popoverContext_1.usePopoverContext_unstable(function (context) { return context.trapFocus; });
|
24
|
+
var legacyTrapFocus = popoverContext_1.usePopoverContext_unstable(function (context) { return context.legacyTrapFocus; });
|
25
|
+
var inline = popoverContext_1.usePopoverContext_unstable(function (context) { return context.inline; });
|
26
|
+
var modalAttributes = react_tabster_1.useModalAttributes({ trapFocus: trapFocus, legacyTrapFocus: legacyTrapFocus }).modalAttributes;
|
27
|
+
var state = {
|
28
|
+
inline: inline,
|
29
|
+
appearance: appearance,
|
30
|
+
withArrow: withArrow,
|
31
|
+
size: size,
|
32
|
+
arrowRef: arrowRef,
|
33
|
+
mountNode: mountNode,
|
34
|
+
components: {
|
35
|
+
root: 'div',
|
36
|
+
},
|
37
|
+
root: react_utilities_1.getNativeElementProps('div', tslib_1.__assign(tslib_1.__assign({ ref: react_utilities_1.useMergedRefs(ref, contentRef), role: trapFocus ? 'dialog' : 'group', 'aria-modal': trapFocus ? true : undefined }, modalAttributes), props)),
|
38
|
+
};
|
39
|
+
var _a = state.root, onMouseEnterOriginal = _a.onMouseEnter, onMouseLeaveOriginal = _a.onMouseLeave, onKeyDownOriginal = _a.onKeyDown;
|
40
|
+
state.root.onMouseEnter = function (e) {
|
41
|
+
if (openOnHover) {
|
42
|
+
setOpen(e, true);
|
43
|
+
}
|
44
|
+
onMouseEnterOriginal === null || onMouseEnterOriginal === void 0 ? void 0 : onMouseEnterOriginal(e);
|
45
|
+
};
|
46
|
+
state.root.onMouseLeave = function (e) {
|
47
|
+
if (openOnHover) {
|
48
|
+
setOpen(e, false);
|
49
|
+
}
|
50
|
+
onMouseLeaveOriginal === null || onMouseLeaveOriginal === void 0 ? void 0 : onMouseLeaveOriginal(e);
|
51
|
+
};
|
52
|
+
state.root.onKeyDown = function (e) {
|
53
|
+
var _a;
|
54
|
+
// only close if the event happened inside the current popover
|
55
|
+
// If using a stack of inline popovers, the user should call `stopPropagation` to avoid dismissing the entire stack
|
56
|
+
if (e.key === 'Escape' && ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
57
|
+
setOpen(e, false);
|
58
|
+
}
|
59
|
+
onKeyDownOriginal === null || onKeyDownOriginal === void 0 ? void 0 : onKeyDownOriginal(e);
|
60
|
+
};
|
61
|
+
return state;
|
62
|
+
};
|
63
|
+
exports.usePopoverSurface_unstable = usePopoverSurface_unstable;
|
64
|
+
});
|
65
|
+
//# sourceMappingURL=usePopoverSurface.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"usePopoverSurface.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverSurface/usePopoverSurface.ts"],"names":[],"mappings":";;;;IAMA;;;;;;;;OAQG;IACI,IAAM,0BAA0B,GAAG,UACxC,KAA0B,EAC1B,GAA8B;QAE9B,IAAM,UAAU,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,UAAU,EAAlB,CAAkB,CAAC,CAAC;QAC7E,IAAM,WAAW,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,WAAW,EAAnB,CAAmB,CAAC,CAAC;QAC/E,IAAM,OAAO,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,OAAO,EAAf,CAAe,CAAC,CAAC;QACvE,IAAM,SAAS,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,SAAS,EAAjB,CAAiB,CAAC,CAAC;QAC3E,IAAM,QAAQ,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,QAAQ,EAAhB,CAAgB,CAAC,CAAC;QACzE,IAAM,IAAI,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,IAAI,EAAZ,CAAY,CAAC,CAAC;QACjE,IAAM,SAAS,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,SAAS,EAAjB,CAAiB,CAAC,CAAC;QAC3E,IAAM,UAAU,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,UAAU,EAAlB,CAAkB,CAAC,CAAC;QAC7E,IA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AY,GAAG,UAAC,CAAmC;YAC5D,IAAI,WAAW,EAAE;gBACf,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;aACnB;YAED,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAG,CAAC,CAAC,CAAC;QAC5B,CAAC,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,SAAS,GAAG,UAAC,CAAsC;;YAC5D,8DAA8D;YAC9D,mHAAmH;YACnH,IAAI,CAAC,CAAC,GAAG,KAAK,QAAQ,KAAI,MAAA,UAAU,CAAC,OAAO,0CAAE,QAAQ,CAAC,CAAC,CAAC,MAAwB,CAAC,CAAA,EAAE;gBAClF,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;aACnB;YAED,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAG,CAAC,CAAC,CAAC;QACzB,CAAC,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IApEW,QAAA,0BAA0B,8BAoErC","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 withArrow = usePopoverContext_unstable(context => context.withArrow);\n const appearance = usePopoverContext_unstable(context => context.appearance);\n const trapFocus = usePopoverContext_unstable(context => context.trapFocus);\n const legacyTrapFocus = usePopoverContext_unstable(context => context.legacyTrapFocus);\n const inline = usePopoverContext_unstable(context => context.inline);\n const { modalAttributes } = useModalAttributes({ trapFocus, legacyTrapFocus });\n\n const state: PopoverSurfaceState = {\n inline,\n appearance,\n withArrow,\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' : 'group',\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"]}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
define(["require", "exports", "tslib", "@griffel/react", "@fluentui/react-positioning", "@fluentui/react-theme"], function (require, exports, tslib_1, react_1, react_positioning_1, react_theme_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.usePopoverSurfaceStyles_unstable = exports.arrowHeights = exports.popoverSurfaceClassNames = void 0;
|
5
|
+
exports.popoverSurfaceClassNames = {
|
6
|
+
root: 'fui-PopoverSurface',
|
7
|
+
};
|
8
|
+
exports.arrowHeights = {
|
9
|
+
small: 6,
|
10
|
+
medium: 8,
|
11
|
+
large: 8,
|
12
|
+
};
|
13
|
+
/**
|
14
|
+
* Styles for the root slot
|
15
|
+
*/
|
16
|
+
var useStyles = react_1.makeStyles({
|
17
|
+
root: tslib_1.__assign(tslib_1.__assign({ backgroundColor: react_theme_1.tokens.colorNeutralBackground1, boxShadow: react_theme_1.tokens.shadow16 }, react_1.shorthands.borderRadius(react_theme_1.tokens.borderRadiusMedium)), react_1.shorthands.border('1px', 'solid', react_theme_1.tokens.colorTransparentStroke)),
|
18
|
+
inverted: {
|
19
|
+
backgroundColor: react_theme_1.tokens.colorNeutralBackgroundStatic,
|
20
|
+
color: react_theme_1.tokens.colorNeutralForegroundStaticInverted,
|
21
|
+
},
|
22
|
+
brand: {
|
23
|
+
backgroundColor: react_theme_1.tokens.colorBrandBackground,
|
24
|
+
color: react_theme_1.tokens.colorNeutralForegroundOnBrand,
|
25
|
+
},
|
26
|
+
smallPadding: tslib_1.__assign({}, react_1.shorthands.padding('12px')),
|
27
|
+
mediumPadding: tslib_1.__assign({}, react_1.shorthands.padding('16px')),
|
28
|
+
largePadding: tslib_1.__assign({}, react_1.shorthands.padding('20px')),
|
29
|
+
smallArrow: react_positioning_1.createArrowHeightStyles(exports.arrowHeights.small),
|
30
|
+
mediumLargeArrow: react_positioning_1.createArrowHeightStyles(exports.arrowHeights.medium),
|
31
|
+
arrow: react_positioning_1.createArrowStyles({ arrowHeight: undefined }),
|
32
|
+
});
|
33
|
+
/**
|
34
|
+
* Apply styling to the PopoverSurface slots based on the state
|
35
|
+
*/
|
36
|
+
var usePopoverSurfaceStyles_unstable = function (state) {
|
37
|
+
var styles = useStyles();
|
38
|
+
state.root.className = react_1.mergeClasses(exports.popoverSurfaceClassNames.root, styles.root, state.size === 'small' && styles.smallPadding, state.size === 'medium' && styles.mediumPadding, state.size === 'large' && styles.largePadding, state.appearance === 'inverted' && styles.inverted, state.appearance === 'brand' && styles.brand, state.root.className);
|
39
|
+
state.arrowClassName = react_1.mergeClasses(styles.arrow, state.size === 'small' ? styles.smallArrow : styles.mediumLargeArrow);
|
40
|
+
return state;
|
41
|
+
};
|
42
|
+
exports.usePopoverSurfaceStyles_unstable = usePopoverSurfaceStyles_unstable;
|
43
|
+
});
|
44
|
+
//# sourceMappingURL=usePopoverSurfaceStyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"usePopoverSurfaceStyles.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverSurface/usePopoverSurfaceStyles.ts"],"names":[],"mappings":";;;;IAOa,QAAA,wBAAwB,GAAwC;QAC3E,IAAI,EAAE,oBAAoB;KAC3B,CAAC;IAEW,QAAA,YAAY,GAAgC;QACvD,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,KAAK,EAAE,CAAC;KACT,CAAC;IAEF;;OAEG;IACH,IAAM,SAAS,GAAG,kBAAU,CAAC;QAC3B,IAAI,sCACF,eAAe,EAAE,oBAAM,CAAC,uBAAuB,EAC/C,SAAS,EAAE,oBAAM,CAAC,QAAQ,IACvB,kBAAU,CAAC,YAAY,CAAC,oBAAM,CAAC,kBAAkB,CAAC,GAClD,kBAAU,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,oBAAM,CAAC,sBAAsB,CAAC,CACpE;QAED,QAAQ,EAAE;YACR,eAAe,EAAE,oBAAM,CAAC,4BAA4B;YACpD,KAAK,EAAE,oBAAM,CAAC,oCAAoC;SACnD;QAED,KAAK,EAAE;YACL,eAAe,EAAE,oBAAM,CAAC,oBAAoB;YAC5C,KAAK,EAAE,oBAAM,CAAC,6BAA6B;SAC5C;QAED,YAAY,uBACP,kBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAC9B;QAED,aAAa,uBACR,kBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAC9B;QAED,YAAY,uBACP,kBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAC9B;QAED,UAAU,EAAE,2CAAuB,CAAC,oBAAY,CAAC,KAAK,CAAC;QACvD,gBAAgB,EAAE,2CAAuB,CAAC,oBAAY,CAAC,MAAM,CAAC;QAC9D,KAAK,EAAE,qCAAiB,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;KACrD,CAAC,CAAC;IAEH;;OAEG;IACI,IAAM,gCAAgC,GAAG,UAAC,KAA0B;QACzE,IAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,SAAS,GAAG,oBAAY,CACjC,gCAAwB,CAAC,IAAI,EAC7B,MAAM,CAAC,IAAI,EACX,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,YAAY,EAC7C,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,EAC/C,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,YAAY,EAC7C,KAAK,CAAC,UAAU,KAAK,UAAU,IAAI,MAAM,CAAC,QAAQ,EAClD,KAAK,CAAC,UAAU,KAAK,OAAO,IAAI,MAAM,CAAC,KAAK,EAC5C,KAAK,CAAC,IAAI,CAAC,SAAS,CACrB,CAAC;QAEF,KAAK,CAAC,cAAc,GAAG,oBAAY,CACjC,MAAM,CAAC,KAAK,EACZ,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,CACrE,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAnBW,QAAA,gCAAgC,oCAmB3C","sourcesContent":["import { shorthands, makeStyles, mergeClasses } from '@griffel/react';\nimport { createArrowHeightStyles, createArrowStyles } from '@fluentui/react-positioning';\nimport { tokens } from '@fluentui/react-theme';\nimport type { PopoverSize } from '../Popover/Popover.types';\nimport type { PopoverSurfaceSlots, PopoverSurfaceState } from './PopoverSurface.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\n\nexport const popoverSurfaceClassNames: SlotClassNames<PopoverSurfaceSlots> = {\n root: 'fui-PopoverSurface',\n};\n\nexport const arrowHeights: Record<PopoverSize, number> = {\n small: 6,\n medium: 8,\n large: 8,\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n backgroundColor: tokens.colorNeutralBackground1,\n boxShadow: tokens.shadow16,\n ...shorthands.borderRadius(tokens.borderRadiusMedium),\n ...shorthands.border('1px', 'solid', tokens.colorTransparentStroke),\n },\n\n inverted: {\n backgroundColor: tokens.colorNeutralBackgroundStatic,\n color: tokens.colorNeutralForegroundStaticInverted,\n },\n\n brand: {\n backgroundColor: tokens.colorBrandBackground,\n color: tokens.colorNeutralForegroundOnBrand,\n },\n\n smallPadding: {\n ...shorthands.padding('12px'),\n },\n\n mediumPadding: {\n ...shorthands.padding('16px'),\n },\n\n largePadding: {\n ...shorthands.padding('20px'),\n },\n\n smallArrow: createArrowHeightStyles(arrowHeights.small),\n mediumLargeArrow: createArrowHeightStyles(arrowHeights.medium),\n arrow: createArrowStyles({ arrowHeight: undefined }),\n});\n\n/**\n * Apply styling to the PopoverSurface slots based on the state\n */\nexport const usePopoverSurfaceStyles_unstable = (state: PopoverSurfaceState): PopoverSurfaceState => {\n const styles = useStyles();\n state.root.className = mergeClasses(\n popoverSurfaceClassNames.root,\n styles.root,\n state.size === 'small' && styles.smallPadding,\n state.size === 'medium' && styles.mediumPadding,\n state.size === 'large' && styles.largePadding,\n state.appearance === 'inverted' && styles.inverted,\n state.appearance === 'brand' && styles.brand,\n state.root.className,\n );\n\n state.arrowClassName = mergeClasses(\n styles.arrow,\n state.size === 'small' ? styles.smallArrow : styles.mediumLargeArrow,\n );\n\n return state;\n};\n"]}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
define(["require", "exports", "./usePopoverTrigger", "./renderPopoverTrigger"], function (require, exports, usePopoverTrigger_1, renderPopoverTrigger_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.PopoverTrigger = void 0;
|
5
|
+
/**
|
6
|
+
* Wraps a trigger element as an only child and adds the necessary event handling to open a popover.
|
7
|
+
*/
|
8
|
+
var PopoverTrigger = function (props) {
|
9
|
+
var state = usePopoverTrigger_1.usePopoverTrigger_unstable(props);
|
10
|
+
return renderPopoverTrigger_1.renderPopoverTrigger_unstable(state);
|
11
|
+
};
|
12
|
+
exports.PopoverTrigger = PopoverTrigger;
|
13
|
+
exports.PopoverTrigger.displayName = 'PopoverTrigger';
|
14
|
+
// type casting here is required to ensure internal type FluentTriggerComponent is not leaked
|
15
|
+
exports.PopoverTrigger.isFluentTriggerComponent = true;
|
16
|
+
});
|
17
|
+
//# sourceMappingURL=PopoverTrigger.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PopoverTrigger.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.tsx"],"names":[],"mappings":";;;;IAMA;;OAEG;IACI,IAAM,cAAc,GAAkC,UAAA,KAAK;QAChE,IAAM,KAAK,GAAG,8CAA0B,CAAC,KAAK,CAAC,CAAC;QAEhD,OAAO,oDAA6B,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC,CAAC;IAJW,QAAA,cAAc,kBAIzB;IAEF,sBAAc,CAAC,WAAW,GAAG,gBAAgB,CAAC;IAC9C,6FAA6F;IAC5F,sBAAyC,CAAC,wBAAwB,GAAG,IAAI,CAAC","sourcesContent":["import * as React from 'react';\nimport { usePopoverTrigger_unstable } from './usePopoverTrigger';\nimport { renderPopoverTrigger_unstable } from './renderPopoverTrigger';\nimport type { FluentTriggerComponent } from '@fluentui/react-utilities';\nimport type { PopoverTriggerProps } from './PopoverTrigger.types';\n\n/**\n * Wraps a trigger element as an only child and adds the necessary event handling to open a popover.\n */\nexport const PopoverTrigger: React.FC<PopoverTriggerProps> = props => {\n const state = usePopoverTrigger_unstable(props);\n\n return renderPopoverTrigger_unstable(state);\n};\n\nPopoverTrigger.displayName = 'PopoverTrigger';\n// type casting here is required to ensure internal type FluentTriggerComponent is not leaked\n(PopoverTrigger as FluentTriggerComponent).isFluentTriggerComponent = true;\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PopoverTrigger.types.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ARIAButtonResultProps, ARIAButtonType } from '@fluentui/react-aria';\nimport type { TriggerProps } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\n/**\n * PopoverTrigger Props\n */\nexport type PopoverTriggerProps = TriggerProps<PopoverTriggerChildProps> & {\n /**\n * Disables internal trigger mechanism that ensures a child provided will be a compliant ARIA button.\n * @default false\n */\n disableButtonEnhancement?: boolean;\n};\n\n/**\n * PopoverTrigger State\n */\nexport type PopoverTriggerState = {\n children: React.ReactElement | null;\n};\n\n/**\n * Props that are passed to the child of the DialogTrigger when cloned to ensure correct behaviour for the Dialog\n */\nexport type PopoverTriggerChildProps<Type extends ARIAButtonType = ARIAButtonType, Props = {}> = ARIAButtonResultProps<\n Type,\n Props & {\n 'aria-expanded'?: 'true' | 'false';\n ref: React.Ref<unknown>;\n onMouseEnter: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;\n onMouseLeave: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;\n onContextMenu: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;\n }\n>;\n"]}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
define(["require", "exports", "tslib", "./PopoverTrigger", "./PopoverTrigger.types", "./renderPopoverTrigger", "./usePopoverTrigger"], function (require, exports, tslib_1, PopoverTrigger_1, PopoverTrigger_types_1, renderPopoverTrigger_1, usePopoverTrigger_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
tslib_1.__exportStar(PopoverTrigger_1, exports);
|
5
|
+
tslib_1.__exportStar(PopoverTrigger_types_1, exports);
|
6
|
+
tslib_1.__exportStar(renderPopoverTrigger_1, exports);
|
7
|
+
tslib_1.__exportStar(usePopoverTrigger_1, exports);
|
8
|
+
});
|
9
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverTrigger/index.ts"],"names":[],"mappings":";;;IAAA,gDAAiC;IACjC,sDAAuC;IACvC,sDAAuC;IACvC,mDAAoC","sourcesContent":["export * from './PopoverTrigger';\nexport * from './PopoverTrigger.types';\nexport * from './renderPopoverTrigger';\nexport * from './usePopoverTrigger';\n"]}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.renderPopoverTrigger_unstable = void 0;
|
5
|
+
/**
|
6
|
+
* Render the final JSX of PopoverTrigger
|
7
|
+
*/
|
8
|
+
var renderPopoverTrigger_unstable = function (state) {
|
9
|
+
return state.children;
|
10
|
+
};
|
11
|
+
exports.renderPopoverTrigger_unstable = renderPopoverTrigger_unstable;
|
12
|
+
});
|
13
|
+
//# sourceMappingURL=renderPopoverTrigger.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"renderPopoverTrigger.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverTrigger/renderPopoverTrigger.tsx"],"names":[],"mappings":";;;;IAEA;;OAEG;IACI,IAAM,6BAA6B,GAAG,UAAC,KAA0B;QACtE,OAAO,KAAK,CAAC,QAAQ,CAAC;IACxB,CAAC,CAAC;IAFW,QAAA,6BAA6B,iCAExC","sourcesContent":["import type { PopoverTriggerState } from './PopoverTrigger.types';\n\n/**\n * Render the final JSX of PopoverTrigger\n */\nexport const renderPopoverTrigger_unstable = (state: PopoverTriggerState) => {\n return state.children;\n};\n"]}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
define(["require", "exports", "tslib", "@fluentui/react-utilities", "@fluentui/react-tabster", "../../popoverContext", "@fluentui/react-aria", "@fluentui/keyboard-keys"], function (require, exports, tslib_1, react_utilities_1, react_tabster_1, popoverContext_1, react_aria_1, keyboard_keys_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.usePopoverTrigger_unstable = void 0;
|
5
|
+
/**
|
6
|
+
* Create the state required to render PopoverTrigger.
|
7
|
+
*
|
8
|
+
* The returned state can be modified with hooks such as usePopoverTriggerStyles,
|
9
|
+
* before being passed to renderPopoverTrigger_unstable.
|
10
|
+
*
|
11
|
+
* @param props - props from this instance of PopoverTrigger
|
12
|
+
*/
|
13
|
+
var usePopoverTrigger_unstable = function (props) {
|
14
|
+
var children = props.children, _a = props.disableButtonEnhancement, disableButtonEnhancement = _a === void 0 ? false : _a;
|
15
|
+
var child = react_utilities_1.getTriggerChild(children);
|
16
|
+
var open = popoverContext_1.usePopoverContext_unstable(function (context) { return context.open; });
|
17
|
+
var setOpen = popoverContext_1.usePopoverContext_unstable(function (context) { return context.setOpen; });
|
18
|
+
var toggleOpen = popoverContext_1.usePopoverContext_unstable(function (context) { return context.toggleOpen; });
|
19
|
+
var triggerRef = popoverContext_1.usePopoverContext_unstable(function (context) { return context.triggerRef; });
|
20
|
+
var openOnHover = popoverContext_1.usePopoverContext_unstable(function (context) { return context.openOnHover; });
|
21
|
+
var openOnContext = popoverContext_1.usePopoverContext_unstable(function (context) { return context.openOnContext; });
|
22
|
+
var triggerAttributes = react_tabster_1.useModalAttributes().triggerAttributes;
|
23
|
+
var onContextMenu = function (e) {
|
24
|
+
if (openOnContext) {
|
25
|
+
e.preventDefault();
|
26
|
+
setOpen(e, true);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
var onClick = function (e) {
|
30
|
+
if (!openOnContext) {
|
31
|
+
toggleOpen(e);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
var onKeyDown = function (e) {
|
35
|
+
if (e.key === keyboard_keys_1.Escape && open) {
|
36
|
+
setOpen(e, false);
|
37
|
+
// stop propagation to avoid conflicting with other elements that listen for `Escape`
|
38
|
+
// e,g: Dialog, Menu
|
39
|
+
e.stopPropagation();
|
40
|
+
}
|
41
|
+
};
|
42
|
+
var onMouseEnter = function (e) {
|
43
|
+
if (openOnHover) {
|
44
|
+
setOpen(e, true);
|
45
|
+
}
|
46
|
+
};
|
47
|
+
var onMouseLeave = function (e) {
|
48
|
+
if (openOnHover) {
|
49
|
+
setOpen(e, false);
|
50
|
+
}
|
51
|
+
};
|
52
|
+
var contextMenuProps = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, triggerAttributes), { 'aria-expanded': "" + open }), child === null || child === void 0 ? void 0 : child.props), { onMouseEnter: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(child === null || child === void 0 ? void 0 : child.props.onMouseEnter, onMouseEnter)), onMouseLeave: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(child === null || child === void 0 ? void 0 : child.props.onMouseLeave, onMouseLeave)), onContextMenu: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(child === null || child === void 0 ? void 0 : child.props.onContextMenu, onContextMenu)), ref: react_utilities_1.useMergedRefs(triggerRef, child === null || child === void 0 ? void 0 : child.ref) });
|
53
|
+
var triggerChildProps = tslib_1.__assign(tslib_1.__assign({}, contextMenuProps), { onClick: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(child === null || child === void 0 ? void 0 : child.props.onClick, onClick)), onKeyDown: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(child === null || child === void 0 ? void 0 : child.props.onKeyDown, onKeyDown)) });
|
54
|
+
var ariaButtonTriggerChildProps = react_aria_1.useARIAButtonProps((child === null || child === void 0 ? void 0 : child.type) === 'button' || (child === null || child === void 0 ? void 0 : child.type) === 'a' ? child.type : 'div', triggerChildProps);
|
55
|
+
return {
|
56
|
+
children: react_utilities_1.applyTriggerPropsToChildren(props.children, react_aria_1.useARIAButtonProps((child === null || child === void 0 ? void 0 : child.type) === 'button' || (child === null || child === void 0 ? void 0 : child.type) === 'a' ? child.type : 'div', openOnContext ? contextMenuProps : disableButtonEnhancement ? triggerChildProps : ariaButtonTriggerChildProps)),
|
57
|
+
};
|
58
|
+
};
|
59
|
+
exports.usePopoverTrigger_unstable = usePopoverTrigger_unstable;
|
60
|
+
});
|
61
|
+
//# sourceMappingURL=usePopoverTrigger.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"usePopoverTrigger.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-popover/src/components/PopoverTrigger/usePopoverTrigger.ts"],"names":[],"mappings":";;;;IAcA;;;;;;;OAOG;IACI,IAAM,0BAA0B,GAAG,UAAC,KAA0B;QAC3D,IAAA,QAAQ,GAAuC,KAAK,SAA5C,EAAE,KAAqC,KAAK,yBAAV,EAAhC,wBAAwB,mBAAG,KAAK,KAAA,CAAW;QAC7D,IAAM,KAAK,GAAG,iCAAe,CAAC,QAAQ,CAAC,CAAC;QAExC,IAAM,IAAI,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,IAAI,EAAZ,CAAY,CAAC,CAAC;QACjE,IAAM,OAAO,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,OAAO,EAAf,CAAe,CAAC,CAAC;QACvE,IAAM,UAAU,GAAG,2CAA0B,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,UAAU,EAAlB,CAAkB,CAAC,CAAC;QAC7E,IAAM,UA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AK,QAAQ,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EACpE,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,2BAA2B,CAC9G,CACF;SACF,CAAC;IACJ,CAAC,CAAC;IA5EW,QAAA,0BAA0B,8BA4ErC","sourcesContent":["import * as React from 'react';\nimport {\n applyTriggerPropsToChildren,\n getTriggerChild,\n mergeCallbacks,\n useMergedRefs,\n useEventCallback,\n} from '@fluentui/react-utilities';\nimport { useModalAttributes } from '@fluentui/react-tabster';\nimport { usePopoverContext_unstable } from '../../popoverContext';\nimport type { PopoverTriggerProps, PopoverTriggerState } from './PopoverTrigger.types';\nimport { useARIAButtonProps } from '@fluentui/react-aria';\nimport { Escape } from '@fluentui/keyboard-keys';\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, disableButtonEnhancement = false } = props;\n const child = getTriggerChild(children);\n\n const open = usePopoverContext_unstable(context => context.open);\n const setOpen = usePopoverContext_unstable(context => context.setOpen);\n const toggleOpen = usePopoverContext_unstable(context => context.toggleOpen);\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 { 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 toggleOpen(e);\n }\n };\n\n const onKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {\n if (e.key === Escape && open) {\n setOpen(e, false);\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Menu\n e.stopPropagation();\n }\n };\n\n const onMouseEnter = (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 const contextMenuProps = {\n ...triggerAttributes,\n 'aria-expanded': `${open}`,\n ...child?.props,\n onMouseEnter: useEventCallback(mergeCallbacks(child?.props.onMouseEnter, onMouseEnter)),\n onMouseLeave: useEventCallback(mergeCallbacks(child?.props.onMouseLeave, onMouseLeave)),\n onContextMenu: useEventCallback(mergeCallbacks(child?.props.onContextMenu, onContextMenu)),\n ref: useMergedRefs(triggerRef, child?.ref),\n } as const;\n\n const triggerChildProps = {\n ...contextMenuProps,\n onClick: useEventCallback(mergeCallbacks(child?.props.onClick, onClick)),\n onKeyDown: useEventCallback(mergeCallbacks(child?.props.onKeyDown, onKeyDown)),\n };\n\n const ariaButtonTriggerChildProps = useARIAButtonProps(\n child?.type === 'button' || child?.type === 'a' ? child.type : 'div',\n triggerChildProps,\n );\n\n return {\n children: applyTriggerPropsToChildren(\n props.children,\n useARIAButtonProps(\n child?.type === 'button' || child?.type === 'a' ? child.type : 'div',\n openOnContext ? contextMenuProps : disableButtonEnhancement ? triggerChildProps : ariaButtonTriggerChildProps,\n ),\n ),\n };\n};\n"]}
|
package/lib-amd/index.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
define(["require", "exports", "./Popover", "./PopoverSurface", "./popoverContext", "./PopoverTrigger"], function (require, exports, Popover_1, PopoverSurface_1, popoverContext_1, PopoverTrigger_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.usePopoverTrigger_unstable = exports.renderPopoverTrigger_unstable = exports.PopoverTrigger = exports.usePopoverContext_unstable = exports.PopoverProvider = exports.usePopoverSurface_unstable = exports.usePopoverSurfaceStyles_unstable = exports.renderPopoverSurface_unstable = exports.popoverSurfaceClassNames = exports.arrowHeights = exports.PopoverSurface = exports.usePopover_unstable = exports.renderPopover_unstable = exports.Popover = void 0;
|
5
|
+
Object.defineProperty(exports, "Popover", { enumerable: true, get: function () { return Popover_1.Popover; } });
|
6
|
+
Object.defineProperty(exports, "renderPopover_unstable", { enumerable: true, get: function () { return Popover_1.renderPopover_unstable; } });
|
7
|
+
Object.defineProperty(exports, "usePopover_unstable", { enumerable: true, get: function () { return Popover_1.usePopover_unstable; } });
|
8
|
+
Object.defineProperty(exports, "PopoverSurface", { enumerable: true, get: function () { return PopoverSurface_1.PopoverSurface; } });
|
9
|
+
Object.defineProperty(exports, "arrowHeights", { enumerable: true, get: function () { return PopoverSurface_1.arrowHeights; } });
|
10
|
+
Object.defineProperty(exports, "popoverSurfaceClassNames", { enumerable: true, get: function () { return PopoverSurface_1.popoverSurfaceClassNames; } });
|
11
|
+
Object.defineProperty(exports, "renderPopoverSurface_unstable", { enumerable: true, get: function () { return PopoverSurface_1.renderPopoverSurface_unstable; } });
|
12
|
+
Object.defineProperty(exports, "usePopoverSurfaceStyles_unstable", { enumerable: true, get: function () { return PopoverSurface_1.usePopoverSurfaceStyles_unstable; } });
|
13
|
+
Object.defineProperty(exports, "usePopoverSurface_unstable", { enumerable: true, get: function () { return PopoverSurface_1.usePopoverSurface_unstable; } });
|
14
|
+
Object.defineProperty(exports, "PopoverProvider", { enumerable: true, get: function () { return popoverContext_1.PopoverProvider; } });
|
15
|
+
Object.defineProperty(exports, "usePopoverContext_unstable", { enumerable: true, get: function () { return popoverContext_1.usePopoverContext_unstable; } });
|
16
|
+
Object.defineProperty(exports, "PopoverTrigger", { enumerable: true, get: function () { return PopoverTrigger_1.PopoverTrigger; } });
|
17
|
+
Object.defineProperty(exports, "renderPopoverTrigger_unstable", { enumerable: true, get: function () { return PopoverTrigger_1.renderPopoverTrigger_unstable; } });
|
18
|
+
Object.defineProperty(exports, "usePopoverTrigger_unstable", { enumerable: true, get: function () { return PopoverTrigger_1.usePopoverTrigger_unstable; } });
|
19
|
+
});
|
20
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-popover/src/index.ts"],"names":[],"mappings":";;;;IAAS,kGAAA,OAAO,OAAA;IAAE,iHAAA,sBAAsB,OAAA;IAAE,8GAAA,mBAAmB,OAAA;IAG3D,gHAAA,cAAc,OAAA;IACd,8GAAA,YAAY,OAAA;IACZ,0HAAA,wBAAwB,OAAA;IACxB,+HAAA,6BAA6B,OAAA;IAC7B,kIAAA,gCAAgC,OAAA;IAChC,4HAAA,0BAA0B,OAAA;IAGnB,iHAAA,eAAe,OAAA;IAAE,4HAAA,0BAA0B,OAAA;IAE3C,gHAAA,cAAc,OAAA;IAAE,+HAAA,6BAA6B,OAAA;IAAE,4HAAA,0BAA0B,OAAA","sourcesContent":["export { Popover, renderPopover_unstable, usePopover_unstable } from './Popover';\nexport type { OnOpenChangeData, OpenPopoverEvents, PopoverProps, PopoverSize, PopoverState } from './Popover';\nexport {\n PopoverSurface,\n arrowHeights,\n popoverSurfaceClassNames,\n renderPopoverSurface_unstable,\n usePopoverSurfaceStyles_unstable,\n usePopoverSurface_unstable,\n} from './PopoverSurface';\nexport type { PopoverSurfaceProps, PopoverSurfaceSlots, PopoverSurfaceState } from './PopoverSurface';\nexport { PopoverProvider, usePopoverContext_unstable } from './popoverContext';\nexport type { PopoverContextValue } from './popoverContext';\nexport { PopoverTrigger, renderPopoverTrigger_unstable, usePopoverTrigger_unstable } from './PopoverTrigger';\nexport type { PopoverTriggerChildProps, PopoverTriggerProps, PopoverTriggerState } from './PopoverTrigger';\n"]}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
define(["require", "exports", "@fluentui/react-context-selector"], function (require, exports, react_context_selector_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.usePopoverContext_unstable = exports.PopoverProvider = exports.PopoverContext = void 0;
|
5
|
+
exports.PopoverContext = react_context_selector_1.createContext(undefined);
|
6
|
+
var popoverContextDefaultValue = {
|
7
|
+
open: false,
|
8
|
+
setOpen: function () { return null; },
|
9
|
+
toggleOpen: function () { return null; },
|
10
|
+
triggerRef: { current: null },
|
11
|
+
contentRef: { current: null },
|
12
|
+
arrowRef: { current: null },
|
13
|
+
openOnContext: false,
|
14
|
+
openOnHover: false,
|
15
|
+
size: 'medium',
|
16
|
+
trapFocus: false,
|
17
|
+
inline: false,
|
18
|
+
};
|
19
|
+
exports.PopoverProvider = exports.PopoverContext.Provider;
|
20
|
+
var usePopoverContext_unstable = function (selector) {
|
21
|
+
return react_context_selector_1.useContextSelector(exports.PopoverContext, function (ctx) {
|
22
|
+
if (ctx === void 0) { ctx = popoverContextDefaultValue; }
|
23
|
+
return selector(ctx);
|
24
|
+
});
|
25
|
+
};
|
26
|
+
exports.usePopoverContext_unstable = usePopoverContext_unstable;
|
27
|
+
});
|
28
|
+
//# sourceMappingURL=popoverContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"popoverContext.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-popover/src/popoverContext.ts"],"names":[],"mappings":";;;;IAIa,QAAA,cAAc,GAAiC,sCAAa,CACvE,SAAS,CACsB,CAAC;IAClC,IAAM,0BAA0B,GAAwB;QACtD,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI;QACnB,UAAU,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI;QACtB,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;QAC7B,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;QAC7B,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;QAC3B,aAAa,EAAE,KAAK;QACpB,WAAW,EAAE,KAAK;QAClB,IAAI,EAAE,QAAiB;QACvB,SAAS,EAAE,KAAK;QAChB,MAAM,EAAE,KAAK;KACd,CAAC;IAEW,QAAA,eAAe,GAAG,sBAAc,CAAC,QAAQ,CAAC;IAwBhD,IAAM,0BAA0B,GAAG,UAAI,QAAiD;QAC7F,OAAA,2CAAkB,CAAC,sBAAc,EAAE,UAAC,GAAgC;YAAhC,oBAAA,EAAA,gCAAgC;YAAK,OAAA,QAAQ,CAAC,GAAG,CAAC;QAAb,CAAa,CAAC;IAAvF,CAAuF,CAAC;IAD7E,QAAA,0BAA0B,8BACmD","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 | undefined>(\n undefined,\n) as Context<PopoverContextValue>;\nconst popoverContextDefaultValue: PopoverContextValue = {\n open: false,\n setOpen: () => null,\n toggleOpen: () => null,\n triggerRef: { current: null },\n contentRef: { current: null },\n arrowRef: { current: null },\n openOnContext: false,\n openOnHover: false,\n size: 'medium' as const,\n trapFocus: false,\n inline: false,\n};\n\nexport const PopoverProvider = PopoverContext.Provider;\n\n/**\n * Context shared between Popover and its children components\n */\nexport type PopoverContextValue = Pick<\n PopoverState,\n | 'open'\n | 'toggleOpen'\n | 'setOpen'\n | 'triggerRef'\n | 'contentRef'\n | 'openOnHover'\n | 'openOnContext'\n | 'mountNode'\n | 'withArrow'\n | 'arrowRef'\n | 'size'\n | 'appearance'\n | 'trapFocus'\n | 'legacyTrapFocus'\n | 'inline'\n>;\n\nexport const usePopoverContext_unstable = <T>(selector: ContextSelector<PopoverContextValue, T>): T =>\n useContextSelector(PopoverContext, (ctx = popoverContextDefaultValue) => selector(ctx));\n"]}
|
@@ -169,16 +169,9 @@ function useOpenState(state) {
|
|
169
169
|
setContextTarget(undefined);
|
170
170
|
}
|
171
171
|
|
172
|
-
setOpenState(
|
173
|
-
|
174
|
-
|
175
|
-
if (prevOpen !== shouldOpen) {
|
176
|
-
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(e, {
|
177
|
-
open: shouldOpen
|
178
|
-
});
|
179
|
-
}
|
180
|
-
|
181
|
-
return shouldOpen;
|
172
|
+
setOpenState(shouldOpen);
|
173
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(e, {
|
174
|
+
open: shouldOpen
|
182
175
|
});
|
183
176
|
}, [setOpenState, onOpenChange, setContextTarget]);
|
184
177
|
return [open, setOpen];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-popover/src/components/Popover/usePopover.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAMA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,mBAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;;AAMA,MAAA,cAAA,gBAAA,OAAA,CAAA,wBAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AACA,MAAA,OAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AAEA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AAEA;;;;;;;AAOG;;;AACI,MAAM,mBAAmB,GAAI,KAAD,IAAsC;;;EACvE,MAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,mBAAA,CAAA,yBAAA,EAA1C;EACA,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,QADa;IAEnB,aAFmB;IAGnB,gBAHmB;IAInB,GAAG;EAJgB,CAArB;EAOA,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAN,CAAe,OAAf,CAAuB,KAAK,CAA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;IAIzB,MAAM,EAAE,KAAK,CAAC,aAAN,GAAsB,KAAK,CAAC,aAA5B,GAA4C,SAJ3B;IAKzB,GAAG,mBAAA,CAAA,2BAAA,CAA4B,KAAK,CAAC,WAAlC;EALsB,CAA3B,CAFmE,CAUnE;;EACA,IAAI,kBAAkB,CAAC,WAAvB,EAAoC;IAClC,KAAK,CAAC,SAAN,GAAkB,KAAlB;EACD;;EAED,IAAI,KAAK,CAAC,SAAV,EAAqB;IACnB,kBAAkB,CAAC,MAAnB,GAA4B,mBAAA,CAAA,gBAAA,CAAiB,kBAAkB,CAAC,MAApC,EAA4C,OAAA,CAAA,YAAA,CAAa,KAAK,CAAC,IAAnB,CAA5C,CAA5B;EACD;;EAED,MAAM;IAAE,SAAS,EAAE,UAAb;IAAyB,YAAY,EAAE,UAAvC;IAAmD;EAAnD,IAAgE,mBAAA,CAAA,cAAA,CAAe,kBAAf,CAAtE;EAEA,OAAO;IACL,UADK;IAEL,UAFK;IAGL;EAHK,CAAP;AAKD","sourcesContent":["import * as React from 'react';\nimport {\n useControllableState,\n useEventCallback,\n useOnClickOutside,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n usePositioning,\n resolvePositioningShorthand,\n mergeArrowOffset,\n usePositioningMouseTarget,\n} from '@fluentui/react-positioning';\nimport { elementContains } from '@fluentui/react-portal';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { arrowHeights } from '../PopoverSurface/index';\nimport type { OpenPopoverEvents, PopoverProps, PopoverState } from './Popover.types';\nimport { popoverSurfaceBorderRadius } from './constants';\n\n/**\n * Create the state required to render Popover.\n *\n * The returned state can be modified with hooks such as usePopoverStyles,\n * before being passed to renderPopover_unstable.\n *\n * @param props - props from this instance of Popover\n */\nexport const usePopover_unstable = (props: PopoverProps): PopoverState => {\n const [contextTarget, setContextTarget] = usePositioningMouseTarget();\n const initialState = {\n size: 'medium',\n contextTarget,\n setContextTarget,\n ...props,\n } as const;\n\n const children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at most two children');\n }\n }\n\n let popoverTrigger: React.ReactElement | undefined = undefined;\n let popoverSurface: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n popoverTrigger = children[0];\n popoverSurface = children[1];\n } else if (children.length === 1) {\n popoverSurface = children[0];\n }\n\n const [open, setOpenState] = useOpenState(initialState);\n\n const setOpenTimeoutRef = React.useRef(0);\n\n const setOpen = useEventCallback((e: OpenPopoverEvents, shouldOpen: boolean) => {\n clearTimeout(setOpenTimeoutRef.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave') {\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeoutRef.current = setTimeout(() => {\n setOpenState(e, shouldOpen);\n }, props.mouseLeaveDelay ?? 500);\n } else {\n setOpenState(e, shouldOpen);\n }\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeoutRef.current);\n };\n }, []);\n\n const toggleOpen = React.useCallback<PopoverState['toggleOpen']>(\n e => {\n setOpen(e, !open);\n },\n [setOpen, open],\n );\n\n const positioningRefs = usePopoverRefs(initialState);\n\n const { targetDocument } = useFluent();\n useOnClickOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [positioningRefs.triggerRef, positioningRefs.contentRef],\n disabled: !open,\n });\n\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = initialState.openOnContext || initialState.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [positioningRefs.triggerRef, positioningRefs.contentRef],\n disabled: !open || !closeOnScroll,\n });\n\n const { findFirstFocusable } = useFocusFinders();\n\n React.useEffect(() => {\n if (open && positioningRefs.contentRef.current) {\n const containerTabIndex = positioningRefs.contentRef.current.getAttribute('tabIndex') ?? undefined;\n const firstFocusable = isNaN(containerTabIndex)\n ? findFirstFocusable(positioningRefs.contentRef.current)\n : positioningRefs.contentRef.current;\n firstFocusable?.focus();\n }\n }, [findFirstFocusable, open, positioningRefs.contentRef]);\n\n return {\n ...initialState,\n ...positioningRefs,\n popoverTrigger,\n popoverSurface,\n open,\n setOpen,\n toggleOpen,\n setContextTarget,\n contextTarget,\n inline: props.inline ?? false,\n };\n};\n\n/**\n * Creates and manages the Popover open state\n */\nfunction useOpenState(\n state: Pick<PopoverState, 'setContextTarget' | 'onOpenChange'> & Pick<PopoverProps, 'open' | 'defaultOpen'>,\n) {\n const onOpenChange: PopoverState['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const [open, setOpenState] = useControllableState({\n state: state.open,\n defaultState: state.defaultOpen,\n initialState: false,\n });\n state.open = open !== undefined ? open : state.open;\n const setContextTarget = state.setContextTarget;\n\n const setOpen = React.useCallback(\n (e: OpenPopoverEvents, shouldOpen: boolean) => {\n if (shouldOpen && e.type === 'contextmenu') {\n setContextTarget(e as React.MouseEvent);\n }\n\n if (!shouldOpen) {\n setContextTarget(undefined);\n }\n\n setOpenState(prevOpen => {\n // More than one event (mouse, focus, keyboard) can request the Popover to close\n // We assume the first event is the correct one\n if (prevOpen !== shouldOpen) {\n onOpenChange?.(e, { open: shouldOpen });\n }\n\n return shouldOpen;\n });\n },\n [setOpenState, onOpenChange, setContextTarget],\n );\n\n return [open, setOpen] as const;\n}\n\n/**\n * Creates and sets the necessary trigger, target and content refs used by Popover\n */\nfunction usePopoverRefs(\n state: Pick<PopoverState, 'size' | 'contextTarget'> &\n Pick<PopoverProps, 'positioning' | 'openOnContext' | 'withArrow'>,\n) {\n const positioningOptions = {\n position: 'above' as const,\n align: 'center' as const,\n arrowPadding: 2 * popoverSurfaceBorderRadius,\n target: state.openOnContext ? state.contextTarget : undefined,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n // no reason to render arrow when covering the target\n if (positioningOptions.coverTarget) {\n state.withArrow = false;\n }\n\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeights[state.size]);\n }\n\n const { targetRef: triggerRef, containerRef: contentRef, arrowRef } = usePositioning(positioningOptions);\n\n return {\n triggerRef,\n contentRef,\n arrowRef,\n } as const;\n}\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-popover/src/components/Popover/usePopover.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAMA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,mBAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;;AAMA,MAAA,cAAA,gBAAA,OAAA,CAAA,wBAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AACA,MAAA,OAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AAEA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AAEA;;;;;;;AAOG;;;AACI,MAAM,mBAAmB,GAAI,KAAD,IAAsC;;;EACvE,MAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,mBAAA,CAAA,yBAAA,EAA1C;EACA,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,QADa;IAEnB,aAFmB;IAGnB,gBAHmB;IAInB,GAAG;EAJgB,CAArB;EAOA,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAN,CAAe,OAAf,CAAuB,KAAK,CAAC,QAA7B,CAAjB;;EAEA,IAAI,OAAO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AC,WAAlC;EALsB,CAA3B,CAFmE,CAUnE;;EACA,IAAI,kBAAkB,CAAC,WAAvB,EAAoC;IAClC,KAAK,CAAC,SAAN,GAAkB,KAAlB;EACD;;EAED,IAAI,KAAK,CAAC,SAAV,EAAqB;IACnB,kBAAkB,CAAC,MAAnB,GAA4B,mBAAA,CAAA,gBAAA,CAAiB,kBAAkB,CAAC,MAApC,EAA4C,OAAA,CAAA,YAAA,CAAa,KAAK,CAAC,IAAnB,CAA5C,CAA5B;EACD;;EAED,MAAM;IAAE,SAAS,EAAE,UAAb;IAAyB,YAAY,EAAE,UAAvC;IAAmD;EAAnD,IAAgE,mBAAA,CAAA,cAAA,CAAe,kBAAf,CAAtE;EAEA,OAAO;IACL,UADK;IAEL,UAFK;IAGL;EAHK,CAAP;AAKD","sourcesContent":["import * as React from 'react';\nimport {\n useControllableState,\n useEventCallback,\n useOnClickOutside,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n usePositioning,\n resolvePositioningShorthand,\n mergeArrowOffset,\n usePositioningMouseTarget,\n} from '@fluentui/react-positioning';\nimport { elementContains } from '@fluentui/react-portal';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { arrowHeights } from '../PopoverSurface/index';\nimport type { OpenPopoverEvents, PopoverProps, PopoverState } from './Popover.types';\nimport { popoverSurfaceBorderRadius } from './constants';\n\n/**\n * Create the state required to render Popover.\n *\n * The returned state can be modified with hooks such as usePopoverStyles,\n * before being passed to renderPopover_unstable.\n *\n * @param props - props from this instance of Popover\n */\nexport const usePopover_unstable = (props: PopoverProps): PopoverState => {\n const [contextTarget, setContextTarget] = usePositioningMouseTarget();\n const initialState = {\n size: 'medium',\n contextTarget,\n setContextTarget,\n ...props,\n } as const;\n\n const children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Popover must contain at most two children');\n }\n }\n\n let popoverTrigger: React.ReactElement | undefined = undefined;\n let popoverSurface: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n popoverTrigger = children[0];\n popoverSurface = children[1];\n } else if (children.length === 1) {\n popoverSurface = children[0];\n }\n\n const [open, setOpenState] = useOpenState(initialState);\n\n const setOpenTimeoutRef = React.useRef(0);\n\n const setOpen = useEventCallback((e: OpenPopoverEvents, shouldOpen: boolean) => {\n clearTimeout(setOpenTimeoutRef.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave') {\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeoutRef.current = setTimeout(() => {\n setOpenState(e, shouldOpen);\n }, props.mouseLeaveDelay ?? 500);\n } else {\n setOpenState(e, shouldOpen);\n }\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeoutRef.current);\n };\n }, []);\n\n const toggleOpen = React.useCallback<PopoverState['toggleOpen']>(\n e => {\n setOpen(e, !open);\n },\n [setOpen, open],\n );\n\n const positioningRefs = usePopoverRefs(initialState);\n\n const { targetDocument } = useFluent();\n useOnClickOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [positioningRefs.triggerRef, positioningRefs.contentRef],\n disabled: !open,\n });\n\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = initialState.openOnContext || initialState.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [positioningRefs.triggerRef, positioningRefs.contentRef],\n disabled: !open || !closeOnScroll,\n });\n\n const { findFirstFocusable } = useFocusFinders();\n\n React.useEffect(() => {\n if (open && positioningRefs.contentRef.current) {\n const containerTabIndex = positioningRefs.contentRef.current.getAttribute('tabIndex') ?? undefined;\n const firstFocusable = isNaN(containerTabIndex)\n ? findFirstFocusable(positioningRefs.contentRef.current)\n : 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(shouldOpen);\n onOpenChange?.(e, { open: shouldOpen });\n },\n [setOpenState, onOpenChange, setContextTarget],\n );\n\n return [open, setOpen] as const;\n}\n\n/**\n * Creates and sets the necessary trigger, target and content refs used by Popover\n */\nfunction usePopoverRefs(\n state: Pick<PopoverState, 'size' | 'contextTarget'> &\n Pick<PopoverProps, 'positioning' | 'openOnContext' | 'withArrow'>,\n) {\n const positioningOptions = {\n position: 'above' as const,\n align: 'center' as const,\n arrowPadding: 2 * popoverSurfaceBorderRadius,\n target: state.openOnContext ? state.contextTarget : undefined,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n // no reason to render arrow when covering the target\n if (positioningOptions.coverTarget) {\n state.withArrow = false;\n }\n\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeights[state.size]);\n }\n\n const { targetRef: triggerRef, containerRef: contentRef, arrowRef } = usePositioning(positioningOptions);\n\n return {\n triggerRef,\n contentRef,\n arrowRef,\n } as const;\n}\n"],"sourceRoot":"../src/"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-popover",
|
3
|
-
"version": "9.3.
|
3
|
+
"version": "9.3.3",
|
4
4
|
"description": "Popover component for Fluent UI",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -34,14 +34,14 @@
|
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
36
|
"@fluentui/keyboard-keys": "^9.0.1",
|
37
|
-
"@fluentui/react-aria": "^9.3.
|
38
|
-
"@fluentui/react-context-selector": "^9.1.
|
39
|
-
"@fluentui/react-portal": "^9.0.
|
40
|
-
"@fluentui/react-positioning": "^9.3.
|
41
|
-
"@fluentui/react-shared-contexts": "^9.1.
|
42
|
-
"@fluentui/react-tabster": "^9.3.
|
43
|
-
"@fluentui/react-theme": "^9.1.
|
44
|
-
"@fluentui/react-utilities": "^9.2.
|
37
|
+
"@fluentui/react-aria": "^9.3.2",
|
38
|
+
"@fluentui/react-context-selector": "^9.1.2",
|
39
|
+
"@fluentui/react-portal": "^9.0.12",
|
40
|
+
"@fluentui/react-positioning": "^9.3.3",
|
41
|
+
"@fluentui/react-shared-contexts": "^9.1.2",
|
42
|
+
"@fluentui/react-tabster": "^9.3.2",
|
43
|
+
"@fluentui/react-theme": "^9.1.3",
|
44
|
+
"@fluentui/react-utilities": "^9.2.2",
|
45
45
|
"@griffel/react": "^1.4.2",
|
46
46
|
"tslib": "^2.1.0"
|
47
47
|
},
|