@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.
- package/.swcrc +30 -0
- package/CHANGELOG.json +80 -17
- package/CHANGELOG.md +28 -11
- package/lib/Tooltip.js.map +1 -1
- package/lib/components/Tooltip/Tooltip.js +1 -0
- package/lib/components/Tooltip/Tooltip.js.map +1 -1
- package/lib/components/Tooltip/Tooltip.types.js +1 -1
- package/lib/components/Tooltip/Tooltip.types.js.map +1 -1
- package/lib/components/Tooltip/index.js.map +1 -1
- package/lib/components/Tooltip/private/constants.js +1 -2
- package/lib/components/Tooltip/private/constants.js.map +1 -1
- package/lib/components/Tooltip/renderTooltip.js +1 -3
- package/lib/components/Tooltip/renderTooltip.js.map +1 -1
- package/lib/components/Tooltip/useTooltip.js +7 -7
- package/lib/components/Tooltip/useTooltip.js.map +1 -1
- package/lib/components/Tooltip/useTooltipStyles.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/Tooltip.js +5 -4
- package/lib-commonjs/Tooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/Tooltip.js +20 -21
- package/lib-commonjs/components/Tooltip/Tooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/Tooltip.types.js +5 -2
- package/lib-commonjs/components/Tooltip/Tooltip.types.js.map +1 -1
- package/lib-commonjs/components/Tooltip/index.js +9 -8
- package/lib-commonjs/components/Tooltip/index.js.map +1 -1
- package/lib-commonjs/components/Tooltip/private/constants.js +17 -16
- package/lib-commonjs/components/Tooltip/private/constants.js.map +1 -1
- package/lib-commonjs/components/Tooltip/renderTooltip.js +19 -24
- package/lib-commonjs/components/Tooltip/renderTooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/useTooltip.js +191 -194
- package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/useTooltipStyles.js +200 -92
- package/lib-commonjs/components/Tooltip/useTooltipStyles.js.map +1 -1
- package/lib-commonjs/index.js +16 -33
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +10 -10
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
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
|
-
|
3
|
+
value: true
|
5
4
|
});
|
6
|
-
const
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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,"
|
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
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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,"
|
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
|
-
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "renderTooltip_unstable", {
|
6
|
+
enumerable: true,
|
7
|
+
get: ()=>renderTooltip_unstable
|
5
8
|
});
|
6
|
-
|
7
|
-
const
|
8
|
-
const
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
*/
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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,"
|
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
|
-
|
3
|
+
value: true
|
5
4
|
});
|
6
|
-
exports
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
const
|
11
|
-
const
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
const
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
158
|
-
|
159
|
-
|
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
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|