@react-stately/tooltip 3.5.10 → 3.6.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/import.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {useTooltipTriggerState as $8796f90736e175cb$export$4d40659c25ecb50b} from "./useTooltipTriggerState.mjs";
1
+ import {useTooltipTriggerState as $1caf4c9749018f3f$re_export$useTooltipTriggerState} from "react-stately/useTooltipTriggerState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useTooltipTriggerState as $8796f90736e175cb$export$4d40659c25ecb50b} fro
13
13
  */
14
14
 
15
15
 
16
- export {$8796f90736e175cb$export$4d40659c25ecb50b as useTooltipTriggerState};
16
+ export {$1caf4c9749018f3f$re_export$useTooltipTriggerState as useTooltipTriggerState};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- var $3391baedd777a697$exports = require("./useTooltipTriggerState.main.js");
1
+ var $fIEQi$reactstatelyuseTooltipTriggerState = require("react-stately/useTooltipTriggerState");
2
2
 
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "useTooltipTriggerState", () => $3391baedd777a697$exports.useTooltipTriggerState);
8
+ $parcel$export(module.exports, "useTooltipTriggerState", function () { return $fIEQi$reactstatelyuseTooltipTriggerState.useTooltipTriggerState; });
9
9
  /*
10
10
  * Copyright 2020 Adobe. All rights reserved.
11
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tooltip/src/index.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\nexport {useTooltipTriggerState} from './useTooltipTriggerState';\n\nexport type {TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipTriggerState} from './useTooltipTriggerState';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tooltip/src/index.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\nexport {useTooltipTriggerState} from 'react-stately/useTooltipTriggerState';\n\nexport type {TooltipTriggerProps, TooltipTriggerState} from 'react-stately/useTooltipTriggerState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useTooltipTriggerState as $8796f90736e175cb$export$4d40659c25ecb50b} from "./useTooltipTriggerState.module.js";
1
+ import {useTooltipTriggerState as $1caf4c9749018f3f$re_export$useTooltipTriggerState} from "react-stately/useTooltipTriggerState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useTooltipTriggerState as $8796f90736e175cb$export$4d40659c25ecb50b} fro
13
13
  */
14
14
 
15
15
 
16
- export {$8796f90736e175cb$export$4d40659c25ecb50b as useTooltipTriggerState};
16
+ export {$1caf4c9749018f3f$re_export$useTooltipTriggerState as useTooltipTriggerState};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tooltip/src/index.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\nexport {useTooltipTriggerState} from './useTooltipTriggerState';\n\nexport type {TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipTriggerState} from './useTooltipTriggerState';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tooltip/src/index.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\nexport {useTooltipTriggerState} from 'react-stately/useTooltipTriggerState';\n\nexport type {TooltipTriggerProps, TooltipTriggerState} from 'react-stately/useTooltipTriggerState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useTooltipTriggerState } from 'react-stately/useTooltipTriggerState';
2
+ export type { TooltipTriggerProps, TooltipTriggerState } from 'react-stately/useTooltipTriggerState';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-stately/tooltip",
3
- "version": "3.5.10",
3
+ "version": "3.6.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,15 +26,18 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-stately/overlays": "^3.6.22",
30
- "@react-types/tooltip": "^3.5.1",
31
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-stately": "3.46.0"
32
31
  },
33
32
  "peerDependencies": {
34
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
34
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
40
43
  }
package/src/index.ts CHANGED
@@ -10,7 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {useTooltipTriggerState} from './useTooltipTriggerState';
13
+ export {useTooltipTriggerState} from 'react-stately/useTooltipTriggerState';
14
14
 
