@react-aria/tooltip 3.1.3 → 3.1.6
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/main.js +131 -156
- package/dist/main.js.map +1 -1
- package/dist/module.js +127 -143
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/main.js
CHANGED
|
@@ -1,176 +1,151 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var {
|
|
13
|
-
useHover,
|
|
14
|
-
getInteractionModality,
|
|
15
|
-
isFocusVisible,
|
|
16
|
-
usePress
|
|
17
|
-
} = require("@react-aria/interactions");
|
|
18
|
-
|
|
19
|
-
var {
|
|
20
|
-
filterDOMProps,
|
|
21
|
-
mergeProps,
|
|
22
|
-
useId
|
|
23
|
-
} = require("@react-aria/utils");
|
|
24
|
-
|
|
25
|
-
function $parcel$interopDefault(a) {
|
|
26
|
-
return a && a.__esModule ? a.default : a;
|
|
27
|
-
}
|
|
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");
|
|
5
|
+
|
|
6
|
+
function $parcel$exportWildcard(dest, source) {
|
|
7
|
+
Object.keys(source).forEach(function(key) {
|
|
8
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
28
11
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
let {
|
|
37
|
-
hoverProps
|
|
38
|
-
} = useHover({
|
|
39
|
-
onHoverStart: () => state == null ? void 0 : state.open(true),
|
|
40
|
-
onHoverEnd: () => state == null ? void 0 : state.close()
|
|
12
|
+
Object.defineProperty(dest, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return source[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
41
18
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
19
|
+
|
|
20
|
+
return dest;
|
|
21
|
+
}
|
|
22
|
+
function $parcel$export(e, n, v, s) {
|
|
23
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
47
24
|
}
|
|
25
|
+
var $199fa2aaa84f20b7$exports = {};
|
|
48
26
|
|
|
49
|
-
exports
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button
|
|
53
|
-
* that shows a description when focused or hovered.
|
|
54
|
-
*/
|
|
55
|
-
function useTooltipTrigger(props, state, ref) {
|
|
56
|
-
let {
|
|
57
|
-
isDisabled,
|
|
58
|
-
trigger
|
|
59
|
-
} = props;
|
|
60
|
-
let tooltipId = useId();
|
|
61
|
-
let isHovered = useRef(false);
|
|
62
|
-
let isFocused = useRef(false);
|
|
63
|
-
|
|
64
|
-
let handleShow = () => {
|
|
65
|
-
if (isHovered.current || isFocused.current) {
|
|
66
|
-
state.open(isFocused.current);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
27
|
+
$parcel$export($199fa2aaa84f20b7$exports, "useTooltip", () => $199fa2aaa84f20b7$export$1c4b08e0eca38426);
|
|
69
28
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (e.key === 'Escape') {
|
|
82
|
-
state.close(true);
|
|
29
|
+
|
|
30
|
+
function $199fa2aaa84f20b7$export$1c4b08e0eca38426(props, state) {
|
|
31
|
+
let domProps = $aGFp5$reactariautils.filterDOMProps(props, {
|
|
32
|
+
labelable: true
|
|
33
|
+
});
|
|
34
|
+
let { hoverProps: hoverProps } = $aGFp5$reactariainteractions.useHover({
|
|
35
|
+
onHoverStart: ()=>{
|
|
36
|
+
return state === null || state === void 0 ? void 0 : state.open(true);
|
|
37
|
+
},
|
|
38
|
+
onHoverEnd: ()=>{
|
|
39
|
+
return state === null || state === void 0 ? void 0 : state.close();
|
|
83
40
|
}
|
|
84
|
-
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
tooltipProps: $aGFp5$reactariautils.mergeProps(domProps, hoverProps, {
|
|
44
|
+
role: 'tooltip'
|
|
45
|
+
})
|
|
85
46
|
};
|
|
47
|
+
}
|
|
86
48
|
|
|
87
|
-
if (state.isOpen) {
|
|
88
|
-
document.addEventListener('keydown', onKeyDown, true);
|
|
89
|
-
return () => {
|
|
90
|
-
document.removeEventListener('keydown', onKeyDown, true);
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}, [ref, state]);
|
|
94
49
|
|
|
95
|
-
|
|
96
|
-
if (trigger === 'focus') {
|
|
97
|
-
return;
|
|
98
|
-
} // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
|
|
99
|
-
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
100
|
-
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
101
|
-
// is the result of moving the mouse.
|
|
50
|
+
var $f017bbc46d58d42a$exports = {};
|
|
102
51
|
|
|
52
|
+
$parcel$export($f017bbc46d58d42a$exports, "useTooltipTrigger", () => $f017bbc46d58d42a$export$a6da6c504e4bba8b);
|
|
103
53
|
|
|
104
|
-
if (getInteractionModality() === 'pointer') {
|
|
105
|
-
isHovered.current = true;
|
|
106
|
-
} else {
|
|
107
|
-
isHovered.current = false;
|
|
108
|
-
}
|
|
109
54
|
|
|
110
|
-
handleShow();
|
|
111
|
-
};
|
|
112
55
|
|
|
113
|
-
let onHoverEnd = () => {
|
|
114
|
-
if (trigger === 'focus') {
|
|
115
|
-
return;
|
|
116
|
-
} // no matter how the trigger is left, we should close the tooltip
|
|
117
56
|
|
|
118
57
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
58
|
+
function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
59
|
+
let { isDisabled: isDisabled , trigger: trigger } = props;
|
|
60
|
+
let tooltipId = $aGFp5$reactariautils.useId();
|
|
61
|
+
let isHovered = $aGFp5$react.useRef(false);
|
|
62
|
+
let isFocused = $aGFp5$react.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
|
+
$aGFp5$react.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') state.close(true);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (state.isOpen) {
|
|
78
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
79
|
+
return ()=>{
|
|
80
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}, [
|
|
84
|
+
ref,
|
|
85
|
+
state
|
|
86
|
+
]);
|
|
87
|
+
let onHoverStart = ()=>{
|
|
88
|
+
if (trigger === 'focus') return;
|
|
89
|
+
// In chrome, if you hover a trigger, then another element obscures it, due to keyboard
|
|
90
|
+
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
91
|
+
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
92
|
+
// is the result of moving the mouse.
|
|
93
|
+
if ($aGFp5$reactariainteractions.getInteractionModality() === 'pointer') isHovered.current = true;
|
|
94
|
+
else isHovered.current = false;
|
|
95
|
+
handleShow();
|
|
96
|
+
};
|
|
97
|
+
let onHoverEnd = ()=>{
|
|
98
|
+
if (trigger === 'focus') return;
|
|
99
|
+
// no matter how the trigger is left, we should close the tooltip
|
|
100
|
+
isFocused.current = false;
|
|
101
|
+
isHovered.current = false;
|
|
102
|
+
handleHide();
|
|
103
|
+
};
|
|
104
|
+
let onPressStart = ()=>{
|
|
105
|
+
// no matter how the trigger is pressed, we should close the tooltip
|
|
106
|
+
isFocused.current = false;
|
|
107
|
+
isHovered.current = false;
|
|
108
|
+
handleHide(true);
|
|
109
|
+
};
|
|
110
|
+
let onFocus = ()=>{
|
|
111
|
+
let isVisible = $aGFp5$reactariainteractions.isFocusVisible();
|
|
112
|
+
if (isVisible) {
|
|
113
|
+
isFocused.current = true;
|
|
114
|
+
handleShow();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
let onBlur = ()=>{
|
|
118
|
+
isFocused.current = false;
|
|
119
|
+
isHovered.current = false;
|
|
120
|
+
handleHide(true);
|
|
121
|
+
};
|
|
122
|
+
let { hoverProps: hoverProps } = $aGFp5$reactariainteractions.useHover({
|
|
123
|
+
isDisabled: isDisabled,
|
|
124
|
+
onHoverStart: onHoverStart,
|
|
125
|
+
onHoverEnd: onHoverEnd
|
|
126
|
+
});
|
|
127
|
+
let { pressProps: pressProps } = $aGFp5$reactariainteractions.usePress({
|
|
128
|
+
onPressStart: onPressStart
|
|
129
|
+
});
|
|
130
|
+
let { focusableProps: focusableProps } = $aGFp5$reactariafocus.useFocusable({
|
|
131
|
+
isDisabled: isDisabled,
|
|
132
|
+
onFocus: onFocus,
|
|
133
|
+
onBlur: onBlur
|
|
134
|
+
}, ref);
|
|
135
|
+
return {
|
|
136
|
+
triggerProps: {
|
|
137
|
+
'aria-describedby': state.isOpen ? tooltipId : undefined,
|
|
138
|
+
...$aGFp5$reactariautils.mergeProps(focusableProps, hoverProps, pressProps)
|
|
139
|
+
},
|
|
140
|
+
tooltipProps: {
|
|
141
|
+
id: tooltipId
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
123
145
|
|
|
124
|
-
let onPressStart = () => {
|
|
125
|
-
// no matter how the trigger is pressed, we should close the tooltip
|
|
126
|
-
isFocused.current = false;
|
|
127
|
-
isHovered.current = false;
|
|
128
|
-
handleHide(true);
|
|
129
|
-
};
|
|
130
146
|
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
$parcel$exportWildcard(module.exports, $199fa2aaa84f20b7$exports);
|
|
148
|
+
$parcel$exportWildcard(module.exports, $f017bbc46d58d42a$exports);
|
|
133
149
|
|
|
134
|
-
if (isVisible) {
|
|
135
|
-
isFocused.current = true;
|
|
136
|
-
handleShow();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
let onBlur = () => {
|
|
141
|
-
isFocused.current = false;
|
|
142
|
-
isHovered.current = false;
|
|
143
|
-
handleHide(true);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
let {
|
|
147
|
-
hoverProps
|
|
148
|
-
} = useHover({
|
|
149
|
-
isDisabled,
|
|
150
|
-
onHoverStart,
|
|
151
|
-
onHoverEnd
|
|
152
|
-
});
|
|
153
|
-
let {
|
|
154
|
-
pressProps
|
|
155
|
-
} = usePress({
|
|
156
|
-
onPressStart
|
|
157
|
-
});
|
|
158
|
-
let {
|
|
159
|
-
focusableProps
|
|
160
|
-
} = useFocusable({
|
|
161
|
-
isDisabled,
|
|
162
|
-
onFocus,
|
|
163
|
-
onBlur
|
|
164
|
-
}, ref);
|
|
165
|
-
return {
|
|
166
|
-
triggerProps: _babelRuntimeHelpersExtends({
|
|
167
|
-
'aria-describedby': state.isOpen ? tooltipId : undefined
|
|
168
|
-
}, mergeProps(focusableProps, hoverProps, pressProps)),
|
|
169
|
-
tooltipProps: {
|
|
170
|
-
id: tooltipId
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
150
|
|
|
175
|
-
exports.useTooltipTrigger = useTooltipTrigger;
|
|
176
151
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;ACuBD;;;AAGO,SAASG,UAAT,CAAoBC,KAApB,EAA6CC,KAA7C,EAAuF;AAC5F,MAAIC,QAAQ,GAAGC,cAAc,CAACH,KAAD,EAAQ;AAACI,IAAAA,SAAS,EAAE;AAAZ,GAAR,CAA7B;AAEA,MAAI;AAACC,IAAAA;AAAD,MAAeC,QAAQ,CAAC;AAC1BC,IAAAA,YAAY,EAAE,MAAMN,KAAN,oBAAMA,KAAK,CAAEO,IAAP,CAAY,IAAZ,CADM;AAE1BC,IAAAA,UAAU,EAAE,MAAMR,KAAN,oBAAMA,KAAK,CAAES,KAAP;AAFQ,GAAD,CAA3B;AAKA,SAAO;AACLC,IAAAA,YAAY,EAAEC,UAAU,CAACV,QAAD,EAAWG,UAAX,EAAuB;AAC7CQ,MAAAA,IAAI,EAAE;AADuC,KAAvB;AADnB,GAAP;AAKD;;;;ACRD;;;;AAIO,SAASC,iBAAT,CAA2Bd,KAA3B,EAAuDC,KAAvD,EAAmFc,GAAnF,EAAqI;AAC1I,MAAI;AACFC,IAAAA,UADE;AAEFC,IAAAA;AAFE,MAGAjB,KAHJ;AAKA,MAAIkB,SAAS,GAAGC,KAAK,EAArB;AAEA,MAAIC,SAAS,GAAGC,MAAM,CAAC,KAAD,CAAtB;AACA,MAAIC,SAAS,GAAGD,MAAM,CAAC,KAAD,CAAtB;;AAEA,MAAIE,UAAU,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P;AAKL9B,IAAAA,YAAY,EAAE;AACZoC,MAAAA,EAAE,EAAE7B;AADQ;AALT,GAAP;AASD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-aria/tooltip/src/useTooltip.ts","./packages/@react-aria/tooltip/src/useTooltipTrigger.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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 {FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {HTMLAttributes, RefObject, useEffect, useRef} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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<HTMLElement>) : 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 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 {pressProps} = usePress({onPressStart});\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, pressProps)\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","useTooltip","props","state","domProps","filterDOMProps","labelable","hoverProps","useHover","onHoverStart","open","onHoverEnd","close","tooltipProps","mergeProps","role","useTooltipTrigger","ref","isDisabled","trigger","tooltipId","useId","isHovered","useRef","isFocused","handleShow","current","handleHide","immediate","useEffect","onKeyDown","e","key","isOpen","document","addEventListener","removeEventListener","getInteractionModality","onPressStart","onFocus","isVisible","isFocusVisible","onBlur","pressProps","usePress","focusableProps","useFocusable","triggerProps","undefined","id"],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;SC4BgB,yCAAU,CAAC,KAAuB,EAAE,KAA2B,EAAe,CAAC;IAC7F,GAAG,CAAC,QAAQ,GAAG,oCAAc,CAAC,KAAK,EAAE,CAAC;QAAA,SAAS,EAAE,IAAI;IAAA,CAAC;IAEtD,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,qCAAQ,CAAC,CAAC;QAC3B,YAAY;mBAAQ,KAAK,aAAL,KAAK,KAAL,IAAI,CAAJ,CAAW,GAAX,IAAI,CAAJ,CAAW,GAAX,KAAK,CAAE,IAAI,CAAC,IAAI;;QACpC,UAAU;mBAAQ,KAAK,aAAL,KAAK,KAAL,IAAI,CAAJ,CAAY,GAAZ,IAAI,CAAJ,CAAY,GAAZ,KAAK,CAAE,KAAK;;IAChC,CAAC;IAED,MAAM,CAAC,CAAC;QACN,YAAY,EAAE,gCAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;YAC9C,IAAI,EAAE,CAAS;QACjB,CAAC;IACH,CAAC;AACH,CAAC;;;;;;;;;;;SCJe,yCAAiB,CAAC,KAA0B,EAAE,KAA0B,EAAE,GAA2B,EAAuB,CAAC;IAC3I,GAAG,CAAC,CAAC,aACH,UAAU,YACV,OAAO,EACT,CAAC,GAAG,KAAK;IAET,GAAG,CAAC,SAAS,GAAG,2BAAK;IAErB,GAAG,CAAC,SAAS,GAAG,mBAAM,CAAC,KAAK;IAC5B,GAAG,CAAC,SAAS,GAAG,mBAAM,CAAC,KAAK;IAE5B,GAAG,CAAC,UAAU,OA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AAE,EAAE,SAAS;QACf,CAAC;IACH,CAAC;AACH,CAAC;;","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 */\n\nexport * from './useTooltip';\nexport * 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 {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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 {FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {HTMLAttributes, RefObject, useEffect, useRef} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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<HTMLElement>) : 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 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 {pressProps} = usePress({onPressStart});\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, pressProps)\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,150 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Provides the accessibility implementation for a Tooltip component.
|
|
9
|
-
*/
|
|
10
|
-
export function useTooltip(props, state) {
|
|
11
|
-
let domProps = filterDOMProps(props, {
|
|
12
|
-
labelable: true
|
|
13
|
-
});
|
|
14
|
-
let {
|
|
15
|
-
hoverProps
|
|
16
|
-
} = useHover({
|
|
17
|
-
onHoverStart: () => state == null ? void 0 : state.open(true),
|
|
18
|
-
onHoverEnd: () => state == null ? void 0 : state.close()
|
|
19
|
-
});
|
|
20
|
-
return {
|
|
21
|
-
tooltipProps: mergeProps(domProps, hoverProps, {
|
|
22
|
-
role: 'tooltip'
|
|
23
|
-
})
|
|
24
|
-
};
|
|
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, usePress as $kgVYN$usePress} 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";
|
|
5
|
+
|
|
6
|
+
function $parcel$export(e, n, v, s) {
|
|
7
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
25
8
|
}
|
|
9
|
+
var $326e436e94273fe1$exports = {};
|
|
10
|
+
|
|
11
|
+
$parcel$export($326e436e94273fe1$exports, "useTooltip", () => $326e436e94273fe1$export$1c4b08e0eca38426);
|
|
26
12
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let isFocused = useRef(false);
|
|
39
|
-
|
|
40
|
-
let handleShow = () => {
|
|
41
|
-
if (isHovered.current || isFocused.current) {
|
|
42
|
-
state.open(isFocused.current);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
let handleHide = immediate => {
|
|
47
|
-
if (!isHovered.current && !isFocused.current) {
|
|
48
|
-
state.close(immediate);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
let onKeyDown = e => {
|
|
54
|
-
if (ref && ref.current) {
|
|
55
|
-
// Escape after clicking something can give it keyboard focus
|
|
56
|
-
// dismiss tooltip on esc key press
|
|
57
|
-
if (e.key === 'Escape') {
|
|
58
|
-
state.close(true);
|
|
13
|
+
|
|
14
|
+
function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
|
|
15
|
+
let domProps = $kgVYN$filterDOMProps(props, {
|
|
16
|
+
labelable: true
|
|
17
|
+
});
|
|
18
|
+
let { hoverProps: hoverProps } = $kgVYN$useHover({
|
|
19
|
+
onHoverStart: ()=>{
|
|
20
|
+
return state === null || state === void 0 ? void 0 : state.open(true);
|
|
21
|
+
},
|
|
22
|
+
onHoverEnd: ()=>{
|
|
23
|
+
return state === null || state === void 0 ? void 0 : state.close();
|
|
59
24
|
}
|
|
60
|
-
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
tooltipProps: $kgVYN$mergeProps(domProps, hoverProps, {
|
|
28
|
+
role: 'tooltip'
|
|
29
|
+
})
|
|
61
30
|
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
var $4e1b34546679e357$exports = {};
|
|
35
|
+
|
|
36
|
+
$parcel$export($4e1b34546679e357$exports, "useTooltipTrigger", () => $4e1b34546679e357$export$a6da6c504e4bba8b);
|
|
62
37
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
} =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
} =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
43
|
+
let { isDisabled: isDisabled , trigger: trigger } = props;
|
|
44
|
+
let tooltipId = $kgVYN$useId();
|
|
45
|
+
let isHovered = $kgVYN$useRef(false);
|
|
46
|
+
let isFocused = $kgVYN$useRef(false);
|
|
47
|
+
let handleShow = ()=>{
|
|
48
|
+
if (isHovered.current || isFocused.current) state.open(isFocused.current);
|
|
49
|
+
};
|
|
50
|
+
let handleHide = (immediate)=>{
|
|
51
|
+
if (!isHovered.current && !isFocused.current) state.close(immediate);
|
|
52
|
+
};
|
|
53
|
+
$kgVYN$useEffect(()=>{
|
|
54
|
+
let onKeyDown = (e)=>{
|
|
55
|
+
if (ref && ref.current) // Escape after clicking something can give it keyboard focus
|
|
56
|
+
// dismiss tooltip on esc key press
|
|
57
|
+
{
|
|
58
|
+
if (e.key === 'Escape') state.close(true);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
if (state.isOpen) {
|
|
62
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
63
|
+
return ()=>{
|
|
64
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}, [
|
|
68
|
+
ref,
|
|
69
|
+
state
|
|
70
|
+
]);
|
|
71
|
+
let onHoverStart = ()=>{
|
|
72
|
+
if (trigger === 'focus') return;
|
|
73
|
+
// In chrome, if you hover a trigger, then another element obscures it, due to keyboard
|
|
74
|
+
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
75
|
+
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
76
|
+
// is the result of moving the mouse.
|
|
77
|
+
if ($kgVYN$getInteractionModality() === 'pointer') isHovered.current = true;
|
|
78
|
+
else isHovered.current = false;
|
|
79
|
+
handleShow();
|
|
80
|
+
};
|
|
81
|
+
let onHoverEnd = ()=>{
|
|
82
|
+
if (trigger === 'focus') return;
|
|
83
|
+
// no matter how the trigger is left, we should close the tooltip
|
|
84
|
+
isFocused.current = false;
|
|
85
|
+
isHovered.current = false;
|
|
86
|
+
handleHide();
|
|
87
|
+
};
|
|
88
|
+
let onPressStart = ()=>{
|
|
89
|
+
// no matter how the trigger is pressed, we should close the tooltip
|
|
90
|
+
isFocused.current = false;
|
|
91
|
+
isHovered.current = false;
|
|
92
|
+
handleHide(true);
|
|
93
|
+
};
|
|
94
|
+
let onFocus = ()=>{
|
|
95
|
+
let isVisible = $kgVYN$isFocusVisible();
|
|
96
|
+
if (isVisible) {
|
|
97
|
+
isFocused.current = true;
|
|
98
|
+
handleShow();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
let onBlur = ()=>{
|
|
102
|
+
isFocused.current = false;
|
|
103
|
+
isHovered.current = false;
|
|
104
|
+
handleHide(true);
|
|
105
|
+
};
|
|
106
|
+
let { hoverProps: hoverProps } = $kgVYN$useHover({
|
|
107
|
+
isDisabled: isDisabled,
|
|
108
|
+
onHoverStart: onHoverStart,
|
|
109
|
+
onHoverEnd: onHoverEnd
|
|
110
|
+
});
|
|
111
|
+
let { pressProps: pressProps } = $kgVYN$usePress({
|
|
112
|
+
onPressStart: onPressStart
|
|
113
|
+
});
|
|
114
|
+
let { focusableProps: focusableProps } = $kgVYN$useFocusable({
|
|
115
|
+
isDisabled: isDisabled,
|
|
116
|
+
onFocus: onFocus,
|
|
117
|
+
onBlur: onBlur
|
|
118
|
+
}, ref);
|
|
119
|
+
return {
|
|
120
|
+
triggerProps: {
|
|
121
|
+
'aria-describedby': state.isOpen ? tooltipId : undefined,
|
|
122
|
+
...$kgVYN$mergeProps(focusableProps, hoverProps, pressProps)
|
|
123
|
+
},
|
|
124
|
+
tooltipProps: {
|
|
125
|
+
id: tooltipId
|
|
126
|
+
}
|
|
127
|
+
};
|
|
149
128
|
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip, $4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
|
|
150
134
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;SC4BgB,yCAAU,CAAC,KAAuB,EAAE,KAA2B,EAAe,CAAC;IAC7F,GAAG,CAAC,QAAQ,GAAG,qBAAc,CAAC,KAAK,EAAE,CAAC;QAAA,SAAS,EAAE,IAAI;IAAA,CAAC;IAEtD,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,eAAQ,CAAC,CAAC;QAC3B,YAAY;mBAAQ,KAAK,aAAL,KAAK,KAAL,IAA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AAS,CAAC,OAAO,GAAG,KAAK;QACzB,SAAS,CAAC,OAAO,GAAG,KAAK;QACzB,UAAU,CAAC,IAAI;IACjB,CAAC;IAED,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,eAAQ,CAAC,CAAC;oBAC3B,UAAU;sBACV,YAAY;oBACZ,UAAU;IACZ,CAAC;IAED,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,eAAQ,CAAC,CAAC;sBAAA,YAAY;IAAA,CAAC;IAE1C,GAAG,CAAC,CAAC,iBAAA,cAAc,EAAA,CAAC,GAAG,mBAAY,CAAC,CAAC;oBACnC,UAAU;iBACV,OAAO;gBACP,MAAM;IACR,CAAC,EAAE,GAAG;IAEN,MAAM,CAAC,CAAC;QACN,YAAY,EAAE,CAAC;YACb,CAAkB,mBAAE,KAAK,CAAC,MAAM,GAAG,SAAS,GAAG,SAAS;eACrD,iBAAU,CAAC,cAAc,EAAE,UAAU,EAAE,UAAU;QACtD,CAAC;QACD,YAAY,EAAE,CAAC;YACb,EAAE,EAAE,SAAS;QACf,CAAC;IACH,CAAC;AACH,CAAC;;","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 */\n\nexport * from './useTooltip';\nexport * 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 {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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 {FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {HTMLAttributes, RefObject, useEffect, useRef} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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<HTMLElement>) : 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 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 {pressProps} = usePress({onPressStart});\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, pressProps)\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAkBA;IACE;;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,CAAA;CAC1C;AAED;;GAEG;AACH,2BAA2B,KAAK,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,WAAW,CAa5F;ACpBD;IACE;;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IAElF;;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,CAAA;CAC1C;AAED;;;GAGG;AACH,kCAAkC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAI,kBAAkB,CA+G1I","sources":["packages/@react-aria/tooltip/src/packages/@react-aria/tooltip/src/useTooltip.ts","packages/@react-aria/tooltip/src/packages/@react-aria/tooltip/src/useTooltipTrigger.ts","packages/@react-aria/tooltip/src/packages/@react-aria/tooltip/src/index.ts","packages/@react-aria/tooltip/src/index.ts"],"sourcesContent":[null,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 * from './useTooltip';\nexport * from './useTooltipTrigger';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/tooltip",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/focus": "^3.
|
|
22
|
-
"@react-aria/interactions": "^3.
|
|
23
|
-
"@react-aria/utils": "^3.
|
|
24
|
-
"@react-stately/tooltip": "^3.0.
|
|
25
|
-
"@react-types/shared": "^3.
|
|
26
|
-
"@react-types/tooltip": "^3.1.
|
|
21
|
+
"@react-aria/focus": "^3.5.3",
|
|
22
|
+
"@react-aria/interactions": "^3.8.2",
|
|
23
|
+
"@react-aria/utils": "^3.11.3",
|
|
24
|
+
"@react-stately/tooltip": "^3.0.8",
|
|
25
|
+
"@react-types/shared": "^3.11.2",
|
|
26
|
+
"@react-types/tooltip": "^3.1.5"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "ed8d8d984c2f7f2c31e8b18795b97858a95e4729"
|
|
35
35
|
}
|