@react-aria/tooltip 3.7.2 → 3.7.3

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,19 +1,7 @@
1
- import {filterDOMProps as $kgVYN$filterDOMProps, mergeProps as $kgVYN$mergeProps, useId as $kgVYN$useId} from "@react-aria/utils";
2
- import {useHover as $kgVYN$useHover, getInteractionModality as $kgVYN$getInteractionModality, isFocusVisible as $kgVYN$isFocusVisible} from "@react-aria/interactions";
3
- import {useRef as $kgVYN$useRef, useEffect as $kgVYN$useEffect} from "react";
4
- import {useFocusable as $kgVYN$useFocusable} from "@react-aria/focus";
1
+ import {useTooltip as $326e436e94273fe1$export$1c4b08e0eca38426} from "./useTooltip.mjs";
2
+ import {useTooltipTrigger as $4e1b34546679e357$export$a6da6c504e4bba8b} from "./useTooltipTrigger.mjs";
5
3
 
6
4
  /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */ /*
17
5
  * Copyright 2020 Adobe. All rights reserved.
18
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -25,128 +13,6 @@ import {useFocusable as $kgVYN$useFocusable} from "@react-aria/focus";
25
13
  * governing permissions and limitations under the License.
26
14
  */
27
15
 
28
- function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
29
- let domProps = (0, $kgVYN$filterDOMProps)(props, {
30
- labelable: true
31
- });
32
- let { hoverProps: hoverProps } = (0, $kgVYN$useHover)({
33
- onHoverStart: ()=>state === null || state === void 0 ? void 0 : state.open(true),
34
- onHoverEnd: ()=>state === null || state === void 0 ? void 0 : state.close()
35
- });
36
- return {
37
- tooltipProps: (0, $kgVYN$mergeProps)(domProps, hoverProps, {
38
- role: "tooltip"
39
- })
40
- };
41
- }
42
-
43
-
44
- /*
45
- * Copyright 2020 Adobe. All rights reserved.
46
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
47
- * you may not use this file except in compliance with the License. You may obtain a copy
48
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
49
- *
50
- * Unless required by applicable law or agreed to in writing, software distributed under
51
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
52
- * OF ANY KIND, either express or implied. See the License for the specific language
53
- * governing permissions and limitations under the License.
54
- */
55
-
56
-
57
-
58
- function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
59
- let { isDisabled: isDisabled, trigger: trigger } = props;
60
- let tooltipId = (0, $kgVYN$useId)();
61
- let isHovered = (0, $kgVYN$useRef)(false);
62
- let isFocused = (0, $kgVYN$useRef)(false);
63
- let handleShow = ()=>{
64
- if (isHovered.current || isFocused.current) state.open(isFocused.current);
65
- };
66
- let handleHide = (immediate)=>{
67
- if (!isHovered.current && !isFocused.current) state.close(immediate);
68
- };
69
- (0, $kgVYN$useEffect)(()=>{
70
- let onKeyDown = (e)=>{
71
- if (ref && ref.current) // Escape after clicking something can give it keyboard focus
72
- // dismiss tooltip on esc key press
73
- {
74
- if (e.key === "Escape") {
75
- e.stopPropagation();
76
- state.close(true);
77
- }
78
- }
79
- };
80
- if (state.isOpen) {
81
- document.addEventListener("keydown", onKeyDown, true);
82
- return ()=>{
83
- document.removeEventListener("keydown", onKeyDown, true);
84
- };
85
- }
86
- }, [
87
- ref,
88
- state
89
- ]);
90
- let onHoverStart = ()=>{
91
- if (trigger === "focus") return;
92
- // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
93
- // interactions for example, hover will end. When hover is restored after that element disappears,
94
- // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
95
- // is the result of moving the mouse.
96
- if ((0, $kgVYN$getInteractionModality)() === "pointer") isHovered.current = true;
97
- else isHovered.current = false;
98
- handleShow();
99
- };
100
- let onHoverEnd = ()=>{
101
- if (trigger === "focus") return;
102
- // no matter how the trigger is left, we should close the tooltip
103
- isFocused.current = false;
104
- isHovered.current = false;
105
- handleHide();
106
- };
107
- let onPressStart = ()=>{
108
- // no matter how the trigger is pressed, we should close the tooltip
109
- isFocused.current = false;
110
- isHovered.current = false;
111
- handleHide(true);
112
- };
113
- let onFocus = ()=>{
114
- let isVisible = (0, $kgVYN$isFocusVisible)();
115
- if (isVisible) {
116
- isFocused.current = true;
117
- handleShow();
118
- }
119
- };
120
- let onBlur = ()=>{
121
- isFocused.current = false;
122
- isHovered.current = false;
123
- handleHide(true);
124
- };
125
- let { hoverProps: hoverProps } = (0, $kgVYN$useHover)({
126
- isDisabled: isDisabled,
127
- onHoverStart: onHoverStart,
128
- onHoverEnd: onHoverEnd
129
- });
130
- let { focusableProps: focusableProps } = (0, $kgVYN$useFocusable)({
131
- isDisabled: isDisabled,
132
- onFocus: onFocus,
133
- onBlur: onBlur
134
- }, ref);
135
- return {
136
- triggerProps: {
137
- "aria-describedby": state.isOpen ? tooltipId : undefined,
138
- ...(0, $kgVYN$mergeProps)(focusableProps, hoverProps, {
139
- onPointerDown: onPressStart,
140
- onKeyDown: onPressStart
141
- })
142
- },
143
- tooltipProps: {
144
- id: tooltipId
145
- }
146
- };
147
- }
148
-
149
-
150
16
 
151
17
 
152
18
  export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip, $4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
package/dist/main.js CHANGED
@@ -1,26 +1,14 @@
1
- var $aGFp5$reactariautils = require("@react-aria/utils");
2
- var $aGFp5$reactariainteractions = require("@react-aria/interactions");
3
- var $aGFp5$react = require("react");
4
- var $aGFp5$reactariafocus = require("@react-aria/focus");
1
+ var $199fa2aaa84f20b7$exports = require("./useTooltip.main.js");
2
+ var $f017bbc46d58d42a$exports = require("./useTooltipTrigger.main.js");
5
3
 
6
4
 
7
5
  function $parcel$export(e, n, v, s) {
8
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
7
  }
10
8
 
11
- $parcel$export(module.exports, "useTooltip", () => $199fa2aaa84f20b7$export$1c4b08e0eca38426);
12
- $parcel$export(module.exports, "useTooltipTrigger", () => $f017bbc46d58d42a$export$a6da6c504e4bba8b);
9
+ $parcel$export(module.exports, "useTooltip", () => $199fa2aaa84f20b7$exports.useTooltip);
10
+ $parcel$export(module.exports, "useTooltipTrigger", () => $f017bbc46d58d42a$exports.useTooltipTrigger);
13
11
  /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */ /*
24
12
  * Copyright 2020 Adobe. All rights reserved.
25
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
26
14
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -32,128 +20,6 @@ $parcel$export(module.exports, "useTooltipTrigger", () => $f017bbc46d58d42a$expo
32
20
  * governing permissions and limitations under the License.
33
21
  */
