@fluentui/react-popover 9.0.0-alpha.40 → 9.0.0-alpha.44
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +67 -1
- package/CHANGELOG.md +39 -2
- package/dist/react-popover.d.ts +35 -46
- package/lib/common/isConformant.js +2 -0
- package/lib/common/isConformant.js.map +1 -1
- package/lib/components/Popover/Popover.types.d.ts +13 -20
- package/lib/components/Popover/Popover.types.js.map +1 -1
- package/lib/components/Popover/usePopover.js +42 -55
- package/lib/components/Popover/usePopover.js.map +1 -1
- package/lib/components/PopoverSurface/PopoverSurface.d.ts +1 -1
- package/lib/components/PopoverSurface/PopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/PopoverSurface.types.d.ts +7 -15
- package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
- package/lib/components/PopoverSurface/renderPopoverSurface.js +4 -3
- package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurface.d.ts +4 -3
- package/lib/components/PopoverSurface/usePopoverSurface.js +24 -15
- package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +1 -1
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib/components/PopoverTrigger/usePopoverTrigger.js +13 -16
- package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib-amd/common/isConformant.js +2 -0
- package/lib-amd/common/isConformant.js.map +1 -1
- package/lib-amd/components/Popover/Popover.types.d.ts +13 -20
- package/lib-amd/components/Popover/Popover.types.js.map +1 -1
- package/lib-amd/components/Popover/usePopover.js +30 -40
- package/lib-amd/components/Popover/usePopover.js.map +1 -1
- package/lib-amd/components/PopoverSurface/PopoverSurface.d.ts +1 -1
- package/lib-amd/components/PopoverSurface/PopoverSurface.js.map +1 -1
- package/lib-amd/components/PopoverSurface/PopoverSurface.types.d.ts +7 -15
- package/lib-amd/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
- package/lib-amd/components/PopoverSurface/renderPopoverSurface.js +3 -3
- package/lib-amd/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib-amd/components/PopoverSurface/usePopoverSurface.d.ts +4 -3
- package/lib-amd/components/PopoverSurface/usePopoverSurface.js +12 -10
- package/lib-amd/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js +1 -1
- package/lib-amd/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js +8 -11
- package/lib-amd/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib-commonjs/common/isConformant.js +2 -0
- package/lib-commonjs/common/isConformant.js.map +1 -1
- package/lib-commonjs/components/Popover/Popover.types.d.ts +13 -20
- package/lib-commonjs/components/Popover/usePopover.js +41 -54
- package/lib-commonjs/components/Popover/usePopover.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.d.ts +1 -1
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.d.ts +7 -15
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +5 -3
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.d.ts +4 -3
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +25 -16
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +13 -16
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/package.json +10 -10
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/Popover/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I,aAAa,CAAC,WAAlB,EAA+B;AAC7B,IAAA,KAAK,CAAC,OAAN,GAAgB,IAAhB;AACD;;AAED,MAAI,CAAC,KAAK,CAAC,OAAX,EAAoB;AAClB,IAAA,aAAa,CAAC,MAAd,GAAuB,gBAAgB,CAAC,aAAa,CAAC,MAAf,EAAuB,YAAY,CAAC,KAAK,CAAC,IAAP,CAAnC,CAAvC;AACD;;AAEK,MAAA,EAAA,GAAgE,SAAS,CAAC,aAAD,CAAzE;AAAA,MAAa,UAAU,GAAA,EAAA,CAAA,SAAvB;AAAA,MAAuC,UAAU,GAAA,EAAA,CAAA,YAAjD;AAAA,MAAmD,QAAQ,GAAA,EAAA,CAAA,QAA3D;;AAEN,SAAO;AACL,IAAA,UAAU,EAAA,UADL;AAEL,IAAA,UAAU,EAAA,UAFL;AAGL,IAAA,QAAQ,EAAA;AAHH,GAAP;AAKD","sourcesContent":["import * as React from 'react';\nimport {\n useControllableState,\n useEventCallback,\n useOnClickOutside,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent } from '@fluentui/react-shared-contexts';\nimport {\n usePopper,\n resolvePositioningShorthand,\n mergeArrowOffset,\n usePopperMouseTarget,\n} from '@fluentui/react-positioning';\nimport { elementContains } from '@fluentui/react-portal';\nimport { arrowHeights } from '../PopoverSurface/index';\nimport type { OpenPopoverEvents, PopoverProps, PopoverState } from './Popover.types';\n\n/**\n * Create the state required to render Popover.\n *\n * The returned state can be modified with hooks such as usePopoverStyles,\n * before being passed to renderPopover.\n *\n * @param props - props from this instance of Popover\n * @param defaultProps - (optional) default prop values provided by the implementing type\n */\nexport const usePopover = (props: PopoverProps, defaultProps?: PopoverProps): PopoverState => {\n const [contextTarget, setContextTarget] = usePopperMouseTarget();\n const initialState = {\n size: 'medium',\n contextTarget,\n setContextTarget,\n ...props,\n } as const;\n\n const [open, setOpen] = useOpenState(initialState);\n const popperRefs = usePopoverRefs(initialState);\n\n const { targetDocument } = useFluent();\n useOnClickOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [popperRefs.triggerRef, popperRefs.contentRef],\n disabled: !open,\n });\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, false),\n refs: [popperRefs.triggerRef, popperRefs.contentRef],\n disabled: !open || !initialState.openOnContext, // only close on scroll for context\n });\n\n return {\n ...initialState,\n ...popperRefs,\n open,\n setOpen,\n setContextTarget,\n contextTarget,\n };\n};\n\n/**\n * Creates and manages the Popover open state\n */\nfunction useOpenState(\n state: Pick<PopoverState, 'setContextTarget' | 'onOpenChange'> & Pick<PopoverProps, 'open' | 'defaultOpen'>,\n) {\n const onOpenChange: PopoverState['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const [open, setOpenState] = useControllableState({\n state: state.open,\n defaultState: state.defaultOpen,\n initialState: false,\n });\n state.open = open !== undefined ? open : state.open;\n const setContextTarget = state.setContextTarget;\n\n const setOpen = React.useCallback(\n (e: OpenPopoverEvents, shouldOpen: boolean) => {\n if (shouldOpen && e.type === 'contextmenu') {\n setContextTarget(e as React.MouseEvent);\n }\n\n if (!shouldOpen) {\n setContextTarget(undefined);\n }\n\n setOpenState(prevOpen => {\n // More than one event (mouse, focus, keyboard) can request the Popover to close\n // We assume the first event is the correct one\n if (prevOpen !== shouldOpen) {\n onOpenChange?.(e, { open: shouldOpen });\n }\n\n return shouldOpen;\n });\n },\n [setOpenState, onOpenChange, setContextTarget],\n );\n\n return [open, setOpen] as const;\n}\n\n/**\n * Creates and sets the necessary trigger, target and content refs used by Popover\n */\nfunction usePopoverRefs(\n state: Pick<PopoverState, 'size' | 'contextTarget'> & Pick<PopoverProps, 'positioning' | 'openOnContext' | 'noArrow'>,\n) {\n const popperOptions = {\n position: 'above' as const,\n align: 'center' as const,\n target: state.openOnContext ? state.contextTarget : undefined,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n // no reason to render arrow when covering the target\n if (popperOptions.coverTarget) {\n state.noArrow = true;\n }\n\n if (!state.noArrow) {\n popperOptions.offset = mergeArrowOffset(popperOptions.offset, arrowHeights[state.size]);\n }\n\n const { targetRef: triggerRef, containerRef: contentRef, arrowRef } = usePopper(popperOptions);\n\n return {\n triggerRef,\n contentRef,\n arrowRef,\n } as const;\n}\n"],"sourceRoot":"../src/"}
|
@@ -3,4 +3,4 @@ import type { PopoverSurfaceProps } from './PopoverSurface.types';
|
|
3
3
|
/**
|
4
4
|
* PopoverSurface component renders react children in a positioned box
|
5
5
|
*/
|
6
|
-
export declare const PopoverSurface: React.ForwardRefExoticComponent<PopoverSurfaceProps & React.RefAttributes<
|
6
|
+
export declare const PopoverSurface: React.ForwardRefExoticComponent<PopoverSurfaceProps & React.RefAttributes<HTMLDivElement>>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,iBAAT,QAAkC,qBAAlC;AACA,SAAS,oBAAT,QAAqC,wBAArC;AACA,SAAS,uBAAT,QAAwC,2BAAxC;AAGA;;AAEG;;AACH,OAAO,IAAM,cAAc,gBAAG,KAAK,CAAC,UAAN,
|
1
|
+
{"version":3,"sources":["components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,iBAAT,QAAkC,qBAAlC;AACA,SAAS,oBAAT,QAAqC,wBAArC;AACA,SAAS,uBAAT,QAAwC,2BAAxC;AAGA;;AAEG;;AACH,OAAO,IAAM,cAAc,gBAAG,KAAK,CAAC,UAAN,CAAsD,UAAC,KAAD,EAAQ,GAAR,EAAW;AAC7F,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAD,EAAQ,GAAR,CAA/B;AAEA,EAAA,uBAAuB,CAAC,KAAD,CAAvB;AACA,SAAO,oBAAoB,CAAC,KAAD,CAA3B;AACD,CAL6B,CAAvB;AAOP,cAAc,CAAC,WAAf,GAA6B,gBAA7B","sourcesContent":["import * as React from 'react';\nimport { usePopoverSurface } from './usePopoverSurface';\nimport { renderPopoverSurface } from './renderPopoverSurface';\nimport { usePopoverSurfaceStyles } from './usePopoverSurfaceStyles';\nimport type { PopoverSurfaceProps } from './PopoverSurface.types';\n\n/**\n * PopoverSurface component renders react children in a positioned box\n */\nexport const PopoverSurface = React.forwardRef<HTMLDivElement, PopoverSurfaceProps>((props, ref) => {\n const state = usePopoverSurface(props, ref);\n\n usePopoverSurfaceStyles(state);\n return renderPopoverSurface(state);\n});\n\nPopoverSurface.displayName = 'PopoverSurface';\n"],"sourceRoot":"../src/"}
|
@@ -1,28 +1,20 @@
|
|
1
|
-
import
|
2
|
-
import type { ComponentPropsCompat, ComponentStateCompat } from '@fluentui/react-utilities';
|
1
|
+
import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities';
|
3
2
|
import type { PopoverContextValue } from '../../popoverContext';
|
4
3
|
/**
|
5
4
|
* PopoverSurface Props
|
6
5
|
*/
|
7
|
-
export interface PopoverSurfaceProps extends
|
6
|
+
export interface PopoverSurfaceProps extends ComponentProps<PopoverSurfaceSlots> {
|
8
7
|
}
|
9
8
|
/**
|
10
|
-
* Names of the
|
9
|
+
* Names of the slots in PopoverSurfaceProps
|
11
10
|
*/
|
12
|
-
export declare type
|
13
|
-
|
14
|
-
|
15
|
-
*/
|
16
|
-
export declare type PopoverSurfaceDefaultedProps = never;
|
11
|
+
export declare type PopoverSurfaceSlots = {
|
12
|
+
root: IntrinsicShorthandProps<'div'>;
|
13
|
+
};
|
17
14
|
/**
|
18
15
|
* PopoverSurface State
|
19
16
|
*/
|
20
|
-
export interface PopoverSurfaceState extends
|
21
|
-
ref: React.Ref<HTMLElement>;
|
22
|
-
/**
|
23
|
-
* Ref to the arrow element
|
24
|
-
*/
|
25
|
-
arrowRef?: React.Ref<HTMLDivElement>;
|
17
|
+
export interface PopoverSurfaceState extends ComponentState<PopoverSurfaceSlots>, Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'brand' | 'inverted' | 'arrowRef'> {
|
26
18
|
/**
|
27
19
|
* CSS class for the arrow element
|
28
20
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PopoverSurface.types.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import
|
1
|
+
{"version":3,"file":"PopoverSurface.types.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities';\nimport type { PopoverContextValue } from '../../popoverContext';\n\n/**\n * PopoverSurface Props\n */\nexport interface PopoverSurfaceProps extends ComponentProps<PopoverSurfaceSlots> {}\n\n/**\n * Names of the slots in PopoverSurfaceProps\n */\nexport type PopoverSurfaceSlots = {\n root: IntrinsicShorthandProps<'div'>;\n};\n\n/**\n * PopoverSurface State\n */\nexport interface PopoverSurfaceState\n extends ComponentState<PopoverSurfaceSlots>,\n Pick<PopoverContextValue, 'open' | 'mountNode' | 'noArrow' | 'size' | 'brand' | 'inverted' | 'arrowRef'> {\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n}\n"]}
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import { __assign } from "tslib";
|
2
2
|
import * as React from 'react';
|
3
|
-
import { getSlotsCompat } from '@fluentui/react-utilities';
|
4
3
|
import { Portal } from '@fluentui/react-portal';
|
4
|
+
import { getSlots } from '@fluentui/react-utilities';
|
5
|
+
import { popoverSurfaceSlots } from './usePopoverSurface';
|
5
6
|
/**
|
6
7
|
* Render the final JSX of PopoverSurface
|
7
8
|
*/
|
8
9
|
|
9
10
|
export var renderPopoverSurface = function (state) {
|
10
|
-
var _a =
|
11
|
+
var _a = getSlots(state, popoverSurfaceSlots),
|
11
12
|
slots = _a.slots,
|
12
13
|
slotProps = _a.slotProps; // TODO should hidden Popovers be supported ?
|
13
14
|
|
@@ -21,6 +22,6 @@ export var renderPopoverSurface = function (state) {
|
|
21
22
|
}, /*#__PURE__*/React.createElement(slots.root, __assign({}, slotProps.root), !state.noArrow && /*#__PURE__*/React.createElement("div", {
|
22
23
|
ref: state.arrowRef,
|
23
24
|
className: state.arrowClassName
|
24
|
-
}),
|
25
|
+
}), slotProps.root.children));
|
25
26
|
};
|
26
27
|
//# sourceMappingURL=renderPopoverSurface.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,
|
1
|
+
{"version":3,"sources":["components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAEA,SAAS,mBAAT,QAAoC,qBAApC;AAEA;;AAEG;;AACH,OAAO,IAAM,oBAAoB,GAAG,UAAC,KAAD,EAA2B;AACvD,MAAA,EAAA,GAAuB,QAAQ,CAAsB,KAAtB,EAA6B,mBAA7B,CAA/B;AAAA,MAAE,KAAK,GAAA,EAAA,CAAA,KAAP;AAAA,MAAS,SAAS,GAAA,EAAA,CAAA,SAAlB,CADuD,CAG7D;;;AACA,MAAI,CAAC,KAAK,CAAC,IAAX,EAAiB;AACf,WAAO,IAAP;AACD;;AAED,sBACE,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO;AAAC,IAAA,SAAS,EAAE,KAAK,CAAC;AAAlB,GAAP,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,IAAf,CAAX,EACG,CAAC,KAAK,CAAC,OAAP,iBAAkB,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAK,IAAA,GAAG,EAAE,KAAK,CAAC,QAAhB;AAA0B,IAAA,SAAS,EAAE,KAAK,CAAC;AAA3C,GAAA,CADrB,EAEG,SAAS,CAAC,IAAV,CAAe,QAFlB,CADF,CADF;AAQD,CAhBM","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';\nimport { popoverSurfaceSlots } from './usePopoverSurface';\n\n/**\n * Render the final JSX of PopoverSurface\n */\nexport const renderPopoverSurface = (state: PopoverSurfaceState) => {\n const { slots, slotProps } = getSlots<PopoverSurfaceSlots>(state, popoverSurfaceSlots);\n\n // TODO should hidden Popovers be supported ?\n if (!state.open) {\n return null;\n }\n\n return (\n <Portal mountNode={state.mountNode}>\n <slots.root {...slotProps.root}>\n {!state.noArrow && <div ref={state.arrowRef} className={state.arrowClassName} />}\n {slotProps.root.children}\n </slots.root>\n </Portal>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import type { PopoverSurfaceProps, PopoverSurfaceState } from './PopoverSurface.types';
|
2
|
+
import type { PopoverSurfaceProps, PopoverSurfaceSlots, PopoverSurfaceState } from './PopoverSurface.types';
|
3
|
+
export declare const popoverSurfaceSlots: Array<keyof PopoverSurfaceSlots>;
|
3
4
|
/**
|
4
5
|
* Create the state required to render PopoverSurface.
|
5
6
|
*
|
@@ -7,7 +8,7 @@ import type { PopoverSurfaceProps, PopoverSurfaceState } from './PopoverSurface.
|
|
7
8
|
* before being passed to renderPopoverSurface.
|
8
9
|
*
|
9
10
|
* @param props - props from this instance of PopoverSurface
|
10
|
-
* @param ref - reference to root
|
11
|
+
* @param ref - reference to root HTMLDivElement of PopoverSurface
|
11
12
|
* @param defaultProps - (optional) default prop values provided by the implementing type
|
12
13
|
*/
|
13
|
-
export declare const usePopoverSurface: (props: PopoverSurfaceProps, ref: React.Ref<
|
14
|
+
export declare const usePopoverSurface: (props: PopoverSurfaceProps, ref: React.Ref<HTMLDivElement>) => PopoverSurfaceState;
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { __assign } from "tslib";
|
2
2
|
import * as React from 'react';
|
3
|
-
import {
|
3
|
+
import { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';
|
4
4
|
import { useFocusFinders, useModalAttributes } from '@fluentui/react-tabster';
|
5
5
|
import { usePopoverContext } from '../../popoverContext';
|
6
|
-
var
|
6
|
+
export var popoverSurfaceSlots = ['root'];
|
7
7
|
/**
|
8
8
|
* Create the state required to render PopoverSurface.
|
9
9
|
*
|
@@ -11,11 +11,11 @@ var mergeProps = /*#__PURE__*/makeMergeProps({});
|
|
11
11
|
* before being passed to renderPopoverSurface.
|
12
12
|
*
|
13
13
|
* @param props - props from this instance of PopoverSurface
|
14
|
-
* @param ref - reference to root
|
14
|
+
* @param ref - reference to root HTMLDivElement of PopoverSurface
|
15
15
|
* @param defaultProps - (optional) default prop values provided by the implementing type
|
16
16
|
*/
|
17
17
|
|
18
|
-
export var usePopoverSurface = function (props, ref
|
18
|
+
export var usePopoverSurface = function (props, ref) {
|
19
19
|
var contentRef = usePopoverContext(function (context) {
|
20
20
|
return context.contentRef;
|
21
21
|
});
|
@@ -52,22 +52,31 @@ export var usePopoverSurface = function (props, ref, defaultProps) {
|
|
52
52
|
var modalAttributes = useModalAttributes({
|
53
53
|
trapFocus: trapFocus
|
54
54
|
}).modalAttributes;
|
55
|
-
|
55
|
+
|
56
|
+
var state = __assign(__assign({
|
56
57
|
brand: brand,
|
57
58
|
inverted: inverted,
|
58
59
|
noArrow: noArrow,
|
59
60
|
size: size,
|
60
61
|
arrowRef: arrowRef,
|
61
62
|
open: open,
|
62
|
-
mountNode: mountNode
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
mountNode: mountNode
|
64
|
+
}, props), {
|
65
|
+
components: {
|
66
|
+
root: 'div'
|
67
|
+
},
|
68
|
+
root: getNativeElementProps('div', __assign(__assign({
|
69
|
+
ref: useMergedRefs(ref, contentRef),
|
70
|
+
role: 'dialog'
|
71
|
+
}, modalAttributes), props))
|
72
|
+
});
|
73
|
+
|
74
|
+
var _a = state.root,
|
75
|
+
onMouseEnterOriginal = _a.onMouseEnter,
|
76
|
+
onMouseLeaveOriginal = _a.onMouseLeave,
|
77
|
+
onKeyDownOriginal = _a.onKeyDown;
|
69
78
|
|
70
|
-
state.onMouseEnter = function (e) {
|
79
|
+
state.root.onMouseEnter = function (e) {
|
71
80
|
if (openOnHover) {
|
72
81
|
setOpen(e, true);
|
73
82
|
}
|
@@ -75,7 +84,7 @@ export var usePopoverSurface = function (props, ref, defaultProps) {
|
|
75
84
|
onMouseEnterOriginal === null || onMouseEnterOriginal === void 0 ? void 0 : onMouseEnterOriginal(e);
|
76
85
|
};
|
77
86
|
|
78
|
-
state.onMouseLeave = function (e) {
|
87
|
+
state.root.onMouseLeave = function (e) {
|
79
88
|
if (openOnHover) {
|
80
89
|
setOpen(e, false);
|
81
90
|
}
|
@@ -83,7 +92,7 @@ export var usePopoverSurface = function (props, ref, defaultProps) {
|
|
83
92
|
onMouseLeaveOriginal === null || onMouseLeaveOriginal === void 0 ? void 0 : onMouseLeaveOriginal(e);
|
84
93
|
};
|
85
94
|
|
86
|
-
state.onKeyDown = function (e) {
|
95
|
+
state.root.onKeyDown = function (e) {
|
87
96
|
var _a; // only close if the event happened inside the current popover
|
88
97
|
// If using a stack of inline popovers, the user should call `stopPropagation` to avoid dismissing the entire stack
|
89
98
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/PopoverSurface/usePopoverSurface.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,
|
1
|
+
{"version":3,"sources":["components/PopoverSurface/usePopoverSurface.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAv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,UAAD,EAAa,kBAAb,EAAiC,KAAK,CAAC,IAAvC,CALH;AAMA,SAAO,KAAP;AACD,CA1EM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';\nimport { useFocusFinders, useModalAttributes } from '@fluentui/react-tabster';\nimport { usePopoverContext } from '../../popoverContext';\nimport type { PopoverSurfaceProps, PopoverSurfaceSlots, PopoverSurfaceState } from './PopoverSurface.types';\n\nexport const popoverSurfaceSlots: Array<keyof PopoverSurfaceSlots> = ['root'];\n\n/**\n * Create the state required to render PopoverSurface.\n *\n * The returned state can be modified with hooks such as usePopoverSurfaceStyles,\n * before being passed to renderPopoverSurface.\n *\n * @param props - props from this instance of PopoverSurface\n * @param ref - reference to root HTMLDivElement of PopoverSurface\n * @param defaultProps - (optional) default prop values provided by the implementing type\n */\nexport const usePopoverSurface = (props: PopoverSurfaceProps, ref: React.Ref<HTMLDivElement>): PopoverSurfaceState => {\n const contentRef = usePopoverContext(context => context.contentRef);\n const open = usePopoverContext(context => context.open);\n const openOnHover = usePopoverContext(context => context.openOnHover);\n const setOpen = usePopoverContext(context => context.setOpen);\n const mountNode = usePopoverContext(context => context.mountNode);\n const arrowRef = usePopoverContext(context => context.arrowRef);\n const size = usePopoverContext(context => context.size);\n const noArrow = usePopoverContext(context => context.noArrow);\n const brand = usePopoverContext(context => context.brand);\n const inverted = usePopoverContext(context => context.inverted);\n const trapFocus = usePopoverContext(context => context.trapFocus);\n const { modalAttributes } = useModalAttributes({ trapFocus });\n\n const state: PopoverSurfaceState = {\n brand,\n inverted,\n noArrow,\n size,\n arrowRef,\n open,\n mountNode,\n ...props,\n components: {\n root: 'div',\n },\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, contentRef),\n role: 'dialog',\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 const { findFirstFocusable } = useFocusFinders();\n\n React.useEffect(() => {\n if (state.open && contentRef.current) {\n const firstFocusable = findFirstFocusable(contentRef.current);\n firstFocusable?.focus();\n }\n }, [contentRef, findFirstFocusable, state.open]);\n return state;\n};\n"],"sourceRoot":"../src/"}
|
@@ -81,7 +81,7 @@ var useStyles = /*#__PURE__*/__styles({
|
|
81
81
|
|
82
82
|
export var usePopoverSurfaceStyles = function (state) {
|
83
83
|
var styles = useStyles();
|
84
|
-
state.className = mergeClasses(styles.root, state.size === 'small' && styles.smallPadding, state.size === 'medium' && styles.mediumPadding, state.size === 'large' && styles.largePadding, state.inverted && styles.inverted, state.brand && styles.brand, state.className);
|
84
|
+
state.root.className = mergeClasses(styles.root, state.size === 'small' && styles.smallPadding, state.size === 'medium' && styles.mediumPadding, state.size === 'large' && styles.largePadding, state.inverted && styles.inverted, state.brand && styles.brand, state.root.className);
|
85
85
|
state.arrowClassName = mergeClasses(styles.arrow, state.size === 'small' ? styles.smallArrow : styles.mediumLargeArrow);
|
86
86
|
return state;
|
87
87
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/PopoverSurface/usePopoverSurfaceStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,QAAyC,6BAAzC;AAIA,OAAO,IAAM,YAAY,GAAgC;AACv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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAlB;AAoEA;;AAEG;;;AACH,OAAO,IAAM,uBAAuB,GAAG,UAAC,KAAD,EAA2B;AAChE,MAAM,MAAM,GAAG,SAAS,EAAxB;AACA,EAAA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CACjC,MAAM,CAAC,IAD0B,EAEjC,KAAK,CAAC,IAAN,KAAe,OAAf,IAA0B,MAAM,CAAC,YAFA,EAGjC,KAAK,CAAC,IAAN,KAAe,QAAf,IAA2B,MAAM,CAAC,aAHD,EAIjC,KAAK,CAAC,IAAN,KAAe,OAAf,IAA0B,MAAM,CAAC,YAJA,EAKjC,KAAK,CAAC,QAAN,IAAkB,MAAM,CAAC,QALQ,EAMjC,KAAK,CAAC,KAAN,IAAe,MAAM,CAAC,KANW,EAOjC,KAAK,CAAC,IAAN,CAAW,SAPsB,CAAnC;AAUA,EAAA,KAAK,CAAC,cAAN,GAAuB,YAAY,CACjC,MAAM,CAAC,KAD0B,EAEjC,KAAK,CAAC,IAAN,KAAe,OAAf,GAAyB,MAAM,CAAC,UAAhC,GAA6C,MAAM,CAAC,gBAFnB,CAAnC;AAKA,SAAO,KAAP;AACD,CAlBM","sourcesContent":["import { makeStyles, mergeClasses } from '@fluentui/react-make-styles';\nimport type { PopoverSize } from '../Popover/Popover.types';\nimport type { PopoverSurfaceState } from './PopoverSurface.types';\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: theme => ({\n backgroundColor: theme.alias.color.neutral.neutralBackground1,\n boxShadow: theme.alias.shadow.shadow16,\n borderRadius: '4px',\n }),\n\n inverted: theme => ({\n // TODO: neutral background inverted missing from superset and theme\n backgroundColor: theme.global.palette.grey[16],\n color: theme.alias.color.neutral.neutralForegroundInverted,\n }),\n\n brand: theme => ({\n backgroundColor: theme.alias.color.neutral.brandBackground,\n // TODO: clarify with designers what foreground color should be with brand background,\n color: theme.alias.color.neutral.neutralForegroundInverted,\n }),\n\n smallPadding: () => ({\n padding: '12px',\n }),\n\n mediumPadding: () => ({\n padding: '16px',\n }),\n\n largePadding: () => ({\n padding: '20px',\n }),\n\n smallArrow: () => ({\n width: `${Math.SQRT2 * arrowHeights.small}px`,\n height: `${Math.SQRT2 * arrowHeights.small}px`,\n }),\n\n mediumLargeArrow: () => ({\n width: `${Math.SQRT2 * arrowHeights.medium}px`,\n height: `${Math.SQRT2 * arrowHeights.medium}px`,\n }),\n\n // TODO dedupe these styles with tooltip\n arrow: theme => ({\n position: 'absolute',\n background: 'inherit',\n visibility: 'hidden',\n zIndex: -1,\n\n ':before': {\n content: '\"\"',\n borderRadius: '4px',\n position: 'absolute',\n width: 'inherit',\n height: 'inherit',\n background: 'inherit',\n visibility: 'visible',\n borderBottomRightRadius: theme.global.borderRadius.small,\n transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',\n },\n\n // Popper sets data-popper-placement on the root element, which is used to align the arrow\n ':global([data-popper-placement^=\"top\"])': { bottom: 0, '--angle': '0' },\n ':global([data-popper-placement^=\"right\"])': { left: 0, '--angle': '90deg' },\n ':global([data-popper-placement^=\"bottom\"])': { top: 0, '--angle': '180deg' },\n ':global([data-popper-placement^=\"left\"])': { right: 0, '--angle': '270deg' },\n }),\n});\n\n/**\n * Apply styling to the PopoverSurface slots based on the state\n */\nexport const usePopoverSurfaceStyles = (state: PopoverSurfaceState): PopoverSurfaceState => {\n const styles = useStyles();\n state.root.className = mergeClasses(\n styles.root,\n state.size === 'small' && styles.smallPadding,\n state.size === 'medium' && styles.mediumPadding,\n state.size === 'large' && styles.largePadding,\n state.inverted && styles.inverted,\n state.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"],"sourceRoot":"../src/"}
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import { __assign } from "tslib";
|
2
2
|
import * as React from 'react';
|
3
|
-
import {
|
3
|
+
import { useMergedRefs, useEventCallback, shouldPreventDefaultOnKeyDown } from '@fluentui/react-utilities';
|
4
4
|
import { useModalAttributes } from '@fluentui/react-tabster';
|
5
5
|
import { usePopoverContext } from '../../popoverContext';
|
6
|
-
var mergeProps = /*#__PURE__*/makeMergeProps({});
|
7
6
|
/**
|
8
7
|
* Create the state required to render PopoverTrigger.
|
9
8
|
*
|
@@ -31,9 +30,6 @@ export var usePopoverTrigger = function (props, defaultProps) {
|
|
31
30
|
return context.openOnContext;
|
32
31
|
});
|
33
32
|
var triggerAttributes = useModalAttributes().triggerAttributes;
|
34
|
-
var state = mergeProps({
|
35
|
-
children: null
|
36
|
-
}, defaultProps, props);
|
37
33
|
var onContextMenu = useEventCallback(function (e) {
|
38
34
|
var _a, _b;
|
39
35
|
|
@@ -85,16 +81,17 @@ export var usePopoverTrigger = function (props, defaultProps) {
|
|
85
81
|
|
86
82
|
(_b = (_a = child.props) === null || _a === void 0 ? void 0 : _a.onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
87
83
|
});
|
88
|
-
var child = React.Children.only(
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
84
|
+
var child = React.Children.only(props.children);
|
85
|
+
return {
|
86
|
+
children: /*#__PURE__*/React.cloneElement(child, __assign({
|
87
|
+
'aria-haspopup': 'true',
|
88
|
+
onClick: onClick,
|
89
|
+
onMouseEnter: onMouseEnter,
|
90
|
+
onKeyDown: onKeyDown,
|
91
|
+
onMouseLeave: onMouseLeave,
|
92
|
+
onContextMenu: onContextMenu,
|
93
|
+
ref: useMergedRefs(child.ref, triggerRef)
|
94
|
+
}, triggerAttributes))
|
95
|
+
};
|
99
96
|
};
|
100
97
|
//# sourceMappingURL=usePopoverTrigger.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/PopoverTrigger/usePopoverTrigger.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,
|
1
|
+
{"version":3,"sources":["components/PopoverTrigger/usePopoverTrigger.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,aAAT,EAAwB,gBAAxB,EAA0C,6BAA1C,QAA+E,2BAA/E;AACA,SAAS,kBAAT,QAAmC,yBAAnC;AACA,SAAS,iBAAT,QAAkC,sBAAlC;AAGA;;;;;;;;AAQG;;AACH,OAAO,IAAM,iBAAiB,GAAG,UAC/B,KAD+B,EAE/B,YAF+B,EAEG;AAElC,MAAM,OAAO,GAAG,iBAAiB,CAAC,UAAA,OAAA,EAAO;AAAI,WAAA,OAAO,CAAP,OAAA;AAAe,GAA3B,CAAjC;AACA,MAAM,IAAI,GAAG,iBAAiB,CAAC,UAAA,OAAA,EAAO;AAAI,WAAA,OAAO,CAAP,IAAA;AAAY,GAAxB,CAA9B;AACA,MAAM,UAAU,GAAG,iBAAiB,CAAC,UAAA,OAAA,EAAO;AAAI,WAAA,OAAO,CAAP,UAAA;AAAkB,GAA9B,CAApC;AACA,MAAM,WAAW,GAAG,iBAAiB,CAAC,UAAA,OAAA,EAAO;AAAI,WAAA,OAAO,CAAP,WAAA;AAAmB,GAA/B,CAArC;AACA,MAAM,aAAa,GAAG,iBAAiB,CAAC,UAAA,OAAA,EAAO;AAAI,WAAA,OAAO,CAAP,aAAA;AAAqB,GAAjC,CAAvC;AACQ,MAAA,iBAAiB,GAAK,kBAAkB,GAAvB,iBAAjB;AAER,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAC,CAAD,EAAiC;;;AACtE,QAAI,aAAJ,EAAmB;AACjB,MAAA,CAAC,CAAC,cAAF;AACA,MAAA,OAAO,CAAC,CAAD,EAAI,IAAJ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AK,CAAC,YAAN,CAAmB,KAAnB,EAAwB,QAAA,CAAA;AAChC,uBAAiB,MADe;AAEhC,MAAA,OAAO,EAAA,OAFyB;AAGhC,MAAA,YAAY,EAAA,YAHoB;AAIhC,MAAA,SAAS,EAAA,SAJuB;AAKhC,MAAA,YAAY,EAAA,YALoB;AAMhC,MAAA,aAAa,EAAA,aANmB;AAOhC,MAAA,GAAG,EAAE,aAAa,CAAG,KAAuE,CAAC,GAA3E,EAAgF,UAAhF;AAPc,KAAA,EAQ7B,iBAR6B,CAAxB;AADL,GAAP;AAYD,CAnEM","sourcesContent":["import * as React from 'react';\nimport { useMergedRefs, useEventCallback, shouldPreventDefaultOnKeyDown } from '@fluentui/react-utilities';\nimport { useModalAttributes } from '@fluentui/react-tabster';\nimport { usePopoverContext } from '../../popoverContext';\nimport type { 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.\n *\n * @param props - props from this instance of PopoverTrigger\n * @param defaultProps - (optional) default prop values provided by the implementing type\n */\nexport const usePopoverTrigger = (\n props: PopoverTriggerProps,\n defaultProps?: PopoverTriggerProps,\n): PopoverTriggerState => {\n const setOpen = usePopoverContext(context => context.setOpen);\n const open = usePopoverContext(context => context.open);\n const triggerRef = usePopoverContext(context => context.triggerRef);\n const openOnHover = usePopoverContext(context => context.openOnHover);\n const openOnContext = usePopoverContext(context => context.openOnContext);\n const { triggerAttributes } = useModalAttributes();\n\n const onContextMenu = useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (openOnContext) {\n e.preventDefault();\n setOpen(e, true);\n }\n\n child.props?.onContextMenu?.(e);\n });\n\n const onClick = useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (!openOnContext) {\n setOpen(e, !open);\n }\n child.props?.onClick?.(e);\n });\n\n const onKeyDown = useEventCallback((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 child.props?.onKeyDown?.(e);\n });\n\n const onMouseEnter = useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (openOnHover) {\n setOpen(e, true);\n }\n child.props?.onMouseEnter?.(e);\n });\n\n const onMouseLeave = useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (openOnHover) {\n setOpen(e, false);\n }\n child.props?.onMouseLeave?.(e);\n });\n\n const child = React.Children.only(props.children);\n return {\n children: React.cloneElement(child, {\n 'aria-haspopup': 'true',\n onClick,\n onMouseEnter,\n onKeyDown,\n onMouseLeave,\n onContextMenu,\n ref: useMergedRefs(((child as unknown) as React.ReactElement & React.RefAttributes<unknown>).ref, triggerRef),\n ...triggerAttributes,\n }),\n };\n};\n"],"sourceRoot":"../src/"}
|
@@ -6,6 +6,8 @@ define(["require", "exports", "@fluentui/react-conformance", "@fluentui/react-co
|
|
6
6
|
var defaultOptions = {
|
7
7
|
asPropHandlesRef: true,
|
8
8
|
componentPath: module.parent.filename.replace('.test', ''),
|
9
|
+
// TODO // https://github.com/microsoft/fluentui/issues/19522
|
10
|
+
skipAsPropTests: true,
|
9
11
|
extraTests: react_conformance_make_styles_1.default,
|
10
12
|
};
|
11
13
|
react_conformance_1.isConformant(defaultOptions, testInfo);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"isConformant.js","sourceRoot":"../src/","sources":["common/isConformant.ts"],"names":[],"mappings":";;;;IAIA,SAAgB,YAAY,CAC1B,QAAyF;QAEzF,IAAM,cAAc,GAAyC;YAC3D,gBAAgB,EAAE,IAAI;YACtB,aAAa,EAAE,MAAO,CAAC,MAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAC5D,UAAU,EAAE,uCAAqC;SAClD,CAAC;QAEF,gCAAgB,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;
|
1
|
+
{"version":3,"file":"isConformant.js","sourceRoot":"../src/","sources":["common/isConformant.ts"],"names":[],"mappings":";;;;IAIA,SAAgB,YAAY,CAC1B,QAAyF;QAEzF,IAAM,cAAc,GAAyC;YAC3D,gBAAgB,EAAE,IAAI;YACtB,aAAa,EAAE,MAAO,CAAC,MAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAC5D,6DAA6D;YAC7D,eAAe,EAAE,IAAI;YACrB,UAAU,EAAE,uCAAqC;SAClD,CAAC;QAEF,gCAAgB,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAZD,oCAYC","sourcesContent":["import { isConformant as baseIsConformant } from '@fluentui/react-conformance';\nimport type { IsConformantOptions, TestObject } from '@fluentui/react-conformance';\nimport makeStylesTests from '@fluentui/react-conformance-make-styles';\n\nexport function isConformant<TProps = {}>(\n testInfo: Omit<IsConformantOptions<TProps>, 'componentPath'> & { componentPath?: string },\n) {\n const defaultOptions: Partial<IsConformantOptions<TProps>> = {\n asPropHandlesRef: true,\n componentPath: module!.parent!.filename.replace('.test', ''),\n // TODO // https://github.com/microsoft/fluentui/issues/19522\n skipAsPropTests: true,\n extraTests: makeStylesTests as TestObject<TProps>,\n };\n\n baseIsConformant(defaultOptions, testInfo);\n}\n"]}
|
@@ -1,20 +1,15 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import type { PopperVirtualElement, PositioningShorthand } from '@fluentui/react-positioning';
|
2
|
+
import type { PopperVirtualElement, PositioningShorthand, usePopperMouseTarget } from '@fluentui/react-positioning';
|
3
3
|
import type { PortalProps } from '@fluentui/react-portal';
|
4
|
-
import type { ComponentStateCompat } from '@fluentui/react-utilities';
|
5
4
|
/**
|
6
5
|
* Determines popover padding and arrow size
|
7
6
|
*/
|
8
7
|
export declare type PopoverSize = 'small' | 'medium' | 'large';
|
9
|
-
|
10
|
-
* Popover Props
|
11
|
-
*/
|
12
|
-
export interface PopoverProps extends Pick<PortalProps, 'mountNode'> {
|
13
|
-
children: React.ReactNode;
|
8
|
+
export interface PopoverCommons extends Pick<PortalProps, 'mountNode'> {
|
14
9
|
/**
|
15
10
|
* Controls the opening of the Popover
|
16
11
|
*/
|
17
|
-
open
|
12
|
+
open: boolean;
|
18
13
|
/**
|
19
14
|
* Used to set the initial open state of the Popover in uncontrolled mode
|
20
15
|
*/
|
@@ -61,21 +56,19 @@ export interface PopoverProps extends Pick<PortalProps, 'mountNode'> {
|
|
61
56
|
positioning?: PositioningShorthand;
|
62
57
|
}
|
63
58
|
/**
|
64
|
-
*
|
65
|
-
*/
|
66
|
-
export declare type PopoverShorthandProps = never;
|
67
|
-
/**
|
68
|
-
* Names of PopoverProps that have a default value in usePopover
|
59
|
+
* Popover Props
|
69
60
|
*/
|
70
|
-
export
|
61
|
+
export interface PopoverProps extends Partial<PopoverCommons> {
|
62
|
+
/**
|
63
|
+
* Can contain two children including {@link PopoverTrigger} and {@link PopoverPopover}.
|
64
|
+
* Alternatively can only contain {@link PopoverPopover} if using a custom `target`.
|
65
|
+
*/
|
66
|
+
children: [JSX.Element, JSX.Element] | JSX.Element;
|
67
|
+
}
|
71
68
|
/**
|
72
69
|
* Popover State
|
73
70
|
*/
|
74
|
-
export interface PopoverState extends
|
75
|
-
/**
|
76
|
-
* Open state of the Popover
|
77
|
-
*/
|
78
|
-
open: boolean;
|
71
|
+
export interface PopoverState extends PopoverCommons, Pick<PopoverProps, 'children'> {
|
79
72
|
/**
|
80
73
|
* Callback to open/close the Popover
|
81
74
|
*/
|
@@ -99,7 +92,7 @@ export interface PopoverState extends ComponentStateCompat<PopoverProps, Popover
|
|
99
92
|
/**
|
100
93
|
* A callback to set the target of the popper to the mouse click for context events
|
101
94
|
*/
|
102
|
-
setContextTarget:
|
95
|
+
setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];
|
103
96
|
size: NonNullable<PopoverProps['size']>;
|
104
97
|
}
|
105
98
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Popover.types.js","sourceRoot":"../src/","sources":["components/Popover/Popover.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PopperVirtualElement, PositioningShorthand } from '@fluentui/react-positioning';\nimport type { PortalProps } from '@fluentui/react-portal';\
|
1
|
+
{"version":3,"file":"Popover.types.js","sourceRoot":"../src/","sources":["components/Popover/Popover.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PopperVirtualElement, PositioningShorthand, usePopperMouseTarget } from '@fluentui/react-positioning';\nimport type { PortalProps } from '@fluentui/react-portal';\n\n/**\n * Determines popover padding and arrow size\n */\nexport type PopoverSize = 'small' | 'medium' | 'large';\n\nexport interface PopoverCommons extends Pick<PortalProps, 'mountNode'> {\n /**\n * Controls the opening of the Popover\n */\n open: boolean;\n /**\n * Used to set the initial open state of the Popover in uncontrolled mode\n */\n defaultOpen?: boolean;\n /**\n * Call back when the component requests to change value\n * The `open` value is used as a hint when directly controlling the component\n */\n onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;\n /**\n * Flag to open the Popover by hovering the trigger\n */\n openOnHover?: boolean;\n /**\n * Flag to open the Popover as a context menu. Disables all other interactions\n */\n openOnContext?: boolean;\n /**\n * Do not display the arrow\n */\n noArrow?: boolean;\n /**\n * Determines popover padding and arrow size\n * @default medium\n */\n size?: PopoverSize;\n /**\n * Uses brand colour as background\n * Mutually exclusive with `inverted`\n */\n brand?: boolean;\n /**\n * Inverts the foreground/background colour of the popover\n * Mutually exclusive with `brand`\n */\n inverted?: boolean;\n\n /**\n * Should trap focus\n */\n trapFocus?: boolean;\n\n /**\n * Configures the position of the Popover\n */\n positioning?: PositioningShorthand;\n}\n\n/**\n * Popover Props\n */\nexport interface PopoverProps extends Partial<PopoverCommons> {\n /**\n * Can contain two children including {@link PopoverTrigger} and {@link PopoverPopover}.\n * Alternatively can only contain {@link PopoverPopover} if using a custom `target`.\n */\n children: [JSX.Element, JSX.Element] | JSX.Element;\n}\n\n/**\n * Popover State\n */\nexport interface PopoverState extends PopoverCommons, Pick<PopoverProps, 'children'> {\n /**\n * Callback to open/close the Popover\n */\n setOpen: (e: OpenPopoverEvents, open: boolean) => void;\n /**\n * Ref of the PopoverTrigger\n */\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n /**\n * Ref of the PopoverSurface\n */\n contentRef: React.MutableRefObject<HTMLElement | null>;\n /**\n * Ref of the pointing arrow\n */\n arrowRef: React.MutableRefObject<HTMLDivElement | null>;\n /**\n * Anchors the popper to the mouse click for context events\n */\n contextTarget: PopperVirtualElement | undefined;\n /**\n * A callback to set the target of the popper to the mouse click for context events\n */\n setContextTarget: ReturnType<typeof usePopperMouseTarget>[1];\n\n size: NonNullable<PopoverProps['size']>;\n}\n\n/**\n * Data attached to open/close events\n */\nexport interface OnOpenChangeData extends Pick<PopoverState, 'open'> {}\n\n/**\n * The supported events that will trigger open/close of the menu\n */\nexport type OpenPopoverEvents =\n | MouseEvent\n | TouchEvent\n | React.MouseEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.FocusEvent<HTMLElement>;\n"]}
|
@@ -2,10 +2,6 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
2
2
|
"use strict";
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
4
|
exports.usePopover = void 0;
|
5
|
-
/**
|
6
|
-
* Names of the shorthand properties in PopoverProps
|
7
|
-
*/
|
8
|
-
var mergeProps = react_utilities_1.makeMergeProps({});
|
9
5
|
/**
|
10
6
|
* Create the state required to render Popover.
|
11
7
|
*
|
@@ -16,58 +12,52 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
16
12
|
* @param defaultProps - (optional) default prop values provided by the implementing type
|
17
13
|
*/
|
18
14
|
var usePopover = function (props, defaultProps) {
|
19
|
-
var
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
contentRef: { current: null },
|
25
|
-
arrowRef: { current: null },
|
26
|
-
children: null,
|
27
|
-
setContextTarget: function () { return null; },
|
28
|
-
contextTarget: undefined,
|
29
|
-
}, defaultProps, props);
|
30
|
-
var _a = React.useState(), contextTarget = _a[0], setContextTarget = _a[1];
|
31
|
-
state.setContextTarget = setContextTarget;
|
32
|
-
state.contextTarget = contextTarget;
|
33
|
-
useOpenState(state);
|
34
|
-
usePopoverRefs(state);
|
15
|
+
var _a = react_positioning_1.usePopperMouseTarget(), contextTarget = _a[0], setContextTarget = _a[1];
|
16
|
+
var initialState = tslib_1.__assign({ size: 'medium', contextTarget: contextTarget,
|
17
|
+
setContextTarget: setContextTarget }, props);
|
18
|
+
var _b = useOpenState(initialState), open = _b[0], setOpen = _b[1];
|
19
|
+
var popperRefs = usePopoverRefs(initialState);
|
35
20
|
var targetDocument = react_shared_contexts_1.useFluent().targetDocument;
|
36
21
|
react_utilities_1.useOnClickOutside({
|
37
22
|
contains: react_portal_1.elementContains,
|
38
23
|
element: targetDocument,
|
39
|
-
callback: function (ev) { return
|
40
|
-
refs: [
|
41
|
-
disabled: !
|
24
|
+
callback: function (ev) { return setOpen(ev, false); },
|
25
|
+
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
26
|
+
disabled: !open,
|
42
27
|
});
|
43
28
|
react_utilities_1.useOnScrollOutside({
|
44
29
|
contains: react_portal_1.elementContains,
|
45
30
|
element: targetDocument,
|
46
|
-
callback: function (ev) { return
|
47
|
-
refs: [
|
48
|
-
disabled: !
|
31
|
+
callback: function (ev) { return setOpen(ev, false); },
|
32
|
+
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
33
|
+
disabled: !open || !initialState.openOnContext,
|
49
34
|
});
|
50
|
-
return
|
35
|
+
return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, initialState), popperRefs), { open: open,
|
36
|
+
setOpen: setOpen,
|
37
|
+
setContextTarget: setContextTarget,
|
38
|
+
contextTarget: contextTarget });
|
51
39
|
};
|
52
40
|
exports.usePopover = usePopover;
|
53
41
|
/**
|
54
42
|
* Creates and manages the Popover open state
|
55
|
-
* @param state Popover state
|
56
43
|
*/
|
57
44
|
function useOpenState(state) {
|
58
45
|
var onOpenChange = react_utilities_1.useEventCallback(function (e, data) { var _a; return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data); });
|
59
|
-
var _a = react_utilities_1.
|
46
|
+
var _a = react_utilities_1.useControllableState({
|
47
|
+
state: state.open,
|
48
|
+
defaultState: state.defaultOpen,
|
49
|
+
initialState: false,
|
50
|
+
}), open = _a[0], setOpenState = _a[1];
|
60
51
|
state.open = open !== undefined ? open : state.open;
|
61
52
|
var setContextTarget = state.setContextTarget;
|
62
|
-
|
53
|
+
var setOpen = React.useCallback(function (e, shouldOpen) {
|
63
54
|
if (shouldOpen && e.type === 'contextmenu') {
|
64
|
-
|
65
|
-
setContextTarget(virtualElement);
|
55
|
+
setContextTarget(e);
|
66
56
|
}
|
67
57
|
if (!shouldOpen) {
|
68
58
|
setContextTarget(undefined);
|
69
59
|
}
|
70
|
-
|
60
|
+
setOpenState(function (prevOpen) {
|
71
61
|
// More than one event (mouse, focus, keyboard) can request the Popover to close
|
72
62
|
// We assume the first event is the correct one
|
73
63
|
if (prevOpen !== shouldOpen) {
|
@@ -75,12 +65,11 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
75
65
|
}
|
76
66
|
return shouldOpen;
|
77
67
|
});
|
78
|
-
}, [
|
79
|
-
return
|
68
|
+
}, [setOpenState, onOpenChange, setContextTarget]);
|
69
|
+
return [open, setOpen];
|
80
70
|
}
|
81
71
|
/**
|
82
72
|
* Creates and sets the necessary trigger, target and content refs used by Popover
|
83
|
-
* @param state Popover state
|
84
73
|
*/
|
85
74
|
function usePopoverRefs(state) {
|
86
75
|
var popperOptions = tslib_1.__assign({ position: 'above', align: 'center', target: state.openOnContext ? state.contextTarget : undefined }, react_positioning_1.resolvePositioningShorthand(state.positioning));
|
@@ -92,10 +81,11 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
92
81
|
popperOptions.offset = react_positioning_1.mergeArrowOffset(popperOptions.offset, index_1.arrowHeights[state.size]);
|
93
82
|
}
|
94
83
|
var _a = react_positioning_1.usePopper(popperOptions), triggerRef = _a.targetRef, contentRef = _a.containerRef, arrowRef = _a.arrowRef;
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
84
|
+
return {
|
85
|
+
triggerRef: triggerRef,
|
86
|
+
contentRef: contentRef,
|
87
|
+
arrowRef: arrowRef,
|
88
|
+
};
|
99
89
|
}
|
100
90
|
});
|
101
91
|
//# sourceMappingURL=usePopover.js.map
|