@fluentui/react-tooltip 0.0.0-nightly-20230321-0440.1 → 0.0.0-nightly-20230324-0422.1

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.
Files changed (36) hide show
  1. package/.swcrc +30 -0
  2. package/CHANGELOG.json +80 -17
  3. package/CHANGELOG.md +28 -11
  4. package/lib/Tooltip.js.map +1 -1
  5. package/lib/components/Tooltip/Tooltip.js +1 -0
  6. package/lib/components/Tooltip/Tooltip.js.map +1 -1
  7. package/lib/components/Tooltip/Tooltip.types.js +1 -1
  8. package/lib/components/Tooltip/Tooltip.types.js.map +1 -1
  9. package/lib/components/Tooltip/index.js.map +1 -1
  10. package/lib/components/Tooltip/private/constants.js +1 -2
  11. package/lib/components/Tooltip/private/constants.js.map +1 -1
  12. package/lib/components/Tooltip/renderTooltip.js +1 -3
  13. package/lib/components/Tooltip/renderTooltip.js.map +1 -1
  14. package/lib/components/Tooltip/useTooltip.js +7 -7
  15. package/lib/components/Tooltip/useTooltip.js.map +1 -1
  16. package/lib/components/Tooltip/useTooltipStyles.js.map +1 -1
  17. package/lib/index.js.map +1 -1
  18. package/lib-commonjs/Tooltip.js +5 -4
  19. package/lib-commonjs/Tooltip.js.map +1 -1
  20. package/lib-commonjs/components/Tooltip/Tooltip.js +20 -21
  21. package/lib-commonjs/components/Tooltip/Tooltip.js.map +1 -1
  22. package/lib-commonjs/components/Tooltip/Tooltip.types.js +5 -2
  23. package/lib-commonjs/components/Tooltip/Tooltip.types.js.map +1 -1
  24. package/lib-commonjs/components/Tooltip/index.js +9 -8
  25. package/lib-commonjs/components/Tooltip/index.js.map +1 -1
  26. package/lib-commonjs/components/Tooltip/private/constants.js +17 -16
  27. package/lib-commonjs/components/Tooltip/private/constants.js.map +1 -1
  28. package/lib-commonjs/components/Tooltip/renderTooltip.js +19 -24
  29. package/lib-commonjs/components/Tooltip/renderTooltip.js.map +1 -1
  30. package/lib-commonjs/components/Tooltip/useTooltip.js +191 -194
  31. package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -1
  32. package/lib-commonjs/components/Tooltip/useTooltipStyles.js +200 -92
  33. package/lib-commonjs/components/Tooltip/useTooltipStyles.js.map +1 -1
  34. package/lib-commonjs/index.js +16 -33
  35. package/lib-commonjs/index.js.map +1 -1
  36. package/package.json +10 -10
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComponentProps, ComponentState, Slot, TriggerProps } from '@fluentui/react-utilities';\nimport type { PortalProps } from '@fluentui/react-portal';\n\n/**\n * Slot properties for Tooltip\n */\nexport type TooltipSlots = {\n /**\n * The text or JSX content of the tooltip.\n */\n content: NonNullable<Slot<'div'>>;\n};\n\n/**\n * The properties that are added to the child of the Tooltip\n */\nexport type TooltipChildProps = {\n ref?: React.Ref<unknown>;\n} & Pick<\n React.HTMLAttributes<HTMLElement>,\n 'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'onBlur' | 'onFocus' | 'onPointerEnter' | 'onPointerLeave'\n>;\n\n/**\n * Data for the Tooltip's onVisibleChange event.\n */\nexport type OnVisibleChangeData = {\n visible: boolean;\n};\n\n/**\n * Properties for Tooltip\n */\nexport type TooltipProps = ComponentProps<TooltipSlots> &\n TriggerProps<TooltipChildProps> &\n Pick<PortalProps, 'mountNode'> & {\n /**\n * The tooltip's visual appearance.\n * * `normal` - Uses the theme's background and text colors.\n * * `inverted` - Higher contrast variant that uses the theme's inverted colors.\n *\n * @default normal\n */\n appearance?: 'normal' | 'inverted';\n /**\n * Delay before the tooltip is hidden, in milliseconds.\n *\n * @default 250\n */\n hideDelay?: number;\n\n /**\n * Notification when the visibility of the tooltip is changing\n */\n onVisibleChange?: (\n event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined,\n data: OnVisibleChangeData,\n ) => void;\n\n /**\n * Configure the positioning of the tooltip\n *\n * @default above\n */\n positioning?: PositioningShorthand;\n\n /**\n * (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.\n *\n * * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons\n * displaying only an icon, for example.\n * * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.\n * * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to\n * screen readers, and should only be used if the tooltip's text is available by some other means.\n */\n relationship: 'label' | 'description' | 'inaccessible';\n\n /**\n * Delay before the tooltip is shown, in milliseconds.\n *\n * @default 250\n */\n showDelay?: number;\n\n /**\n * Control the tooltip's visibility programatically.\n *\n * This can be used in conjunction with onVisibleChange to modify the tooltip's show and hide behavior.\n *\n * If not provided, the visibility will be controlled by the tooltip itself, based on hover and focus events on the\n * trigger (child) element.\n *\n * @default false\n */\n visible?: boolean;\n\n /**\n * Render an arrow pointing to the target element\n *\n * @default false\n */\n withArrow?: boolean;\n };\n\n/**\n * State used in rendering Tooltip\n */\nexport type TooltipState = ComponentState<TooltipSlots> &\n Pick<TooltipProps, 'mountNode' | 'relationship'> &\n Required<Pick<TooltipProps, 'appearance' | 'hideDelay' | 'positioning' | 'showDelay' | 'visible' | 'withArrow'>> & {\n children?: React.ReactElement | null;\n\n /**\n * Whether the tooltip should be rendered to the DOM.\n */\n shouldRenderTooltip?: boolean;\n\n /**\n * Ref to the arrow element\n */\n arrowRef?: React.Ref<HTMLDivElement>;\n\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"],"mappings":""}
1
+ {"version":3,"sources":["../../../lib/components/Tooltip/Tooltip.types.js"],"sourcesContent":["import * as React from 'react';\n//# sourceMappingURL=Tooltip.types.js.map"],"names":[],"mappings":";;;;;6DAAuB;CACvB,yCAAyC"}
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- const tslib_1 = /*#__PURE__*/require("tslib");
7
- tslib_1.__exportStar(require("./Tooltip"), exports);
8
- tslib_1.__exportStar(require("./Tooltip.types"), exports);
9
- tslib_1.__exportStar(require("./renderTooltip"), exports);
10
- tslib_1.__exportStar(require("./useTooltip"), exports);
11
- tslib_1.__exportStar(require("./useTooltipStyles"), exports);
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./Tooltip"), exports);
7
+ _exportStar(require("./Tooltip.types"), exports);
8
+ _exportStar(require("./renderTooltip"), exports);
9
+ _exportStar(require("./useTooltip"), exports);
10
+ _exportStar(require("./useTooltipStyles"), exports);
11
+ //# sourceMappingURL=index.js.map
12
+
12
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["tslib_1","__exportStar","require","exports"],"sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/index.ts"],"sourcesContent":["export * from './Tooltip';\nexport * from './Tooltip.types';\nexport * from './renderTooltip';\nexport * from './useTooltip';\nexport * from './useTooltipStyles';\n"],"mappings":";;;;;;AAAAA,OAAA,CAAAC,YAAA,CAAAC,OAAA,eAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,qBAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,qBAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,kBAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,wBAAAC,OAAA"}
1
+ {"version":3,"sources":["../../../lib/components/Tooltip/index.js"],"sourcesContent":["export * from './Tooltip';\nexport * from './Tooltip.types';\nexport * from './renderTooltip';\nexport * from './useTooltip';\nexport * from './useTooltipStyles';\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;oBAAc;oBACA;oBACA;oBACA;oBACA;CACd,iCAAiC"}
@@ -1,19 +1,20 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.tooltipBorderRadius = exports.arrowHeight = void 0;
7
1
  /**
8
2
  * The height of the tooltip's arrow in pixels.
9
- */
10
- exports.arrowHeight = 6;
11
- /**
12
- * The default value of the tooltip's border radius (borderRadiusMedium).
13
- *
14
- * Unfortunately, Popper requires it to be specified as a variable instead of using CSS.
15
- * While we could use getComputedStyle, that adds a performance penalty for something that
16
- * will likely never change.
17
- */
18
- exports.tooltipBorderRadius = 4;
3
+ */ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ function _export(target, all) {
8
+ for(var name in all)Object.defineProperty(target, name, {
9
+ enumerable: true,
10
+ get: all[name]
11
+ });
12
+ }
13
+ _export(exports, {
14
+ arrowHeight: ()=>arrowHeight,
15
+ tooltipBorderRadius: ()=>tooltipBorderRadius
16
+ });
17
+ const arrowHeight = 6;
18
+ const tooltipBorderRadius = 4; //# sourceMappingURL=constants.js.map
19
+
19
20
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["exports","arrowHeight","tooltipBorderRadius"],"sources":["../../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/private/constants.ts"],"sourcesContent":["/**\n * The height of the tooltip's arrow in pixels.\n */\nexport const arrowHeight = 6;\n\n/**\n * The default value of the tooltip's border radius (borderRadiusMedium).\n *\n * Unfortunately, Popper requires it to be specified as a variable instead of using CSS.\n * While we could use getComputedStyle, that adds a performance penalty for something that\n * will likely never change.\n */\nexport const tooltipBorderRadius = 4;\n"],"mappings":";;;;;;AAAA;;;AAGaA,OAAA,CAAAC,WAAW,GAAG,CAAC;AAE5B;;;;;;;AAOaD,OAAA,CAAAE,mBAAmB,GAAG,CAAC"}
1
+ {"version":3,"sources":["../../../../lib/components/Tooltip/private/constants.js"],"sourcesContent":["/**\n * The height of the tooltip's arrow in pixels.\n */export const arrowHeight = 6;\n/**\n * The default value of the tooltip's border radius (borderRadiusMedium).\n *\n * Unfortunately, Popper requires it to be specified as a variable instead of using CSS.\n * While we could use getComputedStyle, that adds a performance penalty for something that\n * will likely never change.\n */\nexport const tooltipBorderRadius = 4;\n//# sourceMappingURL=constants.js.map"],"names":["arrowHeight","tooltipBorderRadius"],"mappings":"AAAA;;CAEC;;;;;;;;;;;IAAeA,WAAW,MAAXA;IAQHC,mBAAmB,MAAnBA;;AARH,MAAMD,cAAc;AAQvB,MAAMC,sBAAsB,GACnC,qCAAqC"}
@@ -1,28 +1,23 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "renderTooltip_unstable", {
6
+ enumerable: true,
7
+ get: ()=>renderTooltip_unstable
5
8
  });