34
22
 
35
- function $199fa2aaa84f20b7$export$1c4b08e0eca38426(props, state) {
36
- let domProps = (0, $aGFp5$reactariautils.filterDOMProps)(props, {
37
- labelable: true
38
- });
39
- let { hoverProps: hoverProps } = (0, $aGFp5$reactariainteractions.useHover)({
40
- onHoverStart: ()=>state === null || state === void 0 ? void 0 : state.open(true),
41
- onHoverEnd: ()=>state === null || state === void 0 ? void 0 : state.close()
42
- });
43
- return {
44
- tooltipProps: (0, $aGFp5$reactariautils.mergeProps)(domProps, hoverProps, {
45
- role: "tooltip"
46
- })
47
- };
48
- }
49
-
50
-
51
- /*
52
- * Copyright 2020 Adobe. All rights reserved.
53
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
54
- * you may not use this file except in compliance with the License. You may obtain a copy
55
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
56
- *
57
- * Unless required by applicable law or agreed to in writing, software distributed under
58
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
59
- * OF ANY KIND, either express or implied. See the License for the specific language
60
- * governing permissions and limitations under the License.
61
- */
62
-
63
-
64
-
65
- function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
66
- let { isDisabled: isDisabled, trigger: trigger } = props;
67
- let tooltipId = (0, $aGFp5$reactariautils.useId)();
68
- let isHovered = (0, $aGFp5$react.useRef)(false);
69
- let isFocused = (0, $aGFp5$react.useRef)(false);
70
- let handleShow = ()=>{
71
- if (isHovered.current || isFocused.current) state.open(isFocused.current);
72
- };
73
- let handleHide = (immediate)=>{
74
- if (!isHovered.current && !isFocused.current) state.close(immediate);
75
- };
76
- (0, $aGFp5$react.useEffect)(()=>{
77
- let onKeyDown = (e)=>{
78
- if (ref && ref.current) // Escape after clicking something can give it keyboard focus
79
- // dismiss tooltip on esc key press
80
- {
81
- if (e.key === "Escape") {
82
- e.stopPropagation();
83
- state.close(true);
84
- }
85
- }
86
- };
87
- if (state.isOpen) {
88
- document.addEventListener("keydown", onKeyDown, true);
89
- return ()=>{
90
- document.removeEventListener("keydown", onKeyDown, true);
91
- };
92
- }
93
- }, [
94
- ref,
95
- state
96
- ]);
97
- let onHoverStart = ()=>{
98
- if (trigger === "focus") return;
99
- // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
100
- // interactions for example, hover will end. When hover is restored after that element disappears,
101
- // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
102
- // is the result of moving the mouse.
103
- if ((0, $aGFp5$reactariainteractions.getInteractionModality)() === "pointer") isHovered.current = true;
104
- else isHovered.current = false;
105
- handleShow();
106
- };
107
- let onHoverEnd = ()=>{
108
- if (trigger === "focus") return;
109
- // no matter how the trigger is left, we should close the tooltip
110
- isFocused.current = false;
111
- isHovered.current = false;
112
- handleHide();
113
- };
114
- let onPressStart = ()=>{
115
- // no matter how the trigger is pressed, we should close the tooltip
116
- isFocused.current = false;
117
- isHovered.current = false;
118
- handleHide(true);
119
- };
120
- let onFocus = ()=>{
121
- let isVisible = (0, $aGFp5$reactariainteractions.isFocusVisible)();
122
- if (isVisible) {
123
- isFocused.current = true;
124
- handleShow();
125
- }
126
- };
127
- let onBlur = ()=>{
128
- isFocused.current = false;
129
- isHovered.current = false;
130
- handleHide(true);
131
- };
132
- let { hoverProps: hoverProps } = (0, $aGFp5$reactariainteractions.useHover)({
133
- isDisabled: isDisabled,
134
- onHoverStart: onHoverStart,
135
- onHoverEnd: onHoverEnd
136
- });
137
- let { focusableProps: focusableProps } = (0, $aGFp5$reactariafocus.useFocusable)({
138
- isDisabled: isDisabled,
139
- onFocus: onFocus,
140
- onBlur: onBlur
141
- }, ref);
142
- return {
143
- triggerProps: {
144
- "aria-describedby": state.isOpen ? tooltipId : undefined,
145
- ...(0, $aGFp5$reactariautils.mergeProps)(focusableProps, hoverProps, {
146
- onPointerDown: onPressStart,
147
- onKeyDown: onPressStart
148
- })
149
- },
150
- tooltipProps: {
151
- id: tooltipId
152
- }
153
- };
154
- }
155
-
156
-
157
23
 
158
24
 