15
- export type {TooltipTriggerProps} from '@react-types/tooltip';
16
- export type {TooltipTriggerState} from './useTooltipTriggerState';
15
+ export type {TooltipTriggerProps, TooltipTriggerState} from 'react-stately/useTooltipTriggerState';
package/dist/types.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import { TooltipTriggerProps } from "@react-types/tooltip";
2
- export interface TooltipTriggerState {
3
- /** Whether the tooltip is currently showing. */
4
- isOpen: boolean;
5
- /**
6
- * Shows the tooltip. By default, the tooltip becomes visible after a delay
7
- * depending on a global warmup timer. The `immediate` option shows the
8
- * tooltip immediately instead.
9
- */
10
- open(immediate?: boolean): void;
11
- /** Hides the tooltip. */
12
- close(immediate?: boolean): void;
13
- }
14
- /**
15
- * Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides
16
- * methods to toggle this state. Ensures only one tooltip is open at a time and controls
17
- * the delay for showing a tooltip.
18
- */
19
- export function useTooltipTriggerState(props?: TooltipTriggerProps): TooltipTriggerState;
20
- export type { TooltipTriggerProps } from '@react-types/tooltip';
21
-
22
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,117 +0,0 @@
1
- var $w0mn6$react = require("react");
2
- var $w0mn6$reactstatelyoverlays = require("@react-stately/overlays");
3
-
4
-
5
- function $parcel$export(e, n, v, s) {
6
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
- }
8
-
9
- $parcel$export(module.exports, "useTooltipTriggerState", () => $3391baedd777a697$export$4d40659c25ecb50b);
10
- /*
11
- * Copyright 2020 Adobe. All rights reserved.
12
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License. You may obtain a copy
14
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software distributed under
17
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
- * OF ANY KIND, either express or implied. See the License for the specific language
19
- * governing permissions and limitations under the License.
20
- */
21
-
22
- const $3391baedd777a697$var$TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design
23
- const $3391baedd777a697$var$TOOLTIP_COOLDOWN = 500;
24
- let $3391baedd777a697$var$tooltips = {};
25
- let $3391baedd777a697$var$tooltipId = 0;
26
- let $3391baedd777a697$var$globalWarmedUp = false;
27
- let $3391baedd777a697$var$globalWarmUpTimeout = null;
28
- let $3391baedd777a697$var$globalCooldownTimeout = null;
29
- function $3391baedd777a697$export$4d40659c25ecb50b(props = {}) {
30
- let { delay: delay = $3391baedd777a697$var$TOOLTIP_DELAY, closeDelay: closeDelay = $3391baedd777a697$var$TOOLTIP_COOLDOWN } = props;
31
- let { isOpen: isOpen, open: open, close: close } = (0, $w0mn6$reactstatelyoverlays.useOverlayTriggerState)(props);
32
- let id = (0, $w0mn6$react.useMemo)(()=>`${++$3391baedd777a697$var$tooltipId}`, []);
33
- let closeTimeout = (0, $w0mn6$react.useRef)(null);
34
- let closeCallback = (0, $w0mn6$react.useRef)(close);
35
- let ensureTooltipEntry = ()=>{
36
- $3391baedd777a697$var$tooltips[id] = hideTooltip;
37
- };
38
- let closeOpenTooltips = ()=>{
39
- for(let hideTooltipId in $3391baedd777a697$var$tooltips)if (hideTooltipId !== id) {
40
- $3391baedd777a697$var$tooltips[hideTooltipId](true);
41
- delete $3391baedd777a697$var$tooltips[hideTooltipId];
42
- }
43
- };
44
- let showTooltip = ()=>{
45
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
46
- closeTimeout.current = null;
47
- closeOpenTooltips();
48
- ensureTooltipEntry();
49
- $3391baedd777a697$var$globalWarmedUp = true;
50
- open();
51
- if ($3391baedd777a697$var$globalWarmUpTimeout) {
52
- clearTimeout($3391baedd777a697$var$globalWarmUpTimeout);
53
- $3391baedd777a697$var$globalWarmUpTimeout = null;
54
- }
55
- if ($3391baedd777a697$var$globalCooldownTimeout) {
56
- clearTimeout($3391baedd777a697$var$globalCooldownTimeout);
57
- $3391baedd777a697$var$globalCooldownTimeout = null;
58
- }
59
- };
60
- let hideTooltip = (immediate)=>{
61
- if (immediate || closeDelay <= 0) {
62
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
63
- closeTimeout.current = null;
64
- closeCallback.current();
65
- } else if (!closeTimeout.current) closeTimeout.current = setTimeout(()=>{
66
- closeTimeout.current = null;
67
- closeCallback.current();
68
- }, closeDelay);
69
- if ($3391baedd777a697$var$globalWarmUpTimeout) {
70
- clearTimeout($3391baedd777a697$var$globalWarmUpTimeout);
71
- $3391baedd777a697$var$globalWarmUpTimeout = null;
72
- }
73
- if ($3391baedd777a697$var$globalWarmedUp) {
74
- if ($3391baedd777a697$var$globalCooldownTimeout) clearTimeout($3391baedd777a697$var$globalCooldownTimeout);
75
- $3391baedd777a697$var$globalCooldownTimeout = setTimeout(()=>{
76
- delete $3391baedd777a697$var$tooltips[id];
77
- $3391baedd777a697$var$globalCooldownTimeout = null;
78
- $3391baedd777a697$var$globalWarmedUp = false;
79
- }, Math.max($3391baedd777a697$var$TOOLTIP_COOLDOWN, closeDelay));
80
- }
81
- };
82
- let warmupTooltip = ()=>{
83
- closeOpenTooltips();
84
- ensureTooltipEntry();
85
- if (!isOpen && !$3391baedd777a697$var$globalWarmUpTimeout && !$3391baedd777a697$var$globalWarmedUp) $3391baedd777a697$var$globalWarmUpTimeout = setTimeout(()=>{
86
- $3391baedd777a697$var$globalWarmUpTimeout = null;
87
- $3391baedd777a697$var$globalWarmedUp = true;
88
- showTooltip();
89
- }, delay);
90
- else if (!isOpen) showTooltip();
91
- };
92
- (0, $w0mn6$react.useEffect)(()=>{
93
- closeCallback.current = close;
94
- }, [
95
- close
96
- ]);
97
- (0, $w0mn6$react.useEffect)(()=>{
98
- return ()=>{
99
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
100
- let tooltip = $3391baedd777a697$var$tooltips[id];
101
- if (tooltip) delete $3391baedd777a697$var$tooltips[id];
102
- };
103
- }, [
104
- id
105
- ]);
106
- return {
107
- isOpen: isOpen,
108
- open: (immediate)=>{
109
- if (!immediate && delay > 0 && !closeTimeout.current) warmupTooltip();
110
- else showTooltip();
111
- },
112
- close: hideTooltip
113
- };
114
- }
115
-
116
-
117
- //# sourceMappingURL=useTooltipTriggerState.main.js.map
@@ -1 +0,0 @@
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,SAAE,KAAK,EAAC,GAAG,CAAA,GAAA,kDAAqB,EAAE;IACnD,IAAI,KAAK,CAAA,GAAA,oBAAM,EAAE,IAAM,GAAG,EAAE,iCAAW,EAAE,EAAE;IAC3C,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAwC;IAChE,IAAI,gBAAgB,CAAA,GAAA,mBAAK,EAAc;IAEvC,IAAI,qBAAqB;QACvB,8BAAQ,CAAC,GAAG,GAAG;IACjB;IAEA,IAAI,oBAAoB;QACtB,IAAK,IAAI,iBAAiB,+BACxB,IAAI,kBAAkB,IAAI;YACxB,8BAAQ,CAAC,cAAc,CAAC;YACxB,OAAO,8BAAQ,CAAC,cAAc;QAChC;IAEJ;IAEA,IAAI,cAAc;QAChB,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;QAEnC,aAAa,OAAO,GAAG;QACvB;QACA;QACA,uCAAiB;QACjB;QACA,IAAI,2CAAqB;YACvB,aAAa;YACb,4CAAsB;QACxB;QACA,IAAI,6CAAuB;YACzB,aAAa;YACb,8CAAwB;QAC1B;IACF;IAEA,IAAI,cAAc,CAAC;QACjB,IAAI,aAAa,cAAc,GAAG;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,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"}
@@ -1,112 +0,0 @@
1
- import {useMemo as $50cCT$useMemo, useRef as $50cCT$useRef, useEffect as $50cCT$useEffect} from "react";
2
- import {useOverlayTriggerState as $50cCT$useOverlayTriggerState} from "@react-stately/overlays";
3
-
4
- /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- const $8796f90736e175cb$var$TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design
17
- const $8796f90736e175cb$var$TOOLTIP_COOLDOWN = 500;
18
- let $8796f90736e175cb$var$tooltips = {};
19
- let $8796f90736e175cb$var$tooltipId = 0;
20
- let $8796f90736e175cb$var$globalWarmedUp = false;
21
- let $8796f90736e175cb$var$globalWarmUpTimeout = null;
22
- let $8796f90736e175cb$var$globalCooldownTimeout = null;
23
- function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
24
- let { delay: delay = $8796f90736e175cb$var$TOOLTIP_DELAY, closeDelay: closeDelay = $8796f90736e175cb$var$TOOLTIP_COOLDOWN } = props;
25
- let { isOpen: isOpen, open: open, close: close } = (0, $50cCT$useOverlayTriggerState)(props);
26
- let id = (0, $50cCT$useMemo)(()=>`${++$8796f90736e175cb$var$tooltipId}`, []);
27
- let closeTimeout = (0, $50cCT$useRef)(null);
28
- let closeCallback = (0, $50cCT$useRef)(close);
29
- let ensureTooltipEntry = ()=>{
30
- $8796f90736e175cb$var$tooltips[id] = hideTooltip;
31
- };
32
- let closeOpenTooltips = ()=>{
33
- for(let hideTooltipId in $8796f90736e175cb$var$tooltips)if (hideTooltipId !== id) {
34
- $8796f90736e175cb$var$tooltips[hideTooltipId](true);
35
- delete $8796f90736e175cb$var$tooltips[hideTooltipId];
36
- }
37
- };
38
- let showTooltip = ()=>{
39
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
40
- closeTimeout.current = null;
41
- closeOpenTooltips();
42
- ensureTooltipEntry();
43
- $8796f90736e175cb$var$globalWarmedUp = true;
44
- open();
45
- if ($8796f90736e175cb$var$globalWarmUpTimeout) {
46
- clearTimeout($8796f90736e175cb$var$globalWarmUpTimeout);
47
- $8796f90736e175cb$var$globalWarmUpTimeout = null;
48
- }
49
- if ($8796f90736e175cb$var$globalCooldownTimeout) {
50
- clearTimeout($8796f90736e175cb$var$globalCooldownTimeout);
51
- $8796f90736e175cb$var$globalCooldownTimeout = null;
52
- }
53
- };
54
- let hideTooltip = (immediate)=>{
55
- if (immediate || closeDelay <= 0) {
56
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
57
- closeTimeout.current = null;
58
- closeCallback.current();
59
- } else if (!closeTimeout.current) closeTimeout.current = setTimeout(()=>{
60
- closeTimeout.current = null;
61
- closeCallback.current();
62
- }, closeDelay);
63
- if ($8796f90736e175cb$var$globalWarmUpTimeout) {
64
- clearTimeout($8796f90736e175cb$var$globalWarmUpTimeout);
65
- $8796f90736e175cb$var$globalWarmUpTimeout = null;
66
- }
67
- if ($8796f90736e175cb$var$globalWarmedUp) {
68
- if ($8796f90736e175cb$var$globalCooldownTimeout) clearTimeout($8796f90736e175cb$var$globalCooldownTimeout);
69
- $8796f90736e175cb$var$globalCooldownTimeout = setTimeout(()=>{
70
- delete $8796f90736e175cb$var$tooltips[id];
71
- $8796f90736e175cb$var$globalCooldownTimeout = null;
72
- $8796f90736e175cb$var$globalWarmedUp = false;
73
- }, Math.max($8796f90736e175cb$var$TOOLTIP_COOLDOWN, closeDelay));
74
- }
75
- };
76
- let warmupTooltip = ()=>{
77
- closeOpenTooltips();
78
- ensureTooltipEntry();
79
- if (!isOpen && !$8796f90736e175cb$var$globalWarmUpTimeout && !$8796f90736e175cb$var$globalWarmedUp) $8796f90736e175cb$var$globalWarmUpTimeout = setTimeout(()=>{
80
- $8796f90736e175cb$var$globalWarmUpTimeout = null;
81
- $8796f90736e175cb$var$globalWarmedUp = true;
82
- showTooltip();
83
- }, delay);
84
- else if (!isOpen) showTooltip();
85
- };
86
- (0, $50cCT$useEffect)(()=>{
87
- closeCallback.current = close;
88
- }, [
89
- close
90
- ]);
91
- (0, $50cCT$useEffect)(()=>{
92
- return ()=>{
93
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
94
- let tooltip = $8796f90736e175cb$var$tooltips[id];
95
- if (tooltip) delete $8796f90736e175cb$var$tooltips[id];
96
- };
97
- }, [
98
- id
99
- ]);
100
- return {
101
- isOpen: isOpen,
102
- open: (immediate)=>{
103
- if (!immediate && delay > 0 && !closeTimeout.current) warmupTooltip();
104
- else showTooltip();
105
- },
106
- close: hideTooltip
107
- };
108
- }
109
-
110
-
111
- export {$8796f90736e175cb$export$4d40659c25ecb50b as useTooltipTriggerState};
112
- //# sourceMappingURL=useTooltipTriggerState.module.js.map
@@ -1,112 +0,0 @@
1
- import {useMemo as $50cCT$useMemo, useRef as $50cCT$useRef, useEffect as $50cCT$useEffect} from "react";
2
- import {useOverlayTriggerState as $50cCT$useOverlayTriggerState} from "@react-stately/overlays";
3
-
4
- /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- const $8796f90736e175cb$var$TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design
17
- const $8796f90736e175cb$var$TOOLTIP_COOLDOWN = 500;
18
- let $8796f90736e175cb$var$tooltips = {};
19
- let $8796f90736e175cb$var$tooltipId = 0;
20
- let $8796f90736e175cb$var$globalWarmedUp = false;
21
- let $8796f90736e175cb$var$globalWarmUpTimeout = null;
22
- let $8796f90736e175cb$var$globalCooldownTimeout = null;
23
- function $8796f90736e175cb$export$4d40659c25ecb50b(props = {}) {
24
- let { delay: delay = $8796f90736e175cb$var$TOOLTIP_DELAY, closeDelay: closeDelay = $8796f90736e175cb$var$TOOLTIP_COOLDOWN } = props;
25
- let { isOpen: isOpen, open: open, close: close } = (0, $50cCT$useOverlayTriggerState)(props);
26
- let id = (0, $50cCT$useMemo)(()=>`${++$8796f90736e175cb$var$tooltipId}`, []);
27
- let closeTimeout = (0, $50cCT$useRef)(null);
28
- let closeCallback = (0, $50cCT$useRef)(close);
29
- let ensureTooltipEntry = ()=>{
30
- $8796f90736e175cb$var$tooltips[id] = hideTooltip;
31
- };
32
- let closeOpenTooltips = ()=>{
33
- for(let hideTooltipId in $8796f90736e175cb$var$tooltips)if (hideTooltipId !== id) {
34
- $8796f90736e175cb$var$tooltips[hideTooltipId](true);
35
- delete $8796f90736e175cb$var$tooltips[hideTooltipId];
36
- }
37
- };
38
- let showTooltip = ()=>{
39
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
40
- closeTimeout.current = null;
41
- closeOpenTooltips();
42
- ensureTooltipEntry();
43
- $8796f90736e175cb$var$globalWarmedUp = true;
44
- open();
45
- if ($8796f90736e175cb$var$globalWarmUpTimeout) {
46
- clearTimeout($8796f90736e175cb$var$globalWarmUpTimeout);
47
- $8796f90736e175cb$var$globalWarmUpTimeout = null;
48
- }
49
- if ($8796f90736e175cb$var$globalCooldownTimeout) {
50
- clearTimeout($8796f90736e175cb$var$globalCooldownTimeout);
51
- $8796f90736e175cb$var$globalCooldownTimeout = null;
52
- }
53
- };
54
- let hideTooltip = (immediate)=>{
55
- if (immediate || closeDelay <= 0) {
56
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
57
- closeTimeout.current = null;
58
- closeCallback.current();
59
- } else if (!closeTimeout.current) closeTimeout.current = setTimeout(()=>{
60
- closeTimeout.current = null;
61
- closeCallback.current();
62
- }, closeDelay);
63
- if ($8796f90736e175cb$var$globalWarmUpTimeout) {
64
- clearTimeout($8796f90736e175cb$var$globalWarmUpTimeout);
65
- $8796f90736e175cb$var$globalWarmUpTimeout = null;
66
- }
67
- if ($8796f90736e175cb$var$globalWarmedUp) {
68
- if ($8796f90736e175cb$var$globalCooldownTimeout) clearTimeout($8796f90736e175cb$var$globalCooldownTimeout);
69
- $8796f90736e175cb$var$globalCooldownTimeout = setTimeout(()=>{
70
- delete $8796f90736e175cb$var$tooltips[id];
71
- $8796f90736e175cb$var$globalCooldownTimeout = null;
72
- $8796f90736e175cb$var$globalWarmedUp = false;
73
- }, Math.max($8796f90736e175cb$var$TOOLTIP_COOLDOWN, closeDelay));
74
- }
75
- };
76
- let warmupTooltip = ()=>{
77
- closeOpenTooltips();
78
- ensureTooltipEntry();
79
- if (!isOpen && !$8796f90736e175cb$var$globalWarmUpTimeout && !$8796f90736e175cb$var$globalWarmedUp) $8796f90736e175cb$var$globalWarmUpTimeout = setTimeout(()=>{
80
- $8796f90736e175cb$var$globalWarmUpTimeout = null;
81
- $8796f90736e175cb$var$globalWarmedUp = true;
82
- showTooltip();
83
- }, delay);
84
- else if (!isOpen) showTooltip();
85
- };
86
- (0, $50cCT$useEffect)(()=>{
87
- closeCallback.current = close;
88
- }, [
89
- close
90
- ]);
91
- (0, $50cCT$useEffect)(()=>{
92
- return ()=>{
93
- if (closeTimeout.current) clearTimeout(closeTimeout.current);
94
- let tooltip = $8796f90736e175cb$var$tooltips[id];
95
- if (tooltip) delete $8796f90736e175cb$var$tooltips[id];
96
- };
97
- }, [
98
- id
99
- ]);
100
- return {
101
- isOpen: isOpen,
102
- open: (immediate)=>{
103
- if (!immediate && delay > 0 && !closeTimeout.current) warmupTooltip();
104
- else showTooltip();
105
- },
106
- close: hideTooltip
107
- };
108
- }
109
-
110
-
111
- export {$8796f90736e175cb$export$4d40659c25ecb50b as useTooltipTriggerState};
112
- //# sourceMappingURL=useTooltipTriggerState.module.js.map
@@ -1 +0,0 @@
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,SAAE,KAAK,EAAC,GAAG,CAAA,GAAA,6BAAqB,EAAE;IACnD,IAAI,KAAK,CAAA,GAAA,cAAM,EAAE,IAAM,GAAG,EAAE,iCAAW,EAAE,EAAE;IAC3C,IAAI,eAAe,CAAA,GAAA,aAAK,EAAwC;IAChE,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAc;IAEvC,IAAI,qBAAqB;QACvB,8BAAQ,CAAC,GAAG,GAAG;IACjB;IAEA,IAAI,oBAAoB;QACtB,IAAK,IAAI,iBAAiB,+BACxB,IAAI,kBAAkB,IAAI;YACxB,8BAAQ,CAAC,cAAc,CAAC;YACxB,OAAO,8BAAQ,CAAC,cAAc;QAChC;IAEJ;IAEA,IAAI,cAAc;QAChB,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;QAEnC,aAAa,OAAO,GAAG;QACvB;QACA;QACA,uCAAiB;QACjB;QACA,IAAI,2CAAqB;YACvB,aAAa;YACb,4CAAsB;QACxB;QACA,IAAI,6CAAuB;YACzB,aAAa;YACb,8CAAwB;QAC1B;IACF;IAEA,IAAI,cAAc,CAAC;QACjB,IAAI,aAAa,cAAc,GAAG;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"}
@@ -1,155 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {TooltipTriggerProps} from '@react-types/tooltip';
14
- import {useEffect, useMemo, useRef} from 'react';
15
- import {useOverlayTriggerState} from '@react-stately/overlays';
16
-
17
- const TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design
18
- const TOOLTIP_COOLDOWN = 500;
19
-
20
- export interface TooltipTriggerState {
21
- /** Whether the tooltip is currently showing. */
22
- isOpen: boolean,
23
- /**
24
- * Shows the tooltip. By default, the tooltip becomes visible after a delay
25
- * depending on a global warmup timer. The `immediate` option shows the
26
- * tooltip immediately instead.
27
- */
28
- open(immediate?: boolean): void,
29
- /** Hides the tooltip. */
30
- close(immediate?: boolean): void
31
- }
32
-
33
- let tooltips = {};
34
- let tooltipId = 0;
35
- let globalWarmedUp = false;
36
- let globalWarmUpTimeout: ReturnType<typeof setTimeout> | null = null;
37
- let globalCooldownTimeout: ReturnType<typeof setTimeout> | null = null;
38
-
39
- /**
40
- * Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides
41
- * methods to toggle this state. Ensures only one tooltip is open at a time and controls
42
- * the delay for showing a tooltip.
43
- */
44
- export function useTooltipTriggerState(props: TooltipTriggerProps = {}): TooltipTriggerState {
45
- let {delay = TOOLTIP_DELAY, closeDelay = TOOLTIP_COOLDOWN} = props;
46
- let {isOpen, open, close} = useOverlayTriggerState(props);
47
- let id = useMemo(() => `${++tooltipId}`, []);
48
- let closeTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
49
- let closeCallback = useRef<() => void>(close);
50
-
51
- let ensureTooltipEntry = () => {
52
- tooltips[id] = hideTooltip;
53
- };
54
-
55
- let closeOpenTooltips = () => {
56
- for (let hideTooltipId in tooltips) {
57
- if (hideTooltipId !== id) {
58
- tooltips[hideTooltipId](true);
59
- delete tooltips[hideTooltipId];
60
- }
61
- }
62
- };
63
-
64
- let showTooltip = () => {
65
- if (closeTimeout.current) {
66
- clearTimeout(closeTimeout.current);
67
- }
68
- closeTimeout.current = null;
69
- closeOpenTooltips();
70
- ensureTooltipEntry();
71
- globalWarmedUp = true;
72
- open();
73
- if (globalWarmUpTimeout) {
74
- clearTimeout(globalWarmUpTimeout);
75
- globalWarmUpTimeout = null;
76
- }
77
- if (globalCooldownTimeout) {
78
- clearTimeout(globalCooldownTimeout);
79
- globalCooldownTimeout = null;
80
- }
81
- };
82
-
83
- let hideTooltip = (immediate?: boolean) => {
84
- if (immediate || closeDelay <= 0) {
85
- if (closeTimeout.current) {
86
- clearTimeout(closeTimeout.current);
87
- }
88
- closeTimeout.current = null;
89
- closeCallback.current();
90
- } else if (!closeTimeout.current) {
91
- closeTimeout.current = setTimeout(() => {
92
- closeTimeout.current = null;
93
- closeCallback.current();
94
- }, closeDelay);
95
- }
96
-
97
- if (globalWarmUpTimeout) {
98
- clearTimeout(globalWarmUpTimeout);
99
- globalWarmUpTimeout = null;
100
- }
101
- if (globalWarmedUp) {
102
- if (globalCooldownTimeout) {
103
- clearTimeout(globalCooldownTimeout);
104
- }
105
- globalCooldownTimeout = setTimeout(() => {
106
- delete tooltips[id];
107
- globalCooldownTimeout = null;
108
- globalWarmedUp = false;
109
- }, Math.max(TOOLTIP_COOLDOWN, closeDelay));
110
- }
111
- };
112
-
113
- let warmupTooltip = () => {
114
- closeOpenTooltips();
115
- ensureTooltipEntry();
116
- if (!isOpen && !globalWarmUpTimeout && !globalWarmedUp) {
117
- globalWarmUpTimeout = setTimeout(() => {
118
- globalWarmUpTimeout = null;
119
- globalWarmedUp = true;
120
- showTooltip();
121
- }, delay);
122
- } else if (!isOpen) {
123
- showTooltip();
124
- }
125
- };
126
-
127
- useEffect(() => {
128
- closeCallback.current = close;
129
- }, [close]);
130
-
131
-
132
- useEffect(() => {
133
- return () => {
134
- if (closeTimeout.current) {
135
- clearTimeout(closeTimeout.current);
136
- }
137
- let tooltip = tooltips[id];
138
- if (tooltip) {
139
- delete tooltips[id];
140
- }
141
- };
142
- }, [id]);
143
-
144
- return {
145
- isOpen,
146
- open: (immediate) => {
147
- if (!immediate && delay > 0 && !closeTimeout.current) {
148
- warmupTooltip();
149
- } else {
150
- showTooltip();
151
- }
152
- },
153
- close: hideTooltip
154
- };
155
- }