@fluentui/react-popover 9.0.0-alpha.40 → 9.0.0-alpha.44
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 +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,"file":"usePopover.js","sourceRoot":"../src/","sources":["components/Popover/usePopover.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"usePopover.js","sourceRoot":"../src/","sources":["components/Popover/usePopover.ts"],"names":[],"mappings":";;;;IAkBA;;;;;;;;OAQG;IACI,IAAM,UAAU,GAAG,UAAC,KAAmB,EAAE,YAA2B;QACnE,IAAA,KAAoC,wCAAoB,EAAE,EAAzD,aAAa,QAAA,EAAE,gBAAgB,QAA0B,CAAC;QACjE,IAAM,YAAY,GAAG,mBACnB,IAAI,EAAE,QAAQ,EACd,aAAa,eAAA;YACb,gBAAgB,kBAAA,IACb,KAAK,CACA,CAAC;QAEL,IAAA,KAAkB,YAAY,CAAC,YAAY,CAAC,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAC;QACnD,IAAM,UAAU,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;QAExC,IAAA,cAAc,GAAK,iCAAS,EAAE,eAAhB,CAAiB;QACvC,mCAAiB,CAAC;YAChB,QAAQ,EAAE,8BAAe;YACzB,OAAO,EAAE,cAAc;YACvB,QAAQ,EAAE,UAAA,EAAE,IAAI,OAAA,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,EAAlB,CAAkB;YAClC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC;YACpD,QAAQ,EAAE,CAAC,IAAI;SAChB,CAAC,CAAC;QACH,oCAAkB,CAAC;YACjB,QAAQ,EAAE,8BAAe;YACzB,OAAO,EAAE,cAAc;YACvB,QAAQ,EAAE,UAAA,EAAE,IAAI,OAAA,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,EAAlB,CAAkB;YAClC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC;YACpD,QAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,YAAY,CAA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CAAC;QACL,CAAC,EACD,CAAC,YAAY,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAC/C,CAAC;QAEF,OAAO,CAAC,IAAI,EAAE,OAAO,CAAU,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,SAAS,cAAc,CACrB,KAAqH;QAErH,IAAM,aAAa,sBACjB,QAAQ,EAAE,OAAgB,EAC1B,KAAK,EAAE,QAAiB,EACxB,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,IAC1D,+CAA2B,CAAC,KAAK,CAAC,WAAW,CAAC,CAClD,CAAC;QAEF,qDAAqD;QACrD,IAAI,aAAa,CAAC,WAAW,EAAE;YAC7B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;SACtB;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;YAClB,aAAa,CAAC,MAAM,GAAG,oCAAgB,CAAC,aAAa,CAAC,MAAM,EAAE,oBAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;SACzF;QAEK,IAAA,KAAgE,6BAAS,CAAC,aAAa,CAAC,EAA3E,UAAU,eAAA,EAAgB,UAAU,kBAAA,EAAE,QAAQ,cAA6B,CAAC;QAE/F,OAAO;YACL,UAAU,YAAA;YACV,UAAU,YAAA;YACV,QAAQ,UAAA;SACA,CAAC;IACb,CAAC","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"]}
|
|
@@ -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,"file":"PopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":";;;;IAMA;;OAEG;IACU,QAAA,cAAc,GAAG,KAAK,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"PopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/PopoverSurface.tsx"],"names":[],"mappings":";;;;IAMA;;OAEG;IACU,QAAA,cAAc,GAAG,KAAK,CAAC,UAAU,CAAsC,UAAC,KAAK,EAAE,GAAG;QAC7F,IAAM,KAAK,GAAG,qCAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE5C,iDAAuB,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,2CAAoB,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,sBAAc,CAAC,WAAW,GAAG,gBAAgB,CAAC","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"]}
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "tslib", "react", "@fluentui/react-
|
|
1
|
+
define(["require", "exports", "tslib", "react", "@fluentui/react-portal", "@fluentui/react-utilities", "./usePopoverSurface"], function (require, exports, tslib_1, React, react_portal_1, react_utilities_1, usePopoverSurface_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.renderPopoverSurface = void 0;
|
|
@@ -6,7 +6,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
|
6
6
|
* Render the final JSX of PopoverSurface
|
|
7
7
|
*/
|
|
8
8
|
var renderPopoverSurface = function (state) {
|
|
9
|
-
var _a = react_utilities_1.
|
|
9
|
+
var _a = react_utilities_1.getSlots(state, usePopoverSurface_1.popoverSurfaceSlots), slots = _a.slots, slotProps = _a.slotProps;
|
|
10
10
|
// TODO should hidden Popovers be supported ?
|
|
11
11
|
if (!state.open) {
|
|
12
12
|
return null;
|
|
@@ -14,7 +14,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
|
14
14
|
return (React.createElement(react_portal_1.Portal, { mountNode: state.mountNode },
|
|
15
15
|
React.createElement(slots.root, tslib_1.__assign({}, slotProps.root),
|
|
16
16
|
!state.noArrow && React.createElement("div", { ref: state.arrowRef, className: state.arrowClassName }),
|
|
17
|
-
|
|
17
|
+
slotProps.root.children)));
|
|
18
18
|
};
|
|
19
19
|
exports.renderPopoverSurface = renderPopoverSurface;
|
|
20
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"renderPopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/renderPopoverSurface.tsx"],"names":[],"mappings":";;;;IAMA;;OAEG;IACI,IAAM,oBAAoB,GAAG,UAAC,KAA0B;QACvD,IAAA,KAAuB,0BAAQ,CAAsB,KAAK,EAAE,uCAAmB,CAAC,EAA9E,KAAK,WAAA,EAAE,SAAS,eAA8D,CAAC;QAEvF,6CAA6C;QAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAED,OAAO,CACL,oBAAC,qBAAM,IAAC,SAAS,EAAE,KAAK,CAAC,SAAS;YAChC,oBAAC,KAAK,CAAC,IAAI,uBAAK,SAAS,CAAC,IAAI;gBAC3B,CAAC,KAAK,CAAC,OAAO,IAAI,6BAAK,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,cAAc,GAAI;gBAC/E,SAAS,CAAC,IAAI,CAAC,QAAQ,CACb,CACN,CACV,CAAC;IACJ,CAAC,CAAC;IAhBW,QAAA,oBAAoB,wBAgB/B","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"]}
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@fluentui/react-tabster", "../../popoverContext"], function (require, exports, tslib_1, React, react_utilities_1, react_tabster_1, popoverContext_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.usePopoverSurface = void 0;
|
|
5
|
-
|
|
4
|
+
exports.usePopoverSurface = exports.popoverSurfaceSlots = void 0;
|
|
5
|
+
exports.popoverSurfaceSlots = ['root'];
|
|
6
6
|
/**
|
|
7
7
|
* Create the state required to render PopoverSurface.
|
|
8
8
|
*
|
|
@@ -10,10 +10,10 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
|
10
10
|
* before being passed to renderPopoverSurface.
|
|
11
11
|
*
|
|
12
12
|
* @param props - props from this instance of PopoverSurface
|
|
13
|
-
* @param ref - reference to root
|
|
13
|
+
* @param ref - reference to root HTMLDivElement of PopoverSurface
|
|
14
14
|
* @param defaultProps - (optional) default prop values provided by the implementing type
|
|
15
15
|
*/
|
|
16
|
-
var usePopoverSurface = function (props, ref
|
|
16
|
+
var usePopoverSurface = function (props, ref) {
|
|
17
17
|
var contentRef = popoverContext_1.usePopoverContext(function (context) { return context.contentRef; });
|
|
18
18
|
var open = popoverContext_1.usePopoverContext(function (context) { return context.open; });
|
|
19
19
|
var openOnHover = popoverContext_1.usePopoverContext(function (context) { return context.openOnHover; });
|
|
@@ -26,27 +26,29 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
|
26
26
|
var inverted = popoverContext_1.usePopoverContext(function (context) { return context.inverted; });
|
|
27
27
|
var trapFocus = popoverContext_1.usePopoverContext(function (context) { return context.trapFocus; });
|
|
28
28
|
var modalAttributes = react_tabster_1.useModalAttributes({ trapFocus: trapFocus }).modalAttributes;
|
|
29
|
-
var state =
|
|
29
|
+
var state = tslib_1.__assign(tslib_1.__assign({ brand: brand,
|
|
30
30
|
inverted: inverted,
|
|
31
31
|
noArrow: noArrow,
|
|
32
32
|
size: size,
|
|
33
33
|
arrowRef: arrowRef,
|
|
34
34
|
open: open,
|
|
35
|
-
mountNode: mountNode
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
mountNode: mountNode }, props), { components: {
|
|
36
|
+
root: 'div',
|
|
37
|
+
}, root: react_utilities_1.getNativeElementProps('div', tslib_1.__assign(tslib_1.__assign({ ref: react_utilities_1.useMergedRefs(ref, contentRef), role: 'dialog' }, modalAttributes), props)) });
|
|
38
|
+
var _a = state.root, onMouseEnterOriginal = _a.onMouseEnter, onMouseLeaveOriginal = _a.onMouseLeave, onKeyDownOriginal = _a.onKeyDown;
|
|
39
|
+
state.root.onMouseEnter = function (e) {
|
|
38
40
|
if (openOnHover) {
|
|
39
41
|
setOpen(e, true);
|
|
40
42
|
}
|
|
41
43
|
onMouseEnterOriginal === null || onMouseEnterOriginal === void 0 ? void 0 : onMouseEnterOriginal(e);
|
|
42
44
|
};
|
|
43
|
-
state.onMouseLeave = function (e) {
|
|
45
|
+
state.root.onMouseLeave = function (e) {
|
|
44
46
|
if (openOnHover) {
|
|
45
47
|
setOpen(e, false);
|
|
46
48
|
}
|
|
47
49
|
onMouseLeaveOriginal === null || onMouseLeaveOriginal === void 0 ? void 0 : onMouseLeaveOriginal(e);
|
|
48
50
|
};
|
|
49
|
-
state.onKeyDown = function (e) {
|
|
51
|
+
state.root.onKeyDown = function (e) {
|
|
50
52
|
var _a;
|
|
51
53
|
// only close if the event happened inside the current popover
|
|
52
54
|
// If using a stack of inline popovers, the user should call `stopPropagation` to avoid dismissing the entire stack
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/usePopoverSurface.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"usePopoverSurface.js","sourceRoot":"../src/","sources":["components/PopoverSurface/usePopoverSurface.ts"],"names":[],"mappings":";;;;IAMa,QAAA,mBAAmB,GAAqC,CAAC,MAAM,CAAC,CAAC;IAE9E;;;;;;;;;OASG;IACI,IAAM,iBAAiB,GAAG,UAAC,KAA0B,EAAE,GAA8B;QAC1F,IAAM,UAAU,GAAG,kCAAiB,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,UAAU,EAAlB,CAAkB,CAAC,CAAC;QACpE,IAAM,IAAI,GAAG,kCAAiB,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,IAAI,EAAZ,CAAY,CAAC,CAAC;QACxD,IAAM,WAAW,GAAG,kCAAiB,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,WAAW,EAAnB,CAAmB,CAAC,CAAC;QACtE,IAAM,OAAO,GAAG,kCAAiB,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,OAAO,EAAf,CAAe,CAAC,CAAC;QAC9D,IAAM,SAAS,GAAG,kCAAiB,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,SAAS,EAAjB,CAAiB,CAAC,CAAC;QAClE,IAAM,QAAQ,GAAG,kCAAiB,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,QAAQ,EAAhB,CAAgB,CAAC,CAAC;QAChE,IAAM,IAAI,GAAG,kCAAiB,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,IAAI,EAAZ,CAAY,CAAC,CAAC;QACxD,IAAM,OAAO,GAAG,kCAAiB,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W,EAAE;gBACf,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;aACnB;YAED,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAG,CAAC,EAAE;QAC5B,CAAC,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,SAAS,GAAG,UAAC,CAAsC;;YAC5D,8DAA8D;YAC9D,mHAAmH;YACnH,IAAI,CAAC,CAAC,GAAG,KAAK,QAAQ,WAAI,UAAU,CAAC,OAAO,0CAAE,QAAQ,CAAC,CAAC,CAAC,MAAwB,EAAC,EAAE;gBAClF,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;aACnB;YAED,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAG,CAAC,EAAE;QACzB,CAAC,CAAC;QAEM,IAAA,kBAAkB,GAAK,+BAAe,EAAE,mBAAtB,CAAuB;QAEjD,KAAK,CAAC,SAAS,CAAC;YACd,IAAI,KAAK,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE;gBACpC,IAAM,cAAc,GAAG,kBAAkB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBAC9D,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,GAAG;aACzB;QACH,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IA1EW,QAAA,iBAAiB,qBA0E5B","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"]}
|
|
@@ -72,7 +72,7 @@ define(["require", "exports", "@fluentui/react-make-styles"], function (require,
|
|
|
72
72
|
*/
|
|
73
73
|
var usePopoverSurfaceStyles = function (state) {
|
|
74
74
|
var styles = useStyles();
|
|
75
|
-
state.className = react_make_styles_1.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);
|
|
75
|
+
state.root.className = react_make_styles_1.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);
|
|
76
76
|
state.arrowClassName = react_make_styles_1.mergeClasses(styles.arrow, state.size === 'small' ? styles.smallArrow : styles.mediumLargeArrow);
|
|
77
77
|
return state;
|
|
78
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopoverSurfaceStyles.js","sourceRoot":"../src/","sources":["components/PopoverSurface/usePopoverSurfaceStyles.ts"],"names":[],"mappings":";;;;IAIa,QAAA,YAAY,GAAgC;QACvD,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,KAAK,EAAE,CAAC;KACT,CAAC;IAEF;;OAEG;IACH,IAAM,SAAS,GAAG,8BAAU,CAAC;QAC3B,IAAI,EAAE,UAAA,KAAK,IAAI,OAAA,CAAC;YACd,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB;YAC7D,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ;YACtC,YAAY,EAAE,KAAK;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C,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,EACjC,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAC3B,KAAK,CAAC,IAAI,CAAC,SAAS,CACrB,CAAC;QAEF,KAAK,CAAC,cAAc,GAAG,gCAAY,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;IAlBW,QAAA,uBAAuB,2BAkBlC","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"]}
|
|
@@ -2,7 +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.usePopoverTrigger = void 0;
|
|
5
|
-
var mergeProps = react_utilities_1.makeMergeProps({});
|
|
6
5
|
/**
|
|
7
6
|
* Create the state required to render PopoverTrigger.
|
|
8
7
|
*
|
|
@@ -19,9 +18,6 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
|
19
18
|
var openOnHover = popoverContext_1.usePopoverContext(function (context) { return context.openOnHover; });
|
|
20
19
|
var openOnContext = popoverContext_1.usePopoverContext(function (context) { return context.openOnContext; });
|
|
21
20
|
var triggerAttributes = react_tabster_1.useModalAttributes().triggerAttributes;
|
|
22
|
-
var state = mergeProps({
|
|
23
|
-
children: null,
|
|
24
|
-
}, defaultProps, props);
|
|
25
21
|
var onContextMenu = react_utilities_1.useEventCallback(function (e) {
|
|
26
22
|
var _a, _b;
|
|
27
23
|
if (openOnContext) {
|
|
@@ -62,13 +58,14 @@ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "@f
|
|
|
62
58
|
}
|
|
63
59
|
(_b = (_a = child.props) === null || _a === void 0 ? void 0 : _a.onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
64
60
|
});
|
|
65
|
-
var child = React.Children.only(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
var child = React.Children.only(props.children);
|
|
62
|
+
return {
|
|
63
|
+
children: React.cloneElement(child, tslib_1.__assign({ 'aria-haspopup': 'true', onClick: onClick,
|
|
64
|
+
onMouseEnter: onMouseEnter,
|
|
65
|
+
onKeyDown: onKeyDown,
|
|
66
|
+
onMouseLeave: onMouseLeave,
|
|
67
|
+
onContextMenu: onContextMenu, ref: react_utilities_1.useMergedRefs(child.ref, triggerRef) }, triggerAttributes)),
|
|
68
|
+
};
|
|
72
69
|
};
|
|
73
70
|
exports.usePopoverTrigger = usePopoverTrigger;
|
|
74
71
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopoverTrigger.js","sourceRoot":"../src/","sources":["components/PopoverTrigger/usePopoverTrigger.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"usePopoverTrigger.js","sourceRoot":"../src/","sources":["components/PopoverTrigger/usePopoverTrigger.ts"],"names":[],"mappings":";;;;IAMA;;;;;;;;OAQG;IACI,IAAM,iBAAiB,GAAG,UAC/B,KAA0B,EAC1B,YAAkC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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"]}
|
|
@@ -13,6 +13,8 @@ function isConformant(testInfo) {
|
|
|
13
13
|
var defaultOptions = {
|
|
14
14
|
asPropHandlesRef: true,
|
|
15
15
|
componentPath: module.parent.filename.replace('.test', ''),
|
|
16
|
+
// TODO // https://github.com/microsoft/fluentui/issues/19522
|
|
17
|
+
skipAsPropTests: true,
|
|
16
18
|
extraTests: react_conformance_make_styles_1.default
|
|
17
19
|
};
|
|
18
20
|
react_conformance_1.isConformant(defaultOptions, testInfo);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["common/isConformant.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,mBAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;;AAEA,IAAA,+BAAA,gBAAA,OAAA,CAAA,yCAAA,CAAA;;AAEA,SAAgB,YAAhB,CACE,QADF,EAC2F;AAEzF,MAAM,cAAc,GAAyC;AAC3D,IAAA,gBAAgB,EAAE,IADyC;AAE3D,IAAA,aAAa,EAAE,MAAO,CAAC,MAAR,CAAgB,QAAhB,CAAyB,OAAzB,CAAiC,OAAjC,EAA0C,EAA1C,CAF4C;AAG3D,IAAA,UAAU,EAAE,+BAAA,CAAA;
|
|
1
|
+
{"version":3,"sources":["common/isConformant.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,mBAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;;AAEA,IAAA,+BAAA,gBAAA,OAAA,CAAA,yCAAA,CAAA;;AAEA,SAAgB,YAAhB,CACE,QADF,EAC2F;AAEzF,MAAM,cAAc,GAAyC;AAC3D,IAAA,gBAAgB,EAAE,IADyC;AAE3D,IAAA,aAAa,EAAE,MAAO,CAAC,MAAR,CAAgB,QAAhB,CAAyB,OAAzB,CAAiC,OAAjC,EAA0C,EAA1C,CAF4C;AAG3D;AACA,IAAA,eAAe,EAAE,IAJ0C;AAK3D,IAAA,UAAU,EAAE,+BAAA,CAAA;AAL+C,GAA7D;AAQA,EAAA,mBAAA,CAAA,YAAA,CAAiB,cAAjB,EAAiC,QAAjC;AACD;;AAZD,OAAA,CAAA,YAAA,GAAA,YAAA","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"],"sourceRoot":"../src/"}
|
|
@@ -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
|
/**
|
|
@@ -18,12 +18,6 @@ var react_positioning_1 = /*#__PURE__*/require("@fluentui/react-positioning");
|
|
|
18
18
|
var react_portal_1 = /*#__PURE__*/require("@fluentui/react-portal");
|
|
19
19
|
|
|
20
20
|
var index_1 = /*#__PURE__*/require("../PopoverSurface/index");
|
|
21
|
-
/**
|
|
22
|
-
* Names of the shorthand properties in PopoverProps
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var mergeProps = /*#__PURE__*/react_utilities_1.makeMergeProps({});
|
|
27
21
|
/**
|
|
28
22
|
* Create the state required to render Popover.
|
|
29
23
|
*
|
|
@@ -34,63 +28,53 @@ var mergeProps = /*#__PURE__*/react_utilities_1.makeMergeProps({});
|
|
|
34
28
|
* @param defaultProps - (optional) default prop values provided by the implementing type
|
|
35
29
|
*/
|
|
36
30
|
|
|
37
|
-
var usePopover = function (props, defaultProps) {
|
|
38
|
-
var state = mergeProps({
|
|
39
|
-
size: 'medium',
|
|
40
|
-
open: undefined,
|
|
41
|
-
setOpen: function () {
|
|
42
|
-
return null;
|
|
43
|
-
},
|
|
44
|
-
triggerRef: {
|
|
45
|
-
current: null
|
|
46
|
-
},
|
|
47
|
-
contentRef: {
|
|
48
|
-
current: null
|
|
49
|
-
},
|
|
50
|
-
arrowRef: {
|
|
51
|
-
current: null
|
|
52
|
-
},
|
|
53
|
-
children: null,
|
|
54
|
-
setContextTarget: function () {
|
|
55
|
-
return null;
|
|
56
|
-
},
|
|
57
|
-
contextTarget: undefined
|
|
58
|
-
}, defaultProps, props);
|
|
59
31
|
|
|
60
|
-
|
|
32
|
+
var usePopover = function (props, defaultProps) {
|
|
33
|
+
var _a = react_positioning_1.usePopperMouseTarget(),
|
|
61
34
|
contextTarget = _a[0],
|
|
62
35
|
setContextTarget = _a[1];
|
|
63
36
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
37
|
+
var initialState = tslib_1.__assign({
|
|
38
|
+
size: 'medium',
|
|
39
|
+
contextTarget: contextTarget,
|
|
40
|
+
setContextTarget: setContextTarget
|
|
41
|
+
}, props);
|
|
42
|
+
|
|
43
|
+
var _b = useOpenState(initialState),
|
|
44
|
+
open = _b[0],
|
|
45
|
+
setOpen = _b[1];
|
|
46
|
+
|
|
47
|
+
var popperRefs = usePopoverRefs(initialState);
|
|
68
48
|
var targetDocument = react_shared_contexts_1.useFluent().targetDocument;
|
|
69
49
|
react_utilities_1.useOnClickOutside({
|
|
70
50
|
contains: react_portal_1.elementContains,
|
|
71
51
|
element: targetDocument,
|
|
72
52
|
callback: function (ev) {
|
|
73
|
-
return
|
|
53
|
+
return setOpen(ev, false);
|
|
74
54
|
},
|
|
75
|
-
refs: [
|
|
76
|
-
disabled: !
|
|
55
|
+
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
|
56
|
+
disabled: !open
|
|
77
57
|
});
|
|
78
58
|
react_utilities_1.useOnScrollOutside({
|
|
79
59
|
contains: react_portal_1.elementContains,
|
|
80
60
|
element: targetDocument,
|
|
81
61
|
callback: function (ev) {
|
|
82
|
-
return
|
|
62
|
+
return setOpen(ev, false);
|
|
83
63
|
},
|
|
84
|
-
refs: [
|
|
85
|
-
disabled: !
|
|
64
|
+
refs: [popperRefs.triggerRef, popperRefs.contentRef],
|
|
65
|
+
disabled: !open || !initialState.openOnContext
|
|
66
|
+
});
|
|
67
|
+
return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, initialState), popperRefs), {
|
|
68
|
+
open: open,
|
|
69
|
+
setOpen: setOpen,
|
|
70
|
+
setContextTarget: setContextTarget,
|
|
71
|
+
contextTarget: contextTarget
|
|
86
72
|
});
|
|
87
|
-
return state;
|
|
88
73
|
};
|
|
89
74
|
|
|
90
75
|
exports.usePopover = usePopover;
|
|
91
76
|
/**
|
|
92
77
|
* Creates and manages the Popover open state
|
|
93
|
-
* @param state Popover state
|
|
94
78
|
*/
|
|
95
79
|
|
|
96
80
|
function useOpenState(state) {
|
|
@@ -100,23 +84,26 @@ function useOpenState(state) {
|
|
|
100
84
|
return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
|
|
101
85
|
});
|
|
102
86
|
|
|
103
|
-
var _a = react_utilities_1.
|
|
87
|
+
var _a = react_utilities_1.useControllableState({
|
|
88
|
+
state: state.open,
|
|
89
|
+
defaultState: state.defaultOpen,
|
|
90
|
+
initialState: false
|
|
91
|
+
}),
|
|
104
92
|
open = _a[0],
|
|
105
|
-
|
|
93
|
+
setOpenState = _a[1];
|
|
106
94
|
|
|
107
95
|
state.open = open !== undefined ? open : state.open;
|
|
108
96
|
var setContextTarget = state.setContextTarget;
|
|
109
|
-
|
|
97
|
+
var setOpen = React.useCallback(function (e, shouldOpen) {
|
|
110
98
|
if (shouldOpen && e.type === 'contextmenu') {
|
|
111
|
-
|
|
112
|
-
setContextTarget(virtualElement);
|
|
99
|
+
setContextTarget(e);
|
|
113
100
|
}
|
|
114
101
|
|
|
115
102
|
if (!shouldOpen) {
|
|
116
103
|
setContextTarget(undefined);
|
|
117
104
|
}
|
|
118
105
|
|
|
119
|
-
|
|
106
|
+
setOpenState(function (prevOpen) {
|
|
120
107
|
// More than one event (mouse, focus, keyboard) can request the Popover to close
|
|
121
108
|
// We assume the first event is the correct one
|
|
122
109
|
if (prevOpen !== shouldOpen) {
|
|
@@ -127,12 +114,11 @@ function useOpenState(state) {
|
|
|
127
114
|
|
|
128
115
|
return shouldOpen;
|
|
129
116
|
});
|
|
130
|
-
}, [
|
|
131
|
-
return
|
|
117
|
+
}, [setOpenState, onOpenChange, setContextTarget]);
|
|
118
|
+
return [open, setOpen];
|
|
132
119
|
}
|
|
133
120
|
/**
|
|
134
121
|
* Creates and sets the necessary trigger, target and content refs used by Popover
|
|
135
|
-
* @param state Popover state
|
|
136
122
|
*/
|
|
137
123
|
|
|
138
124
|
|
|
@@ -157,9 +143,10 @@ function usePopoverRefs(state) {
|
|
|
157
143
|
contentRef = _a.containerRef,
|
|
158
144
|
arrowRef = _a.arrowRef;
|
|
159
145
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
146
|
+
return {
|
|
147
|
+
triggerRef: triggerRef,
|
|
148
|
+
contentRef: contentRef,
|
|
149
|
+
arrowRef: arrowRef
|
|
150
|
+
};
|
|
164
151
|
}
|
|
165
152
|
//# sourceMappingURL=usePopover.js.map
|