6
- exports.renderTooltip_unstable = void 0;
7
- const React = /*#__PURE__*/require("react");
8
- const react_portal_1 = /*#__PURE__*/require("@fluentui/react-portal");
9
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
10
- /**
11
- * Render the final JSX of Tooltip
12
- */
13
- const renderTooltip_unstable = state => {
14
- const {
15
- slots,
16
- slotProps
17
- } = react_utilities_1.getSlots(state);
18
- return React.createElement(React.Fragment, null, state.children, state.shouldRenderTooltip && React.createElement(react_portal_1.Portal, {
19
- mountNode: state.mountNode
20
- }, React.createElement(slots.content, {
21
- ...slotProps.content
22
- }, state.withArrow && React.createElement("div", {
23
- ref: state.arrowRef,
24
- className: state.arrowClassName
25
- }), state.content.children)));
26
- };
27
- exports.renderTooltip_unstable = renderTooltip_unstable;
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _reactPortal = require("@fluentui/react-portal");
12
+ const _reactUtilities = require("@fluentui/react-utilities");
13
+ const renderTooltip_unstable = (state)=>{
14
+ const { slots , slotProps } = (0, _reactUtilities.getSlots)(state);
15
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, null, state.children, state.shouldRenderTooltip && /*#__PURE__*/ _react.createElement(_reactPortal.Portal, {
16
+ mountNode: state.mountNode
17
+ }, /*#__PURE__*/ _react.createElement(slots.content, slotProps.content, state.withArrow && /*#__PURE__*/ _react.createElement("div", {
18
+ ref: state.arrowRef,
19
+ className: state.arrowClassName
20
+ }), state.content.children)));
21
+ }; //# sourceMappingURL=renderTooltip.js.map
22
+
28
23
  //# sourceMappingURL=renderTooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","require","react_portal_1","react_utilities_1","renderTooltip_unstable","state","slots","slotProps","getSlots","createElement","Fragment","children","shouldRenderTooltip","Portal","mountNode","content","withArrow","ref","arrowRef","className","arrowClassName","exports"],"sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/renderTooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Portal } from '@fluentui/react-portal';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { TooltipSlots, TooltipState } from './Tooltip.types';\n\n/**\n * Render the final JSX of Tooltip\n */\nexport const renderTooltip_unstable = (state: TooltipState) => {\n const { slots, slotProps } = getSlots<TooltipSlots>(state);\n\n return (\n <>\n {state.children}\n {state.shouldRenderTooltip && (\n <Portal mountNode={state.mountNode}>\n <slots.content {...slotProps.content}>\n {state.withArrow && <div ref={state.arrowRef} className={state.arrowClassName} />}\n {state.content.children}\n </slots.content>\n </Portal>\n )}\n </>\n );\n};\n"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AACA,MAAAC,cAAA,gBAAAD,OAAA;AACA,MAAAE,iBAAA,gBAAAF,OAAA;AAGA;;;AAGO,MAAMG,sBAAsB,GAAIC,KAAmB,IAAI;EAC5D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,iBAAA,CAAAK,QAAQ,CAAeH,KAAK,CAAC;EAE1D,OACEL,KAAA,CAAAS,aAAA,CAAAT,KAAA,CAAAU,QAAA,QACGL,KAAK,CAACM,QAAQ,EACdN,KAAK,CAACO,mBAAmB,IACxBZ,KAAA,CAAAS,aAAA,CAACP,cAAA,CAAAW,MAAM;IAACC,SAAS,EAAET,KAAK,CAACS;EAAS,GAChCd,KAAA,CAAAS,aAAA,CAACH,KAAK,CAACS,OAAO;IAAA,GAAKR,SAAS,CAACQ;EAAO,GACjCV,KAAK,CAACW,SAAS,IAAIhB,KAAA,CAAAS,aAAA;IAAKQ,GAAG,EAAEZ,KAAK,CAACa,QAAQ;IAAEC,SAAS,EAAEd,KAAK,CAACe;EAAc,EAAI,EAChFf,KAAK,CAACU,OAAO,CAACJ,QAAQ,CACT,CAEnB,CACA;AAEP,CAAC;AAhBYU,OAAA,CAAAjB,sBAAsB,GAAAA,sBAAA"}