159
25
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AAkBM,SAAS,0CAAW,KAAuB,EAAE,KAA2B;IAC7E,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;QAC1B,cAAc,IAAM,kBAAA,4BAAA,MAAO,IAAI,CAAC;QAChC,YAAY,IAAM,kBAAA,4BAAA,MAAO,KAAK;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,gCAAS,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF;;CD/BC;AEVD;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC;IACxH,IAAI,cACF,UAAU,WACV,OAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,2BAAI;IAEpB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IAEvB,IAAI,aAAa;QACf,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,IAAI,CAAC,UAAU,OAAO;IAEhC;IAEA,IAAI,aAAa,CAAC;QAChB,IAAI,CAAC,UAAU,OAAO,IAAI,CAAC,UAAU,OAAO,EAC1C,MAAM,KAAK,CAAC;IAEhB;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,YAAY,CAAC;YACf,IAAI,OAAO,IAAI,OAAO,EACpB,6DAA6D;YAC7D,mCAAmC;YACnC;gBAAA,IAAI,EAAE,GAAG,KAAK,UAAU;oBACtB,EAAE,eAAe;oBACjB,MAAM,KAAK,CAAC;gBACd;YAAA;QAEJ;QACA,IAAI,MAAM,MAAM,EAAE;YAChB,SAAS,gBAAgB,CAAC,WAAW,WAAW;YAChD,OAAO;gBACL,SAAS,mBAAmB,CAAC,WAAW,WAAW;YACrD;QACF;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,IAAI,eAAe;QACjB,IAAI,YAAY,SACd;QAEF,uFAAuF;QACvF,kGAAkG;QAClG,uGAAuG;QACvG,qCAAqC;QACrC,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,UAAU,OAAO,GAAG;aAEpB,UAAU,OAAO,GAAG;QAEtB;IACF;IAEA,IAAI,aAAa;QACf,IAAI,YAAY,SACd;QAEF,iEAAiE;QACjE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB;IACF;IAEA,IAAI,eAAe;QACjB,oEAAoE;QACpE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,CAAA,GAAA,2CAAa;QAC7B,IAAI,WAAW;YACb,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,IAAI,SAAS;QACX,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY;YAC/C,GAAG,CAAA,GAAA,gCAAS,EAAE,gBAAgB,YAAY;gBACxC,eAAe;gBACf,WAAW;YACb,EAAE;QACJ;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF;","sources":["packages/@react-aria/tooltip/src/index.ts","packages/@react-aria/tooltip/src/useTooltip.ts","packages/@react-aria/tooltip/src/useTooltipTrigger.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 */\nexport {useTooltip} from './useTooltip';\nexport {useTooltipTrigger} from './useTooltipTrigger';\nexport type {AriaTooltipProps, TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipAria} from './useTooltip';\nexport type {TooltipTriggerAria} from './useTooltipTrigger';\n","/*\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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n let {hoverProps} = useHover({\n onHoverStart: () => state?.open(true),\n onHoverEnd: () => state?.close()\n });\n\n return {\n tooltipProps: mergeProps(domProps, hoverProps, {\n role: 'tooltip'\n })\n };\n}\n","/*\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 {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\n\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button\n * that shows a description when focused or hovered.\n */\nexport function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement>) : TooltipTriggerAria {\n let {\n isDisabled,\n trigger\n } = props;\n\n let tooltipId = useId();\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n\n let handleShow = () => {\n if (isHovered.current || isFocused.current) {\n state.open(isFocused.current);\n }\n };\n\n let handleHide = (immediate?: boolean) => {\n if (!isHovered.current && !isFocused.current) {\n state.close(immediate);\n }\n };\n\n useEffect(() => {\n let onKeyDown = (e) => {\n if (ref && ref.current) {\n // Escape after clicking something can give it keyboard focus\n // dismiss tooltip on esc key press\n if (e.key === 'Escape') {\n e.stopPropagation();\n state.close(true);\n }\n }\n };\n if (state.isOpen) {\n document.addEventListener('keydown', onKeyDown, true);\n return () => {\n document.removeEventListener('keydown', onKeyDown, true);\n };\n }\n }, [ref, state]);\n\n let onHoverStart = () => {\n if (trigger === 'focus') {\n return;\n }\n // In chrome, if you hover a trigger, then another element obscures it, due to keyboard\n // interactions for example, hover will end. When hover is restored after that element disappears,\n // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover\n // is the result of moving the mouse.\n if (getInteractionModality() === 'pointer') {\n isHovered.current = true;\n } else {\n isHovered.current = false;\n }\n handleShow();\n };\n\n let onHoverEnd = () => {\n if (trigger === 'focus') {\n return;\n }\n // no matter how the trigger is left, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide();\n };\n\n let onPressStart = () => {\n // no matter how the trigger is pressed, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let onFocus = () => {\n let isVisible = isFocusVisible();\n if (isVisible) {\n isFocused.current = true;\n handleShow();\n }\n };\n\n let onBlur = () => {\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {focusableProps} = useFocusable({\n isDisabled,\n onFocus,\n onBlur\n }, ref);\n\n return {\n triggerProps: {\n 'aria-describedby': state.isOpen ? tooltipId : undefined,\n ...mergeProps(focusableProps, hoverProps, {\n onPointerDown: onPressStart,\n onKeyDown: onPressStart\n })\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/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 */\nexport {useTooltip} from './useTooltip';\nexport {useTooltipTrigger} from './useTooltipTrigger';\nexport type {AriaTooltipProps, TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipAria} from './useTooltip';\nexport type {TooltipTriggerAria} from './useTooltipTrigger';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,19 +1,7 @@
1
- import {filterDOMProps as $kgVYN$filterDOMProps, mergeProps as $kgVYN$mergeProps, useId as $kgVYN$useId} from "@react-aria/utils";
2
- import {useHover as $kgVYN$useHover, getInteractionModality as $kgVYN$getInteractionModality, isFocusVisible as $kgVYN$isFocusVisible} from "@react-aria/interactions";
3
- import {useRef as $kgVYN$useRef, useEffect as $kgVYN$useEffect} from "react";
4
- import {useFocusable as $kgVYN$useFocusable} from "@react-aria/focus";
1
+ import {useTooltip as $326e436e94273fe1$export$1c4b08e0eca38426} from "./useTooltip.module.js";
2
+ import {useTooltipTrigger as $4e1b34546679e357$export$a6da6c504e4bba8b} from "./useTooltipTrigger.module.js";
5
3
 
6
4
  /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */ /*
17
5
  * Copyright 2020 Adobe. All rights reserved.
18
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -25,128 +13,6 @@ import {useFocusable as $kgVYN$useFocusable} from "@react-aria/focus";
25
13
  * governing permissions and limitations under the License.
26
14
  */
27
15
 
28
- function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
29
- let domProps = (0, $kgVYN$filterDOMProps)(props, {
30
- labelable: true
31
- });
32
- let { hoverProps: hoverProps } = (0, $kgVYN$useHover)({
33
- onHoverStart: ()=>state === null || state === void 0 ? void 0 : state.open(true),
34
- onHoverEnd: ()=>state === null || state === void 0 ? void 0 : state.close()
35
- });
36
- return {
37
- tooltipProps: (0, $kgVYN$mergeProps)(domProps, hoverProps, {
38
- role: "tooltip"
39
- })
40
- };
41
- }
42
-
43
-
44
- /*
45
- * Copyright 2020 Adobe. All rights reserved.
46
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
47
- * you may not use this file except in compliance with the License. You may obtain a copy
48
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
49
- *
50
- * Unless required by applicable law or agreed to in writing, software distributed under
51
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
52
- * OF ANY KIND, either express or implied. See the License for the specific language
53
- * governing permissions and limitations under the License.
54
- */
55
-
56
-
57
-
58
- function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
59
- let { isDisabled: isDisabled, trigger: trigger } = props;
60
- let tooltipId = (0, $kgVYN$useId)();
61
- let isHovered = (0, $kgVYN$useRef)(false);
62
- let isFocused = (0, $kgVYN$useRef)(false);
63
- let handleShow = ()=>{
64
- if (isHovered.current || isFocused.current) state.open(isFocused.current);
65
- };
66
- let handleHide = (immediate)=>{
67
- if (!isHovered.current && !isFocused.current) state.close(immediate);
68
- };
69
- (0, $kgVYN$useEffect)(()=>{
70
- let onKeyDown = (e)=>{
71
- if (ref && ref.current) // Escape after clicking something can give it keyboard focus
72
- // dismiss tooltip on esc key press
73
- {
74
- if (e.key === "Escape") {
75
- e.stopPropagation();
76
- state.close(true);
77
- }
78
- }
79
- };
80
- if (state.isOpen) {
81
- document.addEventListener("keydown", onKeyDown, true);
82
- return ()=>{
83
- document.removeEventListener("keydown", onKeyDown, true);
84
- };
85
- }
86
- }, [
87
- ref,
88
- state
89
- ]);
90
- let onHoverStart = ()=>{
91
- if (trigger === "focus") return;
92
- // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
93
- // interactions for example, hover will end. When hover is restored after that element disappears,
94
- // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
95
- // is the result of moving the mouse.
96
- if ((0, $kgVYN$getInteractionModality)() === "pointer") isHovered.current = true;
97
- else isHovered.current = false;
98
- handleShow();
99
- };
100
- let onHoverEnd = ()=>{
101
- if (trigger === "focus") return;
102
- // no matter how the trigger is left, we should close the tooltip
103
- isFocused.current = false;
104
- isHovered.current = false;
105
- handleHide();
106
- };
107
- let onPressStart = ()=>{
108
- // no matter how the trigger is pressed, we should close the tooltip
109
- isFocused.current = false;
110
- isHovered.current = false;
111
- handleHide(true);
112
- };
113
- let onFocus = ()=>{
114
- let isVisible = (0, $kgVYN$isFocusVisible)();
115
- if (isVisible) {
116
- isFocused.current = true;
117
- handleShow();
118
- }
119
- };
120
- let onBlur = ()=>{
121
- isFocused.current = false;
122
- isHovered.current = false;
123
- handleHide(true);
124
- };
125
- let { hoverProps: hoverProps } = (0, $kgVYN$useHover)({
126
- isDisabled: isDisabled,
127
- onHoverStart: onHoverStart,
128
- onHoverEnd: onHoverEnd
129
- });
130
- let { focusableProps: focusableProps } = (0, $kgVYN$useFocusable)({
131
- isDisabled: isDisabled,
132
- onFocus: onFocus,
133
- onBlur: onBlur
134
- }, ref);
135
- return {
136
- triggerProps: {
137
- "aria-describedby": state.isOpen ? tooltipId : undefined,
138
- ...(0, $kgVYN$mergeProps)(focusableProps, hoverProps, {
139
- onPointerDown: onPressStart,
140
- onKeyDown: onPressStart
141
- })
142
- },
143
- tooltipProps: {
144
- id: tooltipId
145
- }
146
- };
147
- }
148
-
149
-
150
16
 
151
17
 
152
18
  export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip, $4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AAkBM,SAAS,0CAAW,KAAuB,EAAE,KAA2B;IAC7E,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC1B,cAAc,IAAM,kBAAA,4BAAA,MAAO,IAAI,CAAC;QAChC,YAAY,IAAM,kBAAA,4BAAA,MAAO,KAAK;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,iBAAS,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF;;CD/BC;AEVD;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC;IACxH,IAAI,cACF,UAAU,WACV,OAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,YAAI;IAEpB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IAEvB,IAAI,aAAa;QACf,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,IAAI,CAAC,UAAU,OAAO;IAEhC;IAEA,IAAI,aAAa,CAAC;QAChB,IAAI,CAAC,UAAU,OAAO,IAAI,CAAC,UAAU,OAAO,EAC1C,MAAM,KAAK,CAAC;IAEhB;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,YAAY,CAAC;YACf,IAAI,OAAO,IAAI,OAAO,EACpB,6DAA6D;YAC7D,mCAAmC;YACnC;gBAAA,IAAI,EAAE,GAAG,KAAK,UAAU;oBACtB,EAAE,eAAe;oBACjB,MAAM,KAAK,CAAC;gBACd;YAAA;QAEJ;QACA,IAAI,MAAM,MAAM,EAAE;YAChB,SAAS,gBAAgB,CAAC,WAAW,WAAW;YAChD,OAAO;gBACL,SAAS,mBAAmB,CAAC,WAAW,WAAW;YACrD;QACF;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,IAAI,eAAe;QACjB,IAAI,YAAY,SACd;QAEF,uFAAuF;QACvF,kGAAkG;QAClG,uGAAuG;QACvG,qCAAqC;QACrC,IAAI,CAAA,GAAA,6BAAqB,QAAQ,WAC/B,UAAU,OAAO,GAAG;aAEpB,UAAU,OAAO,GAAG;QAEtB;IACF;IAEA,IAAI,aAAa;QACf,IAAI,YAAY,SACd;QAEF,iEAAiE;QACjE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB;IACF;IAEA,IAAI,eAAe;QACjB,oEAAoE;QACpE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,CAAA,GAAA,qBAAa;QAC7B,IAAI,WAAW;YACb,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,IAAI,SAAS;QACX,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY;YAC/C,GAAG,CAAA,GAAA,iBAAS,EAAE,gBAAgB,YAAY;gBACxC,eAAe;gBACf,WAAW;YACb,EAAE;QACJ;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF;","sources":["packages/@react-aria/tooltip/src/index.ts","packages/@react-aria/tooltip/src/useTooltip.ts","packages/@react-aria/tooltip/src/useTooltipTrigger.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 */\nexport {useTooltip} from './useTooltip';\nexport {useTooltipTrigger} from './useTooltipTrigger';\nexport type {AriaTooltipProps, TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipAria} from './useTooltip';\nexport type {TooltipTriggerAria} from './useTooltipTrigger';\n","/*\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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n let {hoverProps} = useHover({\n onHoverStart: () => state?.open(true),\n onHoverEnd: () => state?.close()\n });\n\n return {\n tooltipProps: mergeProps(domProps, hoverProps, {\n role: 'tooltip'\n })\n };\n}\n","/*\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 {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\n\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button\n * that shows a description when focused or hovered.\n */\nexport function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement>) : TooltipTriggerAria {\n let {\n isDisabled,\n trigger\n } = props;\n\n let tooltipId = useId();\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n\n let handleShow = () => {\n if (isHovered.current || isFocused.current) {\n state.open(isFocused.current);\n }\n };\n\n let handleHide = (immediate?: boolean) => {\n if (!isHovered.current && !isFocused.current) {\n state.close(immediate);\n }\n };\n\n useEffect(() => {\n let onKeyDown = (e) => {\n if (ref && ref.current) {\n // Escape after clicking something can give it keyboard focus\n // dismiss tooltip on esc key press\n if (e.key === 'Escape') {\n e.stopPropagation();\n state.close(true);\n }\n }\n };\n if (state.isOpen) {\n document.addEventListener('keydown', onKeyDown, true);\n return () => {\n document.removeEventListener('keydown', onKeyDown, true);\n };\n }\n }, [ref, state]);\n\n let onHoverStart = () => {\n if (trigger === 'focus') {\n return;\n }\n // In chrome, if you hover a trigger, then another element obscures it, due to keyboard\n // interactions for example, hover will end. When hover is restored after that element disappears,\n // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover\n // is the result of moving the mouse.\n if (getInteractionModality() === 'pointer') {\n isHovered.current = true;\n } else {\n isHovered.current = false;\n }\n handleShow();\n };\n\n let onHoverEnd = () => {\n if (trigger === 'focus') {\n return;\n }\n // no matter how the trigger is left, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide();\n };\n\n let onPressStart = () => {\n // no matter how the trigger is pressed, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let onFocus = () => {\n let isVisible = isFocusVisible();\n if (isVisible) {\n isFocused.current = true;\n handleShow();\n }\n };\n\n let onBlur = () => {\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {focusableProps} = useFocusable({\n isDisabled,\n onFocus,\n onBlur\n }, ref);\n\n return {\n triggerProps: {\n 'aria-describedby': state.isOpen ? tooltipId : undefined,\n ...mergeProps(focusableProps, hoverProps, {\n onPointerDown: onPressStart,\n onKeyDown: onPressStart\n })\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/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 */\nexport {useTooltip} from './useTooltip';\nexport {useTooltipTrigger} from './useTooltipTrigger';\nexport type {AriaTooltipProps, TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipAria} from './useTooltip';\nexport type {TooltipTriggerAria} from './useTooltipTrigger';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,38 @@
1
+ var $1ztb7$reactariautils = require("@react-aria/utils");
2
+ var $1ztb7$reactariainteractions = require("@react-aria/interactions");
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, "useTooltip", () => $199fa2aaa84f20b7$export$1c4b08e0eca38426);
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
+ function $199fa2aaa84f20b7$export$1c4b08e0eca38426(props, state) {
23
+ let domProps = (0, $1ztb7$reactariautils.filterDOMProps)(props, {
24
+ labelable: true
25
+ });
26
+ let { hoverProps: hoverProps } = (0, $1ztb7$reactariainteractions.useHover)({
27
+ onHoverStart: ()=>state === null || state === void 0 ? void 0 : state.open(true),
28
+ onHoverEnd: ()=>state === null || state === void 0 ? void 0 : state.close()
29
+ });
30
+ return {
31
+ tooltipProps: (0, $1ztb7$reactariautils.mergeProps)(domProps, hoverProps, {
32
+ role: "tooltip"
33
+ })
34
+ };
35
+ }
36
+
37
+
38
+ //# sourceMappingURL=useTooltip.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkBM,SAAS,0CAAW,KAAuB,EAAE,KAA2B;IAC7E,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;QAC1B,cAAc,IAAM,kBAAA,4BAAA,MAAO,IAAI,CAAC;QAChC,YAAY,IAAM,kBAAA,4BAAA,MAAO,KAAK;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,gCAAS,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF","sources":["packages/@react-aria/tooltip/src/useTooltip.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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n let {hoverProps} = useHover({\n onHoverStart: () => state?.open(true),\n onHoverEnd: () => state?.close()\n });\n\n return {\n tooltipProps: mergeProps(domProps, hoverProps, {\n role: 'tooltip'\n })\n };\n}\n"],"names":[],"version":3,"file":"useTooltip.main.js.map"}
@@ -0,0 +1,33 @@
1
+ import {filterDOMProps as $kwmr2$filterDOMProps, mergeProps as $kwmr2$mergeProps} from "@react-aria/utils";
2
+ import {useHover as $kwmr2$useHover} from "@react-aria/interactions";
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
+ function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
17
+ let domProps = (0, $kwmr2$filterDOMProps)(props, {
18
+ labelable: true
19
+ });
20
+ let { hoverProps: hoverProps } = (0, $kwmr2$useHover)({
21
+ onHoverStart: ()=>state === null || state === void 0 ? void 0 : state.open(true),
22
+ onHoverEnd: ()=>state === null || state === void 0 ? void 0 : state.close()
23
+ });
24
+ return {
25
+ tooltipProps: (0, $kwmr2$mergeProps)(domProps, hoverProps, {
26
+ role: "tooltip"
27
+ })
28
+ };
29
+ }
30
+
31
+
32
+ export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip};
33
+ //# sourceMappingURL=useTooltip.mjs.map
@@ -0,0 +1,33 @@
1
+ import {filterDOMProps as $kwmr2$filterDOMProps, mergeProps as $kwmr2$mergeProps} from "@react-aria/utils";
2
+ import {useHover as $kwmr2$useHover} from "@react-aria/interactions";
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
+ function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
17
+ let domProps = (0, $kwmr2$filterDOMProps)(props, {
18
+ labelable: true
19
+ });
20
+ let { hoverProps: hoverProps } = (0, $kwmr2$useHover)({
21
+ onHoverStart: ()=>state === null || state === void 0 ? void 0 : state.open(true),
22
+ onHoverEnd: ()=>state === null || state === void 0 ? void 0 : state.close()
23
+ });
24
+ return {
25
+ tooltipProps: (0, $kwmr2$mergeProps)(domProps, hoverProps, {
26
+ role: "tooltip"
27
+ })
28
+ };
29
+ }
30
+
31
+
32
+ export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip};
33
+ //# sourceMappingURL=useTooltip.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkBM,SAAS,0CAAW,KAAuB,EAAE,KAA2B;IAC7E,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC1B,cAAc,IAAM,kBAAA,4BAAA,MAAO,IAAI,CAAC;QAChC,YAAY,IAAM,kBAAA,4BAAA,MAAO,KAAK;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,iBAAS,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF","sources":["packages/@react-aria/tooltip/src/useTooltip.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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n let {hoverProps} = useHover({\n onHoverStart: () => state?.open(true),\n onHoverEnd: () => state?.close()\n });\n\n return {\n tooltipProps: mergeProps(domProps, hoverProps, {\n role: 'tooltip'\n })\n };\n}\n"],"names":[],"version":3,"file":"useTooltip.module.js.map"}
@@ -0,0 +1,118 @@
1
+ var $jCY2B$reactariainteractions = require("@react-aria/interactions");
2
+ var $jCY2B$reactariautils = require("@react-aria/utils");
3
+ var $jCY2B$react = require("react");
4
+ var $jCY2B$reactariafocus = require("@react-aria/focus");
5
+
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
+ }
10
+
11
+ $parcel$export(module.exports, "useTooltipTrigger", () => $f017bbc46d58d42a$export$a6da6c504e4bba8b);
12
+ /*
13
+ * Copyright 2020 Adobe. All rights reserved.
14
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License. You may obtain a copy
16
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software distributed under
19
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
+ * OF ANY KIND, either express or implied. See the License for the specific language
21
+ * governing permissions and limitations under the License.
22
+ */
23
+
24
+
25
+
26
+ function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
27
+ let { isDisabled: isDisabled, trigger: trigger } = props;
28
+ let tooltipId = (0, $jCY2B$reactariautils.useId)();
29
+ let isHovered = (0, $jCY2B$react.useRef)(false);
30
+ let isFocused = (0, $jCY2B$react.useRef)(false);
31
+ let handleShow = ()=>{
32
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
33
+ };
34
+ let handleHide = (immediate)=>{
35
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
36
+ };
37
+ (0, $jCY2B$react.useEffect)(()=>{
38
+ let onKeyDown = (e)=>{
39
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
40
+ // dismiss tooltip on esc key press
41
+ {
42
+ if (e.key === "Escape") {
43
+ e.stopPropagation();
44
+ state.close(true);
45
+ }
46
+ }
47
+ };
48
+ if (state.isOpen) {
49
+ document.addEventListener("keydown", onKeyDown, true);
50
+ return ()=>{
51
+ document.removeEventListener("keydown", onKeyDown, true);
52
+ };
53
+ }
54
+ }, [
55
+ ref,
56
+ state
57
+ ]);
58
+ let onHoverStart = ()=>{
59
+ if (trigger === "focus") return;
60
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
61
+ // interactions for example, hover will end. When hover is restored after that element disappears,
62
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
63
+ // is the result of moving the mouse.
64
+ if ((0, $jCY2B$reactariainteractions.getInteractionModality)() === "pointer") isHovered.current = true;
65
+ else isHovered.current = false;
66
+ handleShow();
67
+ };
68
+ let onHoverEnd = ()=>{
69
+ if (trigger === "focus") return;
70
+ // no matter how the trigger is left, we should close the tooltip
71
+ isFocused.current = false;
72
+ isHovered.current = false;
73
+ handleHide();
74
+ };
75
+ let onPressStart = ()=>{
76
+ // no matter how the trigger is pressed, we should close the tooltip
77
+ isFocused.current = false;
78
+ isHovered.current = false;
79
+ handleHide(true);
80
+ };
81
+ let onFocus = ()=>{
82
+ let isVisible = (0, $jCY2B$reactariainteractions.isFocusVisible)();
83
+ if (isVisible) {
84
+ isFocused.current = true;
85
+ handleShow();
86
+ }
87
+ };
88
+ let onBlur = ()=>{
89
+ isFocused.current = false;
90
+ isHovered.current = false;
91
+ handleHide(true);
92
+ };
93
+ let { hoverProps: hoverProps } = (0, $jCY2B$reactariainteractions.useHover)({
94
+ isDisabled: isDisabled,
95
+ onHoverStart: onHoverStart,
96
+ onHoverEnd: onHoverEnd
97
+ });
98
+ let { focusableProps: focusableProps } = (0, $jCY2B$reactariafocus.useFocusable)({
99
+ isDisabled: isDisabled,
100
+ onFocus: onFocus,
101
+ onBlur: onBlur
102
+ }, ref);
103
+ return {
104
+ triggerProps: {
105
+ "aria-describedby": state.isOpen ? tooltipId : undefined,
106
+ ...(0, $jCY2B$reactariautils.mergeProps)(focusableProps, hoverProps, {
107
+ onPointerDown: onPressStart,
108
+ onKeyDown: onPressStart
109
+ })
110
+ },
111
+ tooltipProps: {
112
+ id: tooltipId
113
+ }
114
+ };
115
+ }
116
+
117
+
118
+ //# sourceMappingURL=useTooltipTrigger.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC;IACxH,IAAI,cACF,UAAU,WACV,OAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,2BAAI;IAEpB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IAEvB,IAAI,aAAa;QACf,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,IAAI,CAAC,UAAU,OAAO;IAEhC;IAEA,IAAI,aAAa,CAAC;QAChB,IAAI,CAAC,UAAU,OAAO,IAAI,CAAC,UAAU,OAAO,EAC1C,MAAM,KAAK,CAAC;IAEhB;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,YAAY,CAAC;YACf,IAAI,OAAO,IAAI,OAAO,EACpB,6DAA6D;YAC7D,mCAAmC;YACnC;gBAAA,IAAI,EAAE,GAAG,KAAK,UAAU;oBACtB,EAAE,eAAe;oBACjB,MAAM,KAAK,CAAC;gBACd;YAAA;QAEJ;QACA,IAAI,MAAM,MAAM,EAAE;YAChB,SAAS,gBAAgB,CAAC,WAAW,WAAW;YAChD,OAAO;gBACL,SAAS,mBAAmB,CAAC,WAAW,WAAW;YACrD;QACF;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,IAAI,eAAe;QACjB,IAAI,YAAY,SACd;QAEF,uFAAuF;QACvF,kGAAkG;QAClG,uGAAuG;QACvG,qCAAqC;QACrC,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,UAAU,OAAO,GAAG;aAEpB,UAAU,OAAO,GAAG;QAEtB;IACF;IAEA,IAAI,aAAa;QACf,IAAI,YAAY,SACd;QAEF,iEAAiE;QACjE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB;IACF;IAEA,IAAI,eAAe;QACjB,oEAAoE;QACpE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,CAAA,GAAA,2CAAa;QAC7B,IAAI,WAAW;YACb,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,IAAI,SAAS;QACX,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY;YAC/C,GAAG,CAAA,GAAA,gCAAS,EAAE,gBAAgB,YAAY;gBACxC,eAAe;gBACf,WAAW;YACb,EAAE;QACJ;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/tooltip/src/useTooltipTrigger.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 {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\n\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button\n * that shows a description when focused or hovered.\n */\nexport function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement>) : TooltipTriggerAria {\n let {\n isDisabled,\n trigger\n } = props;\n\n let tooltipId = useId();\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n\n let handleShow = () => {\n if (isHovered.current || isFocused.current) {\n state.open(isFocused.current);\n }\n };\n\n let handleHide = (immediate?: boolean) => {\n if (!isHovered.current && !isFocused.current) {\n state.close(immediate);\n }\n };\n\n useEffect(() => {\n let onKeyDown = (e) => {\n if (ref && ref.current) {\n // Escape after clicking something can give it keyboard focus\n // dismiss tooltip on esc key press\n if (e.key === 'Escape') {\n e.stopPropagation();\n state.close(true);\n }\n }\n };\n if (state.isOpen) {\n document.addEventListener('keydown', onKeyDown, true);\n return () => {\n document.removeEventListener('keydown', onKeyDown, true);\n };\n }\n }, [ref, state]);\n\n let onHoverStart = () => {\n if (trigger === 'focus') {\n return;\n }\n // In chrome, if you hover a trigger, then another element obscures it, due to keyboard\n // interactions for example, hover will end. When hover is restored after that element disappears,\n // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover\n // is the result of moving the mouse.\n if (getInteractionModality() === 'pointer') {\n isHovered.current = true;\n } else {\n isHovered.current = false;\n }\n handleShow();\n };\n\n let onHoverEnd = () => {\n if (trigger === 'focus') {\n return;\n }\n // no matter how the trigger is left, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide();\n };\n\n let onPressStart = () => {\n // no matter how the trigger is pressed, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let onFocus = () => {\n let isVisible = isFocusVisible();\n if (isVisible) {\n isFocused.current = true;\n handleShow();\n }\n };\n\n let onBlur = () => {\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {focusableProps} = useFocusable({\n isDisabled,\n onFocus,\n onBlur\n }, ref);\n\n return {\n triggerProps: {\n 'aria-describedby': state.isOpen ? tooltipId : undefined,\n ...mergeProps(focusableProps, hoverProps, {\n onPointerDown: onPressStart,\n onKeyDown: onPressStart\n })\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTrigger.main.js.map"}
@@ -0,0 +1,113 @@
1
+ import {getInteractionModality as $6VwSn$getInteractionModality, isFocusVisible as $6VwSn$isFocusVisible, useHover as $6VwSn$useHover} from "@react-aria/interactions";
2
+ import {useId as $6VwSn$useId, mergeProps as $6VwSn$mergeProps} from "@react-aria/utils";
3
+ import {useRef as $6VwSn$useRef, useEffect as $6VwSn$useEffect} from "react";
4
+ import {useFocusable as $6VwSn$useFocusable} from "@react-aria/focus";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
21
+ let { isDisabled: isDisabled, trigger: trigger } = props;
22
+ let tooltipId = (0, $6VwSn$useId)();
23
+ let isHovered = (0, $6VwSn$useRef)(false);
24
+ let isFocused = (0, $6VwSn$useRef)(false);
25
+ let handleShow = ()=>{
26
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
27
+ };
28
+ let handleHide = (immediate)=>{
29
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
30
+ };
31
+ (0, $6VwSn$useEffect)(()=>{
32
+ let onKeyDown = (e)=>{
33
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
34
+ // dismiss tooltip on esc key press
35
+ {
36
+ if (e.key === "Escape") {
37
+ e.stopPropagation();
38
+ state.close(true);
39
+ }
40
+ }
41
+ };
42
+ if (state.isOpen) {
43
+ document.addEventListener("keydown", onKeyDown, true);
44
+ return ()=>{
45
+ document.removeEventListener("keydown", onKeyDown, true);
46
+ };
47
+ }
48
+ }, [
49
+ ref,
50
+ state
51
+ ]);
52
+ let onHoverStart = ()=>{
53
+ if (trigger === "focus") return;
54
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
55
+ // interactions for example, hover will end. When hover is restored after that element disappears,
56
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
57
+ // is the result of moving the mouse.
58
+ if ((0, $6VwSn$getInteractionModality)() === "pointer") isHovered.current = true;
59
+ else isHovered.current = false;
60
+ handleShow();
61
+ };
62
+ let onHoverEnd = ()=>{
63
+ if (trigger === "focus") return;
64
+ // no matter how the trigger is left, we should close the tooltip
65
+ isFocused.current = false;
66
+ isHovered.current = false;
67
+ handleHide();
68
+ };
69
+ let onPressStart = ()=>{
70
+ // no matter how the trigger is pressed, we should close the tooltip
71
+ isFocused.current = false;
72
+ isHovered.current = false;
73
+ handleHide(true);
74
+ };
75
+ let onFocus = ()=>{
76
+ let isVisible = (0, $6VwSn$isFocusVisible)();
77
+ if (isVisible) {
78
+ isFocused.current = true;
79
+ handleShow();
80
+ }
81
+ };
82
+ let onBlur = ()=>{
83
+ isFocused.current = false;
84
+ isHovered.current = false;
85
+ handleHide(true);
86
+ };
87
+ let { hoverProps: hoverProps } = (0, $6VwSn$useHover)({
88
+ isDisabled: isDisabled,
89
+ onHoverStart: onHoverStart,
90
+ onHoverEnd: onHoverEnd
91
+ });
92
+ let { focusableProps: focusableProps } = (0, $6VwSn$useFocusable)({
93
+ isDisabled: isDisabled,
94
+ onFocus: onFocus,
95
+ onBlur: onBlur
96
+ }, ref);
97
+ return {
98
+ triggerProps: {
99
+ "aria-describedby": state.isOpen ? tooltipId : undefined,
100
+ ...(0, $6VwSn$mergeProps)(focusableProps, hoverProps, {
101
+ onPointerDown: onPressStart,
102
+ onKeyDown: onPressStart
103
+ })
104
+ },
105
+ tooltipProps: {
106
+ id: tooltipId
107
+ }
108
+ };
109
+ }
110
+
111
+
112
+ export {$4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
113
+ //# sourceMappingURL=useTooltipTrigger.mjs.map
@@ -0,0 +1,113 @@
1
+ import {getInteractionModality as $6VwSn$getInteractionModality, isFocusVisible as $6VwSn$isFocusVisible, useHover as $6VwSn$useHover} from "@react-aria/interactions";
2
+ import {useId as $6VwSn$useId, mergeProps as $6VwSn$mergeProps} from "@react-aria/utils";
3
+ import {useRef as $6VwSn$useRef, useEffect as $6VwSn$useEffect} from "react";
4
+ import {useFocusable as $6VwSn$useFocusable} from "@react-aria/focus";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
21
+ let { isDisabled: isDisabled, trigger: trigger } = props;
22
+ let tooltipId = (0, $6VwSn$useId)();
23
+ let isHovered = (0, $6VwSn$useRef)(false);
24
+ let isFocused = (0, $6VwSn$useRef)(false);
25
+ let handleShow = ()=>{
26
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
27
+ };
28
+ let handleHide = (immediate)=>{
29
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
30
+ };
31
+ (0, $6VwSn$useEffect)(()=>{
32
+ let onKeyDown = (e)=>{
33
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
34
+ // dismiss tooltip on esc key press
35
+ {
36
+ if (e.key === "Escape") {
37
+ e.stopPropagation();
38
+ state.close(true);
39
+ }
40
+ }
41
+ };
42
+ if (state.isOpen) {
43
+ document.addEventListener("keydown", onKeyDown, true);
44
+ return ()=>{
45
+ document.removeEventListener("keydown", onKeyDown, true);
46
+ };
47
+ }
48
+ }, [
49
+ ref,
50
+ state
51
+ ]);
52
+ let onHoverStart = ()=>{
53
+ if (trigger === "focus") return;
54
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
55
+ // interactions for example, hover will end. When hover is restored after that element disappears,
56
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
57
+ // is the result of moving the mouse.
58
+ if ((0, $6VwSn$getInteractionModality)() === "pointer") isHovered.current = true;
59
+ else isHovered.current = false;
60
+ handleShow();
61
+ };
62
+ let onHoverEnd = ()=>{
63
+ if (trigger === "focus") return;
64
+ // no matter how the trigger is left, we should close the tooltip
65
+ isFocused.current = false;
66
+ isHovered.current = false;
67
+ handleHide();
68
+ };
69
+ let onPressStart = ()=>{
70
+ // no matter how the trigger is pressed, we should close the tooltip
71
+ isFocused.current = false;
72
+ isHovered.current = false;
73
+ handleHide(true);
74
+ };
75
+ let onFocus = ()=>{
76
+ let isVisible = (0, $6VwSn$isFocusVisible)();
77
+ if (isVisible) {
78
+ isFocused.current = true;
79
+ handleShow();
80
+ }
81
+ };
82
+ let onBlur = ()=>{
83
+ isFocused.current = false;
84
+ isHovered.current = false;
85
+ handleHide(true);
86
+ };
87
+ let { hoverProps: hoverProps } = (0, $6VwSn$useHover)({
88
+ isDisabled: isDisabled,
89
+ onHoverStart: onHoverStart,
90
+ onHoverEnd: onHoverEnd
91
+ });
92
+ let { focusableProps: focusableProps } = (0, $6VwSn$useFocusable)({
93
+ isDisabled: isDisabled,
94
+ onFocus: onFocus,
95
+ onBlur: onBlur
96
+ }, ref);
97
+ return {
98
+ triggerProps: {
99
+ "aria-describedby": state.isOpen ? tooltipId : undefined,
100
+ ...(0, $6VwSn$mergeProps)(focusableProps, hoverProps, {
101
+ onPointerDown: onPressStart,
102
+ onKeyDown: onPressStart
103
+ })
104
+ },
105
+ tooltipProps: {
106
+ id: tooltipId
107
+ }
108
+ };
109
+ }
110
+
111
+
112
+ export {$4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
113
+ //# sourceMappingURL=useTooltipTrigger.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC;IACxH,IAAI,cACF,UAAU,WACV,OAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,YAAI;IAEpB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IAEvB,IAAI,aAAa;QACf,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,IAAI,CAAC,UAAU,OAAO;IAEhC;IAEA,IAAI,aAAa,CAAC;QAChB,IAAI,CAAC,UAAU,OAAO,IAAI,CAAC,UAAU,OAAO,EAC1C,MAAM,KAAK,CAAC;IAEhB;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,YAAY,CAAC;YACf,IAAI,OAAO,IAAI,OAAO,EACpB,6DAA6D;YAC7D,mCAAmC;YACnC;gBAAA,IAAI,EAAE,GAAG,KAAK,UAAU;oBACtB,EAAE,eAAe;oBACjB,MAAM,KAAK,CAAC;gBACd;YAAA;QAEJ;QACA,IAAI,MAAM,MAAM,EAAE;YAChB,SAAS,gBAAgB,CAAC,WAAW,WAAW;YAChD,OAAO;gBACL,SAAS,mBAAmB,CAAC,WAAW,WAAW;YACrD;QACF;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,IAAI,eAAe;QACjB,IAAI,YAAY,SACd;QAEF,uFAAuF;QACvF,kGAAkG;QAClG,uGAAuG;QACvG,qCAAqC;QACrC,IAAI,CAAA,GAAA,6BAAqB,QAAQ,WAC/B,UAAU,OAAO,GAAG;aAEpB,UAAU,OAAO,GAAG;QAEtB;IACF;IAEA,IAAI,aAAa;QACf,IAAI,YAAY,SACd;QAEF,iEAAiE;QACjE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB;IACF;IAEA,IAAI,eAAe;QACjB,oEAAoE;QACpE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,CAAA,GAAA,qBAAa;QAC7B,IAAI,WAAW;YACb,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,IAAI,SAAS;QACX,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY;YAC/C,GAAG,CAAA,GAAA,iBAAS,EAAE,gBAAgB,YAAY;gBACxC,eAAe;gBACf,WAAW;YACb,EAAE;QACJ;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/tooltip/src/useTooltipTrigger.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 {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\n\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button\n * that shows a description when focused or hovered.\n */\nexport function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement>) : TooltipTriggerAria {\n let {\n isDisabled,\n trigger\n } = props;\n\n let tooltipId = useId();\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n\n let handleShow = () => {\n if (isHovered.current || isFocused.current) {\n state.open(isFocused.current);\n }\n };\n\n let handleHide = (immediate?: boolean) => {\n if (!isHovered.current && !isFocused.current) {\n state.close(immediate);\n }\n };\n\n useEffect(() => {\n let onKeyDown = (e) => {\n if (ref && ref.current) {\n // Escape after clicking something can give it keyboard focus\n // dismiss tooltip on esc key press\n if (e.key === 'Escape') {\n e.stopPropagation();\n state.close(true);\n }\n }\n };\n if (state.isOpen) {\n document.addEventListener('keydown', onKeyDown, true);\n return () => {\n document.removeEventListener('keydown', onKeyDown, true);\n };\n }\n }, [ref, state]);\n\n let onHoverStart = () => {\n if (trigger === 'focus') {\n return;\n }\n // In chrome, if you hover a trigger, then another element obscures it, due to keyboard\n // interactions for example, hover will end. When hover is restored after that element disappears,\n // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover\n // is the result of moving the mouse.\n if (getInteractionModality() === 'pointer') {\n isHovered.current = true;\n } else {\n isHovered.current = false;\n }\n handleShow();\n };\n\n let onHoverEnd = () => {\n if (trigger === 'focus') {\n return;\n }\n // no matter how the trigger is left, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide();\n };\n\n let onPressStart = () => {\n // no matter how the trigger is pressed, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let onFocus = () => {\n let isVisible = isFocusVisible();\n if (isVisible) {\n isFocused.current = true;\n handleShow();\n }\n };\n\n let onBlur = () => {\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {focusableProps} = useFocusable({\n isDisabled,\n onFocus,\n onBlur\n }, ref);\n\n return {\n triggerProps: {\n 'aria-describedby': state.isOpen ? tooltipId : undefined,\n ...mergeProps(focusableProps, hoverProps, {\n onPointerDown: onPressStart,\n onKeyDown: onPressStart\n })\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTrigger.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/tooltip",
3
- "version": "3.7.2",
3
+ "version": "3.7.3",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,12 +22,12 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.16.2",
26
- "@react-aria/interactions": "^3.21.1",
27
- "@react-aria/utils": "^3.23.2",
28
- "@react-stately/tooltip": "^3.4.7",
29
- "@react-types/shared": "^3.22.1",
30
- "@react-types/tooltip": "^3.4.7",
25
+ "@react-aria/focus": "^3.17.0",
26
+ "@react-aria/interactions": "^3.21.2",
27
+ "@react-aria/utils": "^3.24.0",
28
+ "@react-stately/tooltip": "^3.4.8",
29
+ "@react-types/shared": "^3.23.0",
30
+ "@react-types/tooltip": "^3.4.8",
31
31
  "@swc/helpers": "^0.5.0"
32
32
  },
33
33
  "peerDependencies": {
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "de9f84a22583fc741c29b341d14cd35ef4cca161"
39
+ "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
40
40
  }