@react-stately/tooltip 3.4.13-nightly.5042 → 3.5.0
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/dist/types.d.ts.map +1 -1
- package/dist/useTooltipTriggerState.main.js +4 -5
- package/dist/useTooltipTriggerState.main.js.map +1 -1
- package/dist/useTooltipTriggerState.mjs +4 -5
- package/dist/useTooltipTriggerState.module.js +4 -5
- package/dist/useTooltipTriggerState.module.js.map +1 -1
- package/package.json +5 -5
- package/src/useTooltipTriggerState.ts +13 -7
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAmBA;IACE,gDAAgD;IAChD,MAAM,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,yBAAyB;IACzB,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CACjC;AAQD;;;;GAIG;AACH,uCAAuC,KAAK,GAAE,mBAAwB,GAAG,mBAAmB,
|
|
1
|
+
{"mappings":";AAmBA;IACE,gDAAgD;IAChD,MAAM,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,yBAAyB;IACzB,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CACjC;AAQD;;;;GAIG;AACH,uCAAuC,KAAK,GAAE,mBAAwB,GAAG,mBAAmB,CA+G3F;AC5ID,YAAY,EAAC,mBAAmB,EAAC,MAAM,sBAAsB,CAAC","sources":["packages/@react-stately/tooltip/src/packages/@react-stately/tooltip/src/useTooltipTriggerState.ts","packages/@react-stately/tooltip/src/packages/@react-stately/tooltip/src/index.ts","packages/@react-stately/tooltip/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useTooltipTriggerState} from './useTooltipTriggerState';\n\nexport type {TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipTriggerState} from './useTooltipTriggerState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -30,7 +30,7 @@ function $3391baedd777a697$export$4d40659c25ecb50b(props = {}) {
|
|
|
30
30
|
let { delay: delay = $3391baedd777a697$var$TOOLTIP_DELAY, closeDelay: closeDelay = $3391baedd777a697$var$TOOLTIP_COOLDOWN } = props;
|
|
31
31
|
let { isOpen: isOpen, open: open, close: close } = (0, $w0mn6$reactstatelyoverlays.useOverlayTriggerState)(props);
|
|
32
32
|
let id = (0, $w0mn6$react.useMemo)(()=>`${++$3391baedd777a697$var$tooltipId}`, []);
|
|
33
|
-
let closeTimeout = (0, $w0mn6$react.useRef)(
|
|
33
|
+
let closeTimeout = (0, $w0mn6$react.useRef)(null);
|
|
34
34
|
let closeCallback = (0, $w0mn6$react.useRef)(close);
|
|
35
35
|
let ensureTooltipEntry = ()=>{
|
|
36
36
|
$3391baedd777a697$var$tooltips[id] = hideTooltip;
|
|
@@ -42,7 +42,7 @@ function $3391baedd777a697$export$4d40659c25ecb50b(props = {}) {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
let showTooltip = ()=>{
|
|
45
|
-
clearTimeout(closeTimeout.current);
|
|
45
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
46
46
|
closeTimeout.current = null;
|
|
47
47
|
closeOpenTooltips();
|
|
48
48
|
ensureTooltipEntry();
|
|
@@ -59,7 +59,7 @@ function $3391baedd777a697$export$4d40659c25ecb50b(props = {}) {
|
|
|
59
59
|
};
|
|
60
60
|
let hideTooltip = (immediate)=>{
|
|
61
61
|
if (immediate || closeDelay <= 0) {
|
|
62
|
-
clearTimeout(closeTimeout.current);
|
|
62
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
63
63
|
closeTimeout.current = null;
|
|
64
64
|
closeCallback.current();
|
|
65
65
|
} else if (!closeTimeout.current) closeTimeout.current = setTimeout(()=>{
|
|
@@ -94,10 +94,9 @@ function $3391baedd777a697$export$4d40659c25ecb50b(props = {}) {
|
|
|
94
94
|
}, [
|
|
95
95
|
close
|
|
96
96
|
]);
|
|
97
|
-
// eslint-disable-next-line arrow-body-style
|
|
98
97
|
(0, $w0mn6$react.useEffect)(()=>{
|
|
99
98
|
return ()=>{
|
|
100
|
-
clearTimeout(closeTimeout.current);
|
|
99
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
101
100
|
let tooltip = $3391baedd777a697$var$tooltips[id];
|
|
102
101
|
if (tooltip) delete $3391baedd777a697$var$tooltips[id];
|
|
103
102
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAMD,MAAM,sCAAgB,MAAM,yDAAyD;AACrF,MAAM,yCAAmB;AAezB,IAAI,iCAAW,CAAC;AAChB,IAAI,kCAAY;AAChB,IAAI,uCAAiB;AACrB,IAAI,
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAMD,MAAM,sCAAgB,MAAM,yDAAyD;AACrF,MAAM,yCAAmB;AAezB,IAAI,iCAAW,CAAC;AAChB,IAAI,kCAAY;AAChB,IAAI,uCAAiB;AACrB,IAAI,4CAA4D;AAChE,IAAI,8CAA8D;AAO3D,SAAS,0CAAuB,QAA6B,CAAC,CAAC;IACpE,IAAI,SAAC,QAAQ,iDAAe,aAAa,wCAAiB,GAAG;IAC7D,IAAI,UAAC,MAAM,QAAE,IAAI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AAC,sCACtC,4CAAsB,WAAW;YAC/B,4CAAsB;YACtB,uCAAiB;YACjB;QACF,GAAG;aACE,IAAI,CAAC,QACV;IAEJ;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,cAAc,OAAO,GAAG;IAC1B,GAAG;QAAC;KAAM;IAGV,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;YAEnC,IAAI,UAAU,8BAAQ,CAAC,GAAG;YAC1B,IAAI,SACF,OAAO,8BAAQ,CAAC,GAAG;QAEvB;IACF,GAAG;QAAC;KAAG;IAEP,OAAO;gBACL;QACA,MAAM,CAAC;YACL,IAAI,CAAC,aAAa,QAAQ,KAAK,CAAC,aAAa,OAAO,EAClD;iBAEA;QAEJ;QACA,OAAO;IACT;AACF","sources":["packages/@react-stately/tooltip/src/useTooltipTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {useEffect, useMemo, useRef} from 'react';\nimport {useOverlayTriggerState} from '@react-stately/overlays';\n\nconst TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design\nconst TOOLTIP_COOLDOWN = 500;\n\nexport interface TooltipTriggerState {\n /** Whether the tooltip is currently showing. */\n isOpen: boolean,\n /**\n * Shows the tooltip. By default, the tooltip becomes visible after a delay\n * depending on a global warmup timer. The `immediate` option shows the\n * tooltip immediately instead.\n */\n open(immediate?: boolean): void,\n /** Hides the tooltip. */\n close(immediate?: boolean): void\n}\n\nlet tooltips = {};\nlet tooltipId = 0;\nlet globalWarmedUp = false;\nlet globalWarmUpTimeout: ReturnType<typeof setTimeout> | null = null;\nlet globalCooldownTimeout: ReturnType<typeof setTimeout> | null = null;\n\n/**\n * Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides\n * methods to toggle this state. Ensures only one tooltip is open at a time and controls\n * the delay for showing a tooltip.\n */\nexport function useTooltipTriggerState(props: TooltipTriggerProps = {}): TooltipTriggerState {\n let {delay = TOOLTIP_DELAY, closeDelay = TOOLTIP_COOLDOWN} = props;\n let {isOpen, open, close} = useOverlayTriggerState(props);\n let id = useMemo(() => `${++tooltipId}`, []);\n let closeTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);\n let closeCallback = useRef<() => void>(close);\n\n let ensureTooltipEntry = () => {\n tooltips[id] = hideTooltip;\n };\n\n let closeOpenTooltips = () => {\n for (let hideTooltipId in tooltips) {\n if (hideTooltipId !== id) {\n tooltips[hideTooltipId](true);\n delete tooltips[hideTooltipId];\n }\n }\n };\n\n let showTooltip = () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeOpenTooltips();\n ensureTooltipEntry();\n globalWarmedUp = true;\n open();\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n globalCooldownTimeout = null;\n }\n };\n\n let hideTooltip = (immediate?: boolean) => {\n if (immediate || closeDelay <= 0) {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeCallback.current();\n } else if (!closeTimeout.current) {\n closeTimeout.current = setTimeout(() => {\n closeTimeout.current = null;\n closeCallback.current();\n }, closeDelay);\n }\n\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalWarmedUp) {\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n }\n globalCooldownTimeout = setTimeout(() => {\n delete tooltips[id];\n globalCooldownTimeout = null;\n globalWarmedUp = false;\n }, Math.max(TOOLTIP_COOLDOWN, closeDelay));\n }\n };\n\n let warmupTooltip = () => {\n closeOpenTooltips();\n ensureTooltipEntry();\n if (!isOpen && !globalWarmUpTimeout && !globalWarmedUp) {\n globalWarmUpTimeout = setTimeout(() => {\n globalWarmUpTimeout = null;\n globalWarmedUp = true;\n showTooltip();\n }, delay);\n } else if (!isOpen) {\n showTooltip();\n }\n };\n\n useEffect(() => {\n closeCallback.current = close;\n }, [close]);\n\n\n useEffect(() => {\n return () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n let tooltip = tooltips[id];\n if (tooltip) {\n delete tooltips[id];\n }\n };\n }, [id]);\n\n return {\n isOpen,\n open: (immediate) => {\n if (!immediate && delay > 0 && !closeTimeout.current) {\n warmupTooltip();\n } else {\n showTooltip();\n }\n },\n close: hideTooltip\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTriggerState.main.js.map"}
|
|
@@ -24,7 +24,7 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
24
24
|
let { delay: delay = $8796f90736e175cb$var$TOOLTIP_DELAY, closeDelay: closeDelay = $8796f90736e175cb$var$TOOLTIP_COOLDOWN } = props;
|
|
25
25
|
let { isOpen: isOpen, open: open, close: close } = (0, $50cCT$useOverlayTriggerState)(props);
|
|
26
26
|
let id = (0, $50cCT$useMemo)(()=>`${++$8796f90736e175cb$var$tooltipId}`, []);
|
|
27
|
-
let closeTimeout = (0, $50cCT$useRef)(
|
|
27
|
+
let closeTimeout = (0, $50cCT$useRef)(null);
|
|
28
28
|
let closeCallback = (0, $50cCT$useRef)(close);
|
|
29
29
|
let ensureTooltipEntry = ()=>{
|
|
30
30
|
$8796f90736e175cb$var$tooltips[id] = hideTooltip;
|
|
@@ -36,7 +36,7 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
let showTooltip = ()=>{
|
|
39
|
-
clearTimeout(closeTimeout.current);
|
|
39
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
40
40
|
closeTimeout.current = null;
|
|
41
41
|
closeOpenTooltips();
|
|
42
42
|
ensureTooltipEntry();
|
|
@@ -53,7 +53,7 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
53
53
|
};
|
|
54
54
|
let hideTooltip = (immediate)=>{
|
|
55
55
|
if (immediate || closeDelay <= 0) {
|
|
56
|
-
clearTimeout(closeTimeout.current);
|
|
56
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
57
57
|
closeTimeout.current = null;
|
|
58
58
|
closeCallback.current();
|
|
59
59
|
} else if (!closeTimeout.current) closeTimeout.current = setTimeout(()=>{
|
|
@@ -88,10 +88,9 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
88
88
|
}, [
|
|
89
89
|
close
|
|
90
90
|
]);
|
|
91
|
-
// eslint-disable-next-line arrow-body-style
|
|
92
91
|
(0, $50cCT$useEffect)(()=>{
|
|
93
92
|
return ()=>{
|
|
94
|
-
clearTimeout(closeTimeout.current);
|
|
93
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
95
94
|
let tooltip = $8796f90736e175cb$var$tooltips[id];
|
|
96
95
|
if (tooltip) delete $8796f90736e175cb$var$tooltips[id];
|
|
97
96
|
};
|
|
@@ -24,7 +24,7 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
24
24
|
let { delay: delay = $8796f90736e175cb$var$TOOLTIP_DELAY, closeDelay: closeDelay = $8796f90736e175cb$var$TOOLTIP_COOLDOWN } = props;
|
|
25
25
|
let { isOpen: isOpen, open: open, close: close } = (0, $50cCT$useOverlayTriggerState)(props);
|
|
26
26
|
let id = (0, $50cCT$useMemo)(()=>`${++$8796f90736e175cb$var$tooltipId}`, []);
|
|
27
|
-
let closeTimeout = (0, $50cCT$useRef)(
|
|
27
|
+
let closeTimeout = (0, $50cCT$useRef)(null);
|
|
28
28
|
let closeCallback = (0, $50cCT$useRef)(close);
|
|
29
29
|
let ensureTooltipEntry = ()=>{
|
|
30
30
|
$8796f90736e175cb$var$tooltips[id] = hideTooltip;
|
|
@@ -36,7 +36,7 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
let showTooltip = ()=>{
|
|
39
|
-
clearTimeout(closeTimeout.current);
|
|
39
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
40
40
|
closeTimeout.current = null;
|
|
41
41
|
closeOpenTooltips();
|
|
42
42
|
ensureTooltipEntry();
|
|
@@ -53,7 +53,7 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
53
53
|
};
|
|
54
54
|
let hideTooltip = (immediate)=>{
|
|
55
55
|
if (immediate || closeDelay <= 0) {
|
|
56
|
-
clearTimeout(closeTimeout.current);
|
|
56
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
57
57
|
closeTimeout.current = null;
|
|
58
58
|
closeCallback.current();
|
|
59
59
|
} else if (!closeTimeout.current) closeTimeout.current = setTimeout(()=>{
|
|
@@ -88,10 +88,9 @@ function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
|
|
|
88
88
|
}, [
|
|
89
89
|
close
|
|
90
90
|
]);
|
|
91
|
-
// eslint-disable-next-line arrow-body-style
|
|
92
91
|
(0, $50cCT$useEffect)(()=>{
|
|
93
92
|
return ()=>{
|
|
94
|
-
clearTimeout(closeTimeout.current);
|
|
93
|
+
if (closeTimeout.current) clearTimeout(closeTimeout.current);
|
|
95
94
|
let tooltip = $8796f90736e175cb$var$tooltips[id];
|
|
96
95
|
if (tooltip) delete $8796f90736e175cb$var$tooltips[id];
|
|
97
96
|
};
|
|
@@ -1 +1 @@
|
|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;YAChC,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;YAEnC,aAAa,OAAO,GAAG;YACvB,cAAc,OAAO;QACvB,OAAO,IAAI,CAAC,aAAa,OAAO,EAC9B,aAAa,OAAO,GAAG,WAAW;YAChC,aAAa,OAAO,GAAG;YACvB,cAAc,OAAO;QACvB,GAAG;QAGL,IAAI,2CAAqB;YACvB,aAAa;YACb,4CAAsB;QACxB;QACA,IAAI,sCAAgB;YAClB,IAAI,6CACF,aAAa;YAEf,8CAAwB,WAAW;gBACjC,OAAO,8BAAQ,CAAC,GAAG;gBACnB,8CAAwB;gBACxB,uCAAiB;YACnB,GAAG,KAAK,GAAG,CAAC,wCAAkB;QAChC;IACF;IAEA,IAAI,gBAAgB;QAClB;QACA;QACA,IAAI,CAAC,UAAU,CAAC,6CAAuB,CAAC,sCACtC,4CAAsB,WAAW;YAC/B,4CAAsB;YACtB,uCAAiB;YACjB;QACF,GAAG;aACE,IAAI,CAAC,QACV;IAEJ;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,cAAc,OAAO,GAAG;IAC1B,GAAG;QAAC;KAAM;IAGV,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO;YACL,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;YAEnC,IAAI,UAAU,8BAAQ,CAAC,GAAG;YAC1B,IAAI,SACF,OAAO,8BAAQ,CAAC,GAAG;QAEvB;IACF,GAAG;QAAC;KAAG;IAEP,OAAO;gBACL;QACA,MAAM,CAAC;YACL,IAAI,CAAC,aAAa,QAAQ,KAAK,CAAC,aAAa,OAAO,EAClD;iBAEA;QAEJ;QACA,OAAO;IACT;AACF","sources":["packages/@react-stately/tooltip/src/useTooltipTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {useEffect, useMemo, useRef} from 'react';\nimport {useOverlayTriggerState} from '@react-stately/overlays';\n\nconst TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design\nconst TOOLTIP_COOLDOWN = 500;\n\nexport interface TooltipTriggerState {\n /** Whether the tooltip is currently showing. */\n isOpen: boolean,\n /**\n * Shows the tooltip. By default, the tooltip becomes visible after a delay\n * depending on a global warmup timer. The `immediate` option shows the\n * tooltip immediately instead.\n */\n open(immediate?: boolean): void,\n /** Hides the tooltip. */\n close(immediate?: boolean): void\n}\n\nlet tooltips = {};\nlet tooltipId = 0;\nlet globalWarmedUp = false;\nlet globalWarmUpTimeout: ReturnType<typeof setTimeout> | null = null;\nlet globalCooldownTimeout: ReturnType<typeof setTimeout> | null = null;\n\n/**\n * Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides\n * methods to toggle this state. Ensures only one tooltip is open at a time and controls\n * the delay for showing a tooltip.\n */\nexport function useTooltipTriggerState(props: TooltipTriggerProps = {}): TooltipTriggerState {\n let {delay = TOOLTIP_DELAY, closeDelay = TOOLTIP_COOLDOWN} = props;\n let {isOpen, open, close} = useOverlayTriggerState(props);\n let id = useMemo(() => `${++tooltipId}`, []);\n let closeTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);\n let closeCallback = useRef<() => void>(close);\n\n let ensureTooltipEntry = () => {\n tooltips[id] = hideTooltip;\n };\n\n let closeOpenTooltips = () => {\n for (let hideTooltipId in tooltips) {\n if (hideTooltipId !== id) {\n tooltips[hideTooltipId](true);\n delete tooltips[hideTooltipId];\n }\n }\n };\n\n let showTooltip = () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeOpenTooltips();\n ensureTooltipEntry();\n globalWarmedUp = true;\n open();\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n globalCooldownTimeout = null;\n }\n };\n\n let hideTooltip = (immediate?: boolean) => {\n if (immediate || closeDelay <= 0) {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeCallback.current();\n } else if (!closeTimeout.current) {\n closeTimeout.current = setTimeout(() => {\n closeTimeout.current = null;\n closeCallback.current();\n }, closeDelay);\n }\n\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalWarmedUp) {\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n }\n globalCooldownTimeout = setTimeout(() => {\n delete tooltips[id];\n globalCooldownTimeout = null;\n globalWarmedUp = false;\n }, Math.max(TOOLTIP_COOLDOWN, closeDelay));\n }\n };\n\n let warmupTooltip = () => {\n closeOpenTooltips();\n ensureTooltipEntry();\n if (!isOpen && !globalWarmUpTimeout && !globalWarmedUp) {\n globalWarmUpTimeout = setTimeout(() => {\n globalWarmUpTimeout = null;\n globalWarmedUp = true;\n showTooltip();\n }, delay);\n } else if (!isOpen) {\n showTooltip();\n }\n };\n\n useEffect(() => {\n closeCallback.current = close;\n }, [close]);\n\n\n useEffect(() => {\n return () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n let tooltip = tooltips[id];\n if (tooltip) {\n delete tooltips[id];\n }\n };\n }, [id]);\n\n return {\n isOpen,\n open: (immediate) => {\n if (!immediate && delay > 0 && !closeTimeout.current) {\n warmupTooltip();\n } else {\n showTooltip();\n }\n },\n close: hideTooltip\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTriggerState.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/tooltip",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/overlays": "3.6.
|
|
26
|
-
"@react-types/tooltip": "3.4.
|
|
25
|
+
"@react-stately/overlays": "^3.6.12",
|
|
26
|
+
"@react-types/tooltip": "^3.4.13",
|
|
27
27
|
"@swc/helpers": "^0.5.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
30
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
|
|
36
36
|
}
|
|
@@ -33,8 +33,8 @@ export interface TooltipTriggerState {
|
|
|
33
33
|
let tooltips = {};
|
|
34
34
|
let tooltipId = 0;
|
|
35
35
|
let globalWarmedUp = false;
|
|
36
|
-
let globalWarmUpTimeout = null;
|
|
37
|
-
let globalCooldownTimeout = null;
|
|
36
|
+
let globalWarmUpTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
37
|
+
let globalCooldownTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides
|
|
@@ -45,7 +45,7 @@ export function useTooltipTriggerState(props: TooltipTriggerProps = {}): Tooltip
|
|
|
45
45
|
let {delay = TOOLTIP_DELAY, closeDelay = TOOLTIP_COOLDOWN} = props;
|
|
46
46
|
let {isOpen, open, close} = useOverlayTriggerState(props);
|
|
47
47
|
let id = useMemo(() => `${++tooltipId}`, []);
|
|
48
|
-
let closeTimeout = useRef<ReturnType<typeof setTimeout
|
|
48
|
+
let closeTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
49
49
|
let closeCallback = useRef<() => void>(close);
|
|
50
50
|
|
|
51
51
|
let ensureTooltipEntry = () => {
|
|
@@ -62,7 +62,9 @@ export function useTooltipTriggerState(props: TooltipTriggerProps = {}): Tooltip
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
let showTooltip = () => {
|
|
65
|
-
|
|
65
|
+
if (closeTimeout.current) {
|
|
66
|
+
clearTimeout(closeTimeout.current);
|
|
67
|
+
}
|
|
66
68
|
closeTimeout.current = null;
|
|
67
69
|
closeOpenTooltips();
|
|
68
70
|
ensureTooltipEntry();
|
|
@@ -80,7 +82,9 @@ export function useTooltipTriggerState(props: TooltipTriggerProps = {}): Tooltip
|
|
|
80
82
|
|
|
81
83
|
let hideTooltip = (immediate?: boolean) => {
|
|
82
84
|
if (immediate || closeDelay <= 0) {
|
|
83
|
-
|
|
85
|
+
if (closeTimeout.current) {
|
|
86
|
+
clearTimeout(closeTimeout.current);
|
|
87
|
+
}
|
|
84
88
|
closeTimeout.current = null;
|
|
85
89
|
closeCallback.current();
|
|
86
90
|
} else if (!closeTimeout.current) {
|
|
@@ -124,10 +128,12 @@ export function useTooltipTriggerState(props: TooltipTriggerProps = {}): Tooltip
|
|
|
124
128
|
closeCallback.current = close;
|
|
125
129
|
}, [close]);
|
|
126
130
|
|
|
127
|
-
|
|
131
|
+
|
|
128
132
|
useEffect(() => {
|
|
129
133
|
return () => {
|
|
130
|
-
|
|
134
|
+
if (closeTimeout.current) {
|
|
135
|
+
clearTimeout(closeTimeout.current);
|
|
136
|
+
}
|
|
131
137
|
let tooltip = tooltips[id];
|
|
132
138
|
if (tooltip) {
|
|
133
139
|
delete tooltips[id];
|