@react-aria/tooltip 3.3.4 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/import.mjs +155 -0
  2. package/package.json +13 -8
@@ -0,0 +1,155 @@
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
+ /*
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
+ * Copyright 2020 Adobe. All rights reserved.
18
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License. You may obtain a copy
20
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software distributed under
23
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
24
+ * OF ANY KIND, either express or implied. See the License for the specific language
25
+ * governing permissions and limitations under the License.
26
+ */
27
+
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: ()=>{
34
+ return state === null || state === void 0 ? void 0 : state.open(true);
35
+ },
36
+ onHoverEnd: ()=>{
37
+ return state === null || state === void 0 ? void 0 : state.close();
38
+ }
39
+ });
40
+ return {
41
+ tooltipProps: (0, $kgVYN$mergeProps)(domProps, hoverProps, {
42
+ role: "tooltip"
43
+ })
44
+ };
45
+ }
46
+
47
+
48
+ /*
49
+ * Copyright 2020 Adobe. All rights reserved.
50
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
51
+ * you may not use this file except in compliance with the License. You may obtain a copy
52
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
53
+ *
54
+ * Unless required by applicable law or agreed to in writing, software distributed under
55
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
56
+ * OF ANY KIND, either express or implied. See the License for the specific language
57
+ * governing permissions and limitations under the License.
58
+ */
59
+
60
+
61
+
62
+
63
+ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
64
+ let { isDisabled: isDisabled , trigger: trigger } = props;
65
+ let tooltipId = (0, $kgVYN$useId)();
66
+ let isHovered = (0, $kgVYN$useRef)(false);
67
+ let isFocused = (0, $kgVYN$useRef)(false);
68
+ let handleShow = ()=>{
69
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
70
+ };
71
+ let handleHide = (immediate)=>{
72
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
73
+ };
74
+ (0, $kgVYN$useEffect)(()=>{
75
+ let onKeyDown = (e)=>{
76
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
77
+ // dismiss tooltip on esc key press
78
+ {
79
+ if (e.key === "Escape") state.close(true);
80
+ }
81
+ };
82
+ if (state.isOpen) {
83
+ document.addEventListener("keydown", onKeyDown, true);
84
+ return ()=>{
85
+ document.removeEventListener("keydown", onKeyDown, true);
86
+ };
87
+ }
88
+ }, [
89
+ ref,
90
+ state
91
+ ]);
92
+ let onHoverStart = ()=>{
93
+ if (trigger === "focus") return;
94
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
95
+ // interactions for example, hover will end. When hover is restored after that element disappears,
96
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
97
+ // is the result of moving the mouse.
98
+ if ((0, $kgVYN$getInteractionModality)() === "pointer") isHovered.current = true;
99
+ else isHovered.current = false;
100
+ handleShow();
101
+ };
102
+ let onHoverEnd = ()=>{
103
+ if (trigger === "focus") return;
104
+ // no matter how the trigger is left, we should close the tooltip
105
+ isFocused.current = false;
106
+ isHovered.current = false;
107
+ handleHide();
108
+ };
109
+ let onPressStart = ()=>{
110
+ // no matter how the trigger is pressed, we should close the tooltip
111
+ isFocused.current = false;
112
+ isHovered.current = false;
113
+ handleHide(true);
114
+ };
115
+ let onFocus = ()=>{
116
+ let isVisible = (0, $kgVYN$isFocusVisible)();
117
+ if (isVisible) {
118
+ isFocused.current = true;
119
+ handleShow();
120
+ }
121
+ };
122
+ let onBlur = ()=>{
123
+ isFocused.current = false;
124
+ isHovered.current = false;
125
+ handleHide(true);
126
+ };
127
+ let { hoverProps: hoverProps } = (0, $kgVYN$useHover)({
128
+ isDisabled: isDisabled,
129
+ onHoverStart: onHoverStart,
130
+ onHoverEnd: onHoverEnd
131
+ });
132
+ let { pressProps: pressProps } = (0, $kgVYN$usePress)({
133
+ onPressStart: onPressStart
134
+ });
135
+ let { focusableProps: focusableProps } = (0, $kgVYN$useFocusable)({
136
+ isDisabled: isDisabled,
137
+ onFocus: onFocus,
138
+ onBlur: onBlur
139
+ }, ref);
140
+ return {
141
+ triggerProps: {
142
+ "aria-describedby": state.isOpen ? tooltipId : undefined,
143
+ ...(0, $kgVYN$mergeProps)(focusableProps, hoverProps, pressProps)
144
+ },
145
+ tooltipProps: {
146
+ id: tooltipId
147
+ }
148
+ };
149
+ }
150
+
151
+
152
+
153
+
154
+ export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip, $4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
155
+ //# sourceMappingURL=module.js.map
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@react-aria/tooltip",
3
- "version": "3.3.4",
3
+ "version": "3.4.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
8
13
  "types": "dist/types.d.ts",
9
14
  "source": "src/index.ts",
10
15
  "files": [
@@ -17,12 +22,12 @@
17
22
  "url": "https://github.com/adobe/react-spectrum"
18
23
  },
19
24
  "dependencies": {
20
- "@react-aria/focus": "^3.10.1",
21
- "@react-aria/interactions": "^3.13.1",
22
- "@react-aria/utils": "^3.14.2",
23
- "@react-stately/tooltip": "^3.2.4",
24
- "@react-types/shared": "^3.16.0",
25
- "@react-types/tooltip": "^3.2.5",
25
+ "@react-aria/focus": "^3.11.0",
26
+ "@react-aria/interactions": "^3.14.0",
27
+ "@react-aria/utils": "^3.15.0",
28
+ "@react-stately/tooltip": "^3.3.0",
29
+ "@react-types/shared": "^3.17.0",
30
+ "@react-types/tooltip": "^3.3.0",
26
31
  "@swc/helpers": "^0.4.14"
27
32
  },
28
33
  "peerDependencies": {
@@ -31,5 +36,5 @@
31
36
  "publishConfig": {
32
37
  "access": "public"
33
38
  },
34
- "gitHead": "5480d76bd815e239366f92852c76b6831ad2a4fd"
39
+ "gitHead": "a0efee84aa178cb1a202951dfd6d8de02b292307"
35
40
  }