1
+ {"version":3,"sources":["../../../lib/components/Tooltip/renderTooltip.js"],"sourcesContent":["import * as React from 'react';\nimport { Portal } from '@fluentui/react-portal';\nimport { getSlots } from '@fluentui/react-utilities';\n/**\n * Render the final JSX of Tooltip\n */\nexport const renderTooltip_unstable = state => {\n const {\n slots,\n slotProps\n } = getSlots(state);\n return /*#__PURE__*/React.createElement(React.Fragment, null, state.children, state.shouldRenderTooltip && /*#__PURE__*/React.createElement(Portal, {\n mountNode: state.mountNode\n }, /*#__PURE__*/React.createElement(slots.content, slotProps.content, state.withArrow && /*#__PURE__*/React.createElement(\"div\", {\n ref: state.arrowRef,\n className: state.arrowClassName\n }), state.content.children)));\n};\n//# sourceMappingURL=renderTooltip.js.map"],"names":["renderTooltip_unstable","state","slots","slotProps","getSlots","React","createElement","Fragment","children","shouldRenderTooltip","Portal","mountNode","content","withArrow","ref","arrowRef","className","arrowClassName"],"mappings":";;;;+BAMaA;;aAAAA;;;6DANU;6BACA;gCACE;AAIlB,MAAMA,yBAAyBC,CAAAA,QAAS;IAC7C,MAAM,EACJC,MAAK,EACLC,UAAS,EACV,GAAGC,IAAAA,wBAAQ,EAACH;IACb,OAAO,WAAW,GAAEI,OAAMC,aAAa,CAACD,OAAME,QAAQ,EAAE,IAAI,EAAEN,MAAMO,QAAQ,EAAEP,MAAMQ,mBAAmB,IAAI,WAAW,GAAEJ,OAAMC,aAAa,CAACI,mBAAM,EAAE;QAClJC,WAAWV,MAAMU,SAAS;IAC5B,GAAG,WAAW,GAAEN,OAAMC,aAAa,CAACJ,MAAMU,OAAO,EAAET,UAAUS,OAAO,EAAEX,MAAMY,SAAS,IAAI,WAAW,GAAER,OAAMC,aAAa,CAAC,OAAO;QAC/HQ,KAAKb,MAAMc,QAAQ;QACnBC,WAAWf,MAAMgB,cAAc;IACjC,IAAIhB,MAAMW,OAAO,CAACJ,QAAQ;AAC5B,GACA,yCAAyC"}
@@ -1,203 +1,200 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.useTooltip_unstable = void 0;
7
- const React = /*#__PURE__*/require("react");
8
- const react_positioning_1 = /*#__PURE__*/require("@fluentui/react-positioning");
9
- const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
10
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
- const constants_1 = /*#__PURE__*/require("./private/constants");
12
- const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
13
- /**
14
- * Create the state required to render Tooltip.
15
- *
16
- * The returned state can be modified with hooks such as useTooltipStyles_unstable,
17
- * before being passed to renderTooltip_unstable.
18
- *
19
- * @param props - props from this instance of Tooltip
20
- */
21
- const useTooltip_unstable = props => {
22
- var _a, _b, _c, _d;
23
- const context = react_shared_contexts_1.useTooltipVisibility_unstable();
24
- const isServerSideRender = react_utilities_1.useIsSSR();
25
- const {
26
- targetDocument
27
- } = react_shared_contexts_1.useFluent_unstable();
28
- const [setDelayTimeout, clearDelayTimeout] = react_utilities_1.useTimeout();
29
- const {
30
- appearance = 'normal',
31
- children,
32
- content,
33
- withArrow = false,
34
- positioning = 'above',
35
- onVisibleChange,
36
- relationship,
37
- showDelay = 250,
38
- hideDelay = 250,
39
- mountNode
40
- } = props;
41
- const [visible, setVisibleInternal] = react_utilities_1.useControllableState({
42
- state: props.visible,
43
- initialState: false
44
- });
45
- const setVisible = React.useCallback((newVisible, ev) => {
46
- clearDelayTimeout();
47
- setVisibleInternal(oldVisible => {
48
- if (newVisible !== oldVisible) {
49
- onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, {
50
- visible: newVisible
51
- });
52
- }
53
- return newVisible;
5
+ Object.defineProperty(exports, "useTooltip_unstable", {
6
+ enumerable: true,
7
+ get: ()=>useTooltip_unstable
8
+ });
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _reactPositioning = require("@fluentui/react-positioning");
12
+ const _reactSharedContexts = require("@fluentui/react-shared-contexts");
13
+ const _reactUtilities = require("@fluentui/react-utilities");
14
+ const _constants = require("./private/constants");
15
+ const _keyboardKeys = require("@fluentui/keyboard-keys");
16
+ const useTooltip_unstable = (props)=>{
17
+ var _child_props, _child_props1, _child_props2, _child_props3;
18
+ const context = (0, _reactSharedContexts.useTooltipVisibility_unstable)();
19
+ const isServerSideRender = (0, _reactUtilities.useIsSSR)();
20
+ const { targetDocument } = (0, _reactSharedContexts.useFluent_unstable)();
21
+ const [setDelayTimeout, clearDelayTimeout] = (0, _reactUtilities.useTimeout)();
22
+ const { appearance ='normal' , children , content , withArrow =false , positioning ='above' , onVisibleChange , relationship , showDelay =250 , hideDelay =250 , mountNode } = props;
23
+ const [visible, setVisibleInternal] = (0, _reactUtilities.useControllableState)({
24
+ state: props.visible,
25
+ initialState: false
54
26
  });
55
- }, [clearDelayTimeout, setVisibleInternal, onVisibleChange]);
56
- const state = {
57
- withArrow,
58
- positioning,
59
- showDelay,
60
- hideDelay,
61
- relationship,
62
- visible,
63
- shouldRenderTooltip: visible,
64
- appearance,
65
- mountNode,
66
- // Slots
67
- components: {
68
- content: 'div'
69
- },
70
- content: react_utilities_1.resolveShorthand(content, {
71
- defaultProps: {
72
- role: 'tooltip'
73
- },
74
- required: true
75
- })
76
- };
77
- state.content.id = react_utilities_1.useId('tooltip-', state.content.id);
78
- const positioningOptions = {
79
- enabled: state.visible,
80
- arrowPadding: 2 * constants_1.tooltipBorderRadius,
81
- position: 'above',
82
- align: 'center',
83
- offset: 4,
84
- ...react_positioning_1.resolvePositioningShorthand(state.positioning)
85
- };
86
- if (state.withArrow) {
87
- positioningOptions.offset = react_positioning_1.mergeArrowOffset(positioningOptions.offset, constants_1.arrowHeight);
88
- }
89
- const {
90
- targetRef,
91
- containerRef,
92
- arrowRef
93
- } = react_positioning_1.usePositioning(positioningOptions);
94
- state.content.ref = react_utilities_1.useMergedRefs(state.content.ref, containerRef);
95
- state.arrowRef = arrowRef;
96
- // When this tooltip is visible, hide any other tooltips, and register it
97
- // as the visibleTooltip with the TooltipContext.
98
- // Also add a listener on document to hide the tooltip if Escape is pressed
99
- react_utilities_1.useIsomorphicLayoutEffect(() => {
100
- var _a;
101
- if (visible) {
102
- const thisTooltip = {
103
- hide: () => setVisible(false)
104
- };
105
- (_a = context.visibleTooltip) === null || _a === void 0 ? void 0 : _a.hide();
106
- context.visibleTooltip = thisTooltip;
107
- const onDocumentKeyDown = ev => {
108
- if (ev.key === keyboard_keys_1.Escape) {
109
- thisTooltip.hide();
110
- // stop propagation to avoid conflicting with other elements that listen for `Escape`
111
- // e,g: Dialog, Popover, Menu
112
- ev.stopPropagation();
113
- }
114
- };
115
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown, {
116
- // As this event is added at targeted document,
117
- // we need to capture the event to be sure keydown handling from tooltip happens first
118
- capture: true
119
- });
120
- return () => {
121
- if (context.visibleTooltip === thisTooltip) {
122
- context.visibleTooltip = undefined;
123
- }
124
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown, {
125
- capture: true
27
+ const setVisible = _react.useCallback((newVisible, ev)=>{
28
+ clearDelayTimeout();
29
+ setVisibleInternal((oldVisible)=>{
30
+ if (newVisible !== oldVisible) {
31
+ onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, {
32
+ visible: newVisible
33
+ });
34
+ }
35
+ return newVisible;
126
36
  });
127
- };
128
- }
129
- }, [context, targetDocument, visible, setVisible]);
130
- // The focused element gets a blur event when the document loses focus
131
- // (e.g. switching tabs in the browser), but we don't want to show the
132
- // tooltip again when the document gets focus back. Handle this case by
133
- // checking if the blurred element is still the document's activeElement.
134
- // See https://github.com/microsoft/fluentui/issues/13541
135
- const ignoreNextFocusEventRef = React.useRef(false);
136
- // Listener for onPointerEnter and onFocus on the trigger element
137
- const onEnterTrigger = React.useCallback(ev => {
138
- if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {
139
- ignoreNextFocusEventRef.current = false;
140
- return;
37
+ }, [
38
+ clearDelayTimeout,
39
+ setVisibleInternal,
40
+ onVisibleChange
41
+ ]);
42
+ const state = {
43
+ withArrow,
44
+ positioning,
45
+ showDelay,
46
+ hideDelay,
47
+ relationship,
48
+ visible,
49
+ shouldRenderTooltip: visible,
50
+ appearance,
51
+ mountNode,
52
+ // Slots
53
+ components: {
54
+ content: 'div'
55
+ },
56
+ content: (0, _reactUtilities.resolveShorthand)(content, {
57
+ defaultProps: {
58
+ role: 'tooltip'
59
+ },
60
+ required: true
61
+ })
62
+ };
63
+ state.content.id = (0, _reactUtilities.useId)('tooltip-', state.content.id);
64
+ const positioningOptions = {
65
+ enabled: state.visible,
66
+ arrowPadding: 2 * _constants.tooltipBorderRadius,
67
+ position: 'above',
68
+ align: 'center',
69
+ offset: 4,
70
+ ...(0, _reactPositioning.resolvePositioningShorthand)(state.positioning)
71
+ };
72
+ if (state.withArrow) {
73
+ positioningOptions.offset = (0, _reactPositioning.mergeArrowOffset)(positioningOptions.offset, _constants.arrowHeight);
141
74
  }
142
- // Show immediately if another tooltip is already visible
143
- const delay = context.visibleTooltip ? 0 : state.showDelay;
144
- setDelayTimeout(() => {
145
- setVisible(true, ev);
146
- }, delay);
147
- ev.persist(); // Persist the event since the setVisible call will happen asynchronously
148
- }, [setDelayTimeout, setVisible, state.showDelay, context]);
149
- // Listener for onPointerLeave and onBlur on the trigger element
150
- const onLeaveTrigger = React.useCallback(ev => {
151
- let delay = state.hideDelay;
152
- if (ev.type === 'blur') {
153
- // Hide immediately when losing focus
154
- delay = 0;
155
- ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
75
+ const { targetRef , containerRef , arrowRef } = (0, _reactPositioning.usePositioning)(positioningOptions);
76
+ state.content.ref = (0, _reactUtilities.useMergedRefs)(state.content.ref, containerRef);
77
+ state.arrowRef = arrowRef;
78
+ // When this tooltip is visible, hide any other tooltips, and register it
79
+ // as the visibleTooltip with the TooltipContext.
80
+ // Also add a listener on document to hide the tooltip if Escape is pressed
81
+ (0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
82
+ if (visible) {
83
+ var _context_visibleTooltip;
84
+ const thisTooltip = {
85
+ hide: ()=>setVisible(false)
86
+ };
87
+ (_context_visibleTooltip = context.visibleTooltip) === null || _context_visibleTooltip === void 0 ? void 0 : _context_visibleTooltip.hide();
88
+ context.visibleTooltip = thisTooltip;
89
+ const onDocumentKeyDown = (ev)=>{
90
+ if (ev.key === _keyboardKeys.Escape) {
91
+ thisTooltip.hide();
92
+ // stop propagation to avoid conflicting with other elements that listen for `Escape`
93
+ // e,g: Dialog, Popover, Menu
94
+ ev.stopPropagation();
95
+ }
96
+ };
97
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown, {
98
+ // As this event is added at targeted document,
99
+ // we need to capture the event to be sure keydown handling from tooltip happens first
100
+ capture: true
101
+ });
102
+ return ()=>{
103
+ if (context.visibleTooltip === thisTooltip) {
104
+ context.visibleTooltip = undefined;
105
+ }
106
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown, {
107
+ capture: true
108
+ });
109
+ };
110
+ }
111
+ }, [
112
+ context,
113
+ targetDocument,
114
+ visible,
115
+ setVisible
116
+ ]);
117
+ // The focused element gets a blur event when the document loses focus
118
+ // (e.g. switching tabs in the browser), but we don't want to show the
119
+ // tooltip again when the document gets focus back. Handle this case by
120
+ // checking if the blurred element is still the document's activeElement.
121
+ // See https://github.com/microsoft/fluentui/issues/13541
122
+ const ignoreNextFocusEventRef = _react.useRef(false);
123
+ // Listener for onPointerEnter and onFocus on the trigger element
124
+ const onEnterTrigger = _react.useCallback((ev)=>{
125
+ if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {
126
+ ignoreNextFocusEventRef.current = false;
127
+ return;
128
+ }
129
+ // Show immediately if another tooltip is already visible
130
+ const delay = context.visibleTooltip ? 0 : state.showDelay;
131
+ setDelayTimeout(()=>{
132
+ setVisible(true, ev);
133
+ }, delay);
134
+ ev.persist(); // Persist the event since the setVisible call will happen asynchronously
135
+ }, [
136
+ setDelayTimeout,
137
+ setVisible,
138
+ state.showDelay,
139
+ context
140
+ ]);
141
+ // Listener for onPointerLeave and onBlur on the trigger element
142
+ const onLeaveTrigger = _react.useCallback((ev)=>{
143
+ let delay = state.hideDelay;
144
+ if (ev.type === 'blur') {
145
+ // Hide immediately when losing focus
146
+ delay = 0;
147
+ ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
148
+ }
149
+ setDelayTimeout(()=>{
150
+ setVisible(false, ev);
151
+ }, delay);
152
+ ev.persist(); // Persist the event since the setVisible call will happen asynchronously
153
+ }, [
154
+ setDelayTimeout,
155
+ setVisible,
156
+ state.hideDelay,
157
+ targetDocument
158
+ ]);
159
+ // Cancel the hide timer when the mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.
160
+ // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.
161
+ state.content.onPointerEnter = (0, _reactUtilities.mergeCallbacks)(state.content.onPointerEnter, clearDelayTimeout);
162
+ state.content.onPointerLeave = (0, _reactUtilities.mergeCallbacks)(state.content.onPointerLeave, onLeaveTrigger);
163
+ state.content.onFocus = (0, _reactUtilities.mergeCallbacks)(state.content.onFocus, clearDelayTimeout);
164
+ state.content.onBlur = (0, _reactUtilities.mergeCallbacks)(state.content.onBlur, onLeaveTrigger);
165
+ const child = (0, _reactUtilities.getTriggerChild)(children);
166
+ const triggerAriaProps = {};
167
+ if (relationship === 'label') {
168
+ // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.
169
+ if (typeof state.content.children === 'string') {
170
+ triggerAriaProps['aria-label'] = state.content.children;
171
+ } else {
172
+ triggerAriaProps['aria-labelledby'] = state.content.id;
173
+ // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element
174
+ state.shouldRenderTooltip = true;
175
+ }
176
+ } else if (relationship === 'description') {
177
+ triggerAriaProps['aria-describedby'] = state.content.id;
178
+ // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element
179
+ state.shouldRenderTooltip = true;
156
180
  }
157
- setDelayTimeout(() => {
158
- setVisible(false, ev);
159
- }, delay);
160
- ev.persist(); // Persist the event since the setVisible call will happen asynchronously
161
- }, [setDelayTimeout, setVisible, state.hideDelay, targetDocument]);
162
- // Cancel the hide timer when the mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.
163
- // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.
164
- state.content.onPointerEnter = react_utilities_1.mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);
165
- state.content.onPointerLeave = react_utilities_1.mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);
166
- state.content.onFocus = react_utilities_1.mergeCallbacks(state.content.onFocus, clearDelayTimeout);
167
- state.content.onBlur = react_utilities_1.mergeCallbacks(state.content.onBlur, onLeaveTrigger);
168
- const child = react_utilities_1.getTriggerChild(children);
169
- const triggerAriaProps = {};
170
- if (relationship === 'label') {
171
- // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.
172
- if (typeof state.content.children === 'string') {
173
- triggerAriaProps['aria-label'] = state.content.children;
174
- } else {
175
- triggerAriaProps['aria-labelledby'] = state.content.id;
176
- // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element
177
- state.shouldRenderTooltip = true;
181
+ // Don't render the Tooltip in SSR to avoid hydration errors
182
+ if (isServerSideRender) {
183
+ state.shouldRenderTooltip = false;
178
184
  }
179
- } else if (relationship === 'description') {
180
- triggerAriaProps['aria-describedby'] = state.content.id;
181
- // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element
182
- state.shouldRenderTooltip = true;
183
- }
184
- // Don't render the Tooltip in SSR to avoid hydration errors
185
- if (isServerSideRender) {
186
- state.shouldRenderTooltip = false;
187
- }
188
- const childTargetRef = react_utilities_1.useMergedRefs(child === null || child === void 0 ? void 0 : child.ref, targetRef);
189
- // Apply the trigger props to the child, either by calling the render function, or cloning with the new props
190
- state.children = react_utilities_1.applyTriggerPropsToChildren(children, {
191
- ...triggerAriaProps,
192
- ...(child === null || child === void 0 ? void 0 : child.props),
193
- // If the target prop is not provided, attach targetRef to the trigger element's ref prop
194
- ref: positioningOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref,
195
- onPointerEnter: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.onPointerEnter, onEnterTrigger)),
196
- onPointerLeave: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.onPointerLeave, onLeaveTrigger)),
197
- onFocus: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c.onFocus, onEnterTrigger)),
198
- onBlur: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_d = child === null || child === void 0 ? void 0 : child.props) === null || _d === void 0 ? void 0 : _d.onBlur, onLeaveTrigger))
199
- });
200
- return state;
201
- };
202
- exports.useTooltip_unstable = useTooltip_unstable;
185
+ const childTargetRef = (0, _reactUtilities.useMergedRefs)(child === null || child === void 0 ? void 0 : child.ref, targetRef);
186
+ // Apply the trigger props to the child, either by calling the render function, or cloning with the new props
187
+ state.children = (0, _reactUtilities.applyTriggerPropsToChildren)(children, {
188
+ ...triggerAriaProps,
189
+ ...child === null || child === void 0 ? void 0 : child.props,
190
+ // If the target prop is not provided, attach targetRef to the trigger element's ref prop
191
+ ref: positioningOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref,
192
+ onPointerEnter: (0, _reactUtilities.useEventCallback)((0, _reactUtilities.mergeCallbacks)(child === null || child === void 0 ? void 0 : (_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.onPointerEnter, onEnterTrigger)),
193
+ onPointerLeave: (0, _reactUtilities.useEventCallback)((0, _reactUtilities.mergeCallbacks)(child === null || child === void 0 ? void 0 : (_child_props1 = child.props) === null || _child_props1 === void 0 ? void 0 : _child_props1.onPointerLeave, onLeaveTrigger)),
194
+ onFocus: (0, _reactUtilities.useEventCallback)((0, _reactUtilities.mergeCallbacks)(child === null || child === void 0 ? void 0 : (_child_props2 = child.props) === null || _child_props2 === void 0 ? void 0 : _child_props2.onFocus, onEnterTrigger)),
195
+ onBlur: (0, _reactUtilities.useEventCallback)((0, _reactUtilities.mergeCallbacks)(child === null || child === void 0 ? void 0 : (_child_props3 = child.props) === null || _child_props3 === void 0 ? void 0 : _child_props3.onBlur, onLeaveTrigger))
196
+ });
197
+ return state;
198
+ }; //# sourceMappingURL=useTooltip.js.map
199
+
203
200
  //# sourceMappingURL=useTooltip.js.map