@khanacademy/wonder-blocks-tooltip 1.4.5 → 1.4.7
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/CHANGELOG.md +43 -0
- package/dist/components/tooltip-anchor.d.ts +85 -0
- package/dist/components/tooltip-anchor.js.flow +98 -0
- package/dist/components/tooltip-bubble.d.ts +36 -0
- package/dist/components/tooltip-bubble.js.flow +72 -0
- package/dist/components/tooltip-content.d.ts +33 -0
- package/dist/components/tooltip-content.js.flow +44 -0
- package/dist/components/tooltip-popper.d.ts +32 -0
- package/dist/components/tooltip-popper.js.flow +39 -0
- package/dist/components/tooltip-tail.d.ts +57 -0
- package/dist/components/tooltip-tail.js.flow +77 -0
- package/dist/components/tooltip.d.ts +150 -0
- package/dist/components/tooltip.js.flow +159 -0
- package/dist/es/index.js +220 -273
- package/dist/index.d.ts +8 -0
- package/dist/index.js +234 -288
- package/dist/index.js.flow +20 -2
- package/dist/util/active-tracker.d.ts +61 -0
- package/dist/util/active-tracker.js.flow +71 -0
- package/dist/util/constants.d.ts +6 -0
- package/dist/util/constants.js.flow +13 -0
- package/dist/util/ref-tracker.d.ts +16 -0
- package/dist/util/ref-tracker.js.flow +16 -0
- package/dist/util/types.d.ts +11 -0
- package/dist/util/types.js.flow +36 -0
- package/package.json +9 -9
- package/src/components/__tests__/{tooltip-anchor.test.js → tooltip-anchor.test.tsx} +42 -52
- package/src/components/__tests__/{tooltip-bubble.test.js → tooltip-bubble.test.tsx} +5 -5
- package/src/components/__tests__/{tooltip-popper.test.js → tooltip-popper.test.tsx} +16 -13
- package/src/components/__tests__/{tooltip-tail.test.js → tooltip-tail.test.tsx} +7 -6
- package/src/components/__tests__/{tooltip.integration.test.js → tooltip.integration.test.tsx} +1 -2
- package/src/components/__tests__/{tooltip.test.js → tooltip.test.tsx} +11 -9
- package/src/components/{tooltip-anchor.js → tooltip-anchor.tsx} +29 -30
- package/src/components/{tooltip-bubble.js → tooltip-bubble.tsx} +20 -32
- package/src/components/{tooltip-content.js → tooltip-content.tsx} +8 -10
- package/src/components/{tooltip-popper.js → tooltip-popper.tsx} +17 -17
- package/src/components/{tooltip-tail.js → tooltip-tail.tsx} +29 -33
- package/src/components/{tooltip.js → tooltip.tsx} +40 -44
- package/src/index.ts +11 -0
- package/src/util/__tests__/{active-tracker.test.js → active-tracker.test.ts} +2 -3
- package/src/util/__tests__/{ref-tracker.test.js → ref-tracker.test.tsx} +14 -8
- package/src/util/{active-tracker.js → active-tracker.ts} +1 -2
- package/src/util/{constants.js → constants.ts} +0 -1
- package/src/util/{ref-tracker.js → ref-tracker.ts} +14 -7
- package/src/util/types.ts +32 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/__docs__/tooltip-content.stories.js +0 -89
- package/src/components/__docs__/tooltip.argtypes.js +0 -15
- package/src/components/__docs__/tooltip.stories.js +0 -335
- package/src/index.js +0 -12
- package/src/util/types.js +0 -29
- /package/src/util/__tests__/__snapshots__/{active-tracker.test.js.snap → active-tracker.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{ref-tracker.test.js.snap → ref-tracker.test.tsx.snap} +0 -0
package/dist/es/index.js
CHANGED
|
@@ -2,119 +2,120 @@ import * as React from 'react';
|
|
|
2
2
|
import * as ReactDOM from 'react-dom';
|
|
3
3
|
import { Text as Text$1, View, UniqueIDProvider } from '@khanacademy/wonder-blocks-core';
|
|
4
4
|
import { maybeGetPortalMountedModalHostElement } from '@khanacademy/wonder-blocks-modal';
|
|
5
|
-
import {
|
|
5
|
+
import { css, StyleSheet } from 'aphrodite';
|
|
6
6
|
import Colors from '@khanacademy/wonder-blocks-color';
|
|
7
7
|
import Spacing from '@khanacademy/wonder-blocks-spacing';
|
|
8
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
9
8
|
import { Strut } from '@khanacademy/wonder-blocks-layout';
|
|
10
9
|
import { HeadingSmall, LabelMedium } from '@khanacademy/wonder-blocks-typography';
|
|
11
10
|
import { Popper } from 'react-popper';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function _setPrototypeOf(o, p) {
|
|
13
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
14
|
+
o.__proto__ = p;
|
|
15
|
+
return o;
|
|
16
|
+
};
|
|
17
|
+
return _setPrototypeOf(o, p);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _inheritsLoose(subClass, superClass) {
|
|
21
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
22
|
+
subClass.prototype.constructor = subClass;
|
|
23
|
+
_setPrototypeOf(subClass, superClass);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let ActiveTracker = function () {
|
|
27
|
+
function ActiveTracker() {
|
|
15
28
|
this._subscribers = [];
|
|
29
|
+
this._active = void 0;
|
|
16
30
|
}
|
|
17
|
-
|
|
18
|
-
_getIndex(who) {
|
|
31
|
+
var _proto = ActiveTracker.prototype;
|
|
32
|
+
_proto._getIndex = function _getIndex(who) {
|
|
19
33
|
return this._subscribers.findIndex(v => v === who);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
steal(who) {
|
|
34
|
+
};
|
|
35
|
+
_proto.steal = function steal(who) {
|
|
23
36
|
const wasActive = !!this._active;
|
|
24
37
|
this._active = true;
|
|
25
|
-
|
|
26
38
|
for (const anchor of this._subscribers) {
|
|
27
39
|
if (anchor === who) {
|
|
28
40
|
continue;
|
|
29
41
|
}
|
|
30
|
-
|
|
31
42
|
anchor.activeStateStolen();
|
|
32
43
|
}
|
|
33
|
-
|
|
34
44
|
return wasActive;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
giveup() {
|
|
45
|
+
};
|
|
46
|
+
_proto.giveup = function giveup() {
|
|
38
47
|
this._active = false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
subscribe(who) {
|
|
48
|
+
};
|
|
49
|
+
_proto.subscribe = function subscribe(who) {
|
|
42
50
|
if (this._getIndex(who) >= 0) {
|
|
43
51
|
throw new Error("Already subscribed.");
|
|
44
52
|
}
|
|
45
|
-
|
|
46
53
|
this._subscribers.push(who);
|
|
47
|
-
|
|
48
54
|
const unsubscribe = () => {
|
|
49
55
|
const index = this._getIndex(who);
|
|
50
|
-
|
|
51
56
|
this._subscribers.splice(index, 1);
|
|
52
57
|
};
|
|
53
|
-
|
|
54
58
|
return unsubscribe;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
59
|
+
};
|
|
60
|
+
return ActiveTracker;
|
|
61
|
+
}();
|
|
58
62
|
|
|
59
63
|
const TooltipAppearanceDelay = 100;
|
|
60
64
|
const TooltipDisappearanceDelay = 75;
|
|
61
65
|
|
|
62
66
|
const TRACKER = new ActiveTracker();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
let TooltipAnchor = function (_ref) {
|
|
68
|
+
_inheritsLoose(TooltipAnchor, _ref);
|
|
69
|
+
function TooltipAnchor(props) {
|
|
70
|
+
var _this;
|
|
71
|
+
_this = _ref.call(this, props) || this;
|
|
72
|
+
_this._weSetFocusivity = void 0;
|
|
73
|
+
_this._anchorNode = void 0;
|
|
74
|
+
_this._focused = void 0;
|
|
75
|
+
_this._hovered = void 0;
|
|
76
|
+
_this._stolenFromUs = void 0;
|
|
77
|
+
_this._unsubscribeFromTracker = void 0;
|
|
78
|
+
_this._timeoutID = void 0;
|
|
79
|
+
_this.activeStateStolen = () => {
|
|
80
|
+
_this._stolenFromUs = _this.state.active || !!_this._timeoutID;
|
|
81
|
+
_this._focused = false;
|
|
82
|
+
_this._setActiveState(false, true);
|
|
72
83
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this._updateActiveState(this._hovered, true);
|
|
84
|
+
_this._handleFocusIn = () => {
|
|
85
|
+
_this._updateActiveState(_this._hovered, true);
|
|
76
86
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this._updateActiveState(this._hovered, false);
|
|
87
|
+
_this._handleFocusOut = () => {
|
|
88
|
+
_this._updateActiveState(_this._hovered, false);
|
|
80
89
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this._updateActiveState(true, this._focused);
|
|
90
|
+
_this._handleMouseEnter = () => {
|
|
91
|
+
_this._updateActiveState(true, _this._focused);
|
|
84
92
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this._updateActiveState(false, this._focused);
|
|
93
|
+
_this._handleMouseLeave = () => {
|
|
94
|
+
_this._updateActiveState(false, _this._focused);
|
|
88
95
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (e.key === "Escape" && this.state.active) {
|
|
96
|
+
_this._handleKeyUp = e => {
|
|
97
|
+
if (e.key === "Escape" && _this.state.active) {
|
|
92
98
|
e.preventDefault();
|
|
93
99
|
e.stopPropagation();
|
|
94
|
-
|
|
95
|
-
this._updateActiveState(false, false);
|
|
100
|
+
_this._updateActiveState(false, false);
|
|
96
101
|
}
|
|
97
102
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.state = {
|
|
103
|
+
_this._focused = false;
|
|
104
|
+
_this._hovered = false;
|
|
105
|
+
_this.state = {
|
|
102
106
|
active: false
|
|
103
107
|
};
|
|
108
|
+
return _this;
|
|
104
109
|
}
|
|
105
|
-
|
|
106
|
-
componentDidMount() {
|
|
110
|
+
var _proto = TooltipAnchor.prototype;
|
|
111
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
107
112
|
const anchorNode = ReactDOM.findDOMNode(this);
|
|
108
|
-
|
|
109
113
|
if (anchorNode instanceof Text) {
|
|
110
114
|
throw new Error("TooltipAnchor must be applied to an Element. Text content is not supported.");
|
|
111
115
|
}
|
|
112
|
-
|
|
113
116
|
this._unsubscribeFromTracker = TRACKER.subscribe(this);
|
|
114
117
|
this._anchorNode = anchorNode;
|
|
115
|
-
|
|
116
118
|
this._updateFocusivity();
|
|
117
|
-
|
|
118
119
|
if (anchorNode) {
|
|
119
120
|
anchorNode.addEventListener("focusin", this._handleFocusIn);
|
|
120
121
|
anchorNode.addEventListener("focusout", this._handleFocusOut);
|
|
@@ -122,47 +123,37 @@ class TooltipAnchor extends React.Component {
|
|
|
122
123
|
anchorNode.addEventListener("mouseleave", this._handleMouseLeave);
|
|
123
124
|
this.props.anchorRef(this._anchorNode);
|
|
124
125
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
componentDidUpdate(prevProps) {
|
|
126
|
+
};
|
|
127
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
128
128
|
if (prevProps.forceAnchorFocusivity !== this.props.forceAnchorFocusivity || prevProps.children !== this.props.children) {
|
|
129
129
|
this._updateFocusivity();
|
|
130
130
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
componentWillUnmount() {
|
|
131
|
+
};
|
|
132
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
134
133
|
if (this._unsubscribeFromTracker) {
|
|
135
134
|
this._unsubscribeFromTracker();
|
|
136
135
|
}
|
|
137
|
-
|
|
138
136
|
this._clearPendingAction();
|
|
139
|
-
|
|
140
137
|
const anchorNode = this._anchorNode;
|
|
141
|
-
|
|
142
138
|
if (anchorNode) {
|
|
143
139
|
anchorNode.removeEventListener("focusin", this._handleFocusIn);
|
|
144
140
|
anchorNode.removeEventListener("focusout", this._handleFocusOut);
|
|
145
141
|
anchorNode.removeEventListener("mouseenter", this._handleMouseEnter);
|
|
146
142
|
anchorNode.removeEventListener("mouseleave", this._handleMouseLeave);
|
|
147
143
|
}
|
|
148
|
-
|
|
149
144
|
if (this.state.active) {
|
|
150
145
|
document.removeEventListener("keyup", this._handleKeyUp);
|
|
151
146
|
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
_updateFocusivity() {
|
|
147
|
+
};
|
|
148
|
+
_proto._updateFocusivity = function _updateFocusivity() {
|
|
155
149
|
const anchorNode = this._anchorNode;
|
|
156
|
-
|
|
157
150
|
if (!anchorNode) {
|
|
158
151
|
return;
|
|
159
152
|
}
|
|
160
|
-
|
|
161
153
|
const {
|
|
162
154
|
forceAnchorFocusivity
|
|
163
155
|
} = this.props;
|
|
164
156
|
const currentTabIndex = anchorNode.getAttribute("tabindex");
|
|
165
|
-
|
|
166
157
|
if (forceAnchorFocusivity && !currentTabIndex) {
|
|
167
158
|
anchorNode.setAttribute("tabindex", "0");
|
|
168
159
|
this._weSetFocusivity = true;
|
|
@@ -172,95 +163,99 @@ class TooltipAnchor extends React.Component {
|
|
|
172
163
|
this._weSetFocusivity = false;
|
|
173
164
|
}
|
|
174
165
|
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
_updateActiveState(hovered, focused) {
|
|
166
|
+
};
|
|
167
|
+
_proto._updateActiveState = function _updateActiveState(hovered, focused) {
|
|
178
168
|
this._hovered = hovered;
|
|
179
169
|
this._focused = focused;
|
|
180
|
-
|
|
181
170
|
this._setActiveState(hovered || focused);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
_clearPendingAction() {
|
|
171
|
+
};
|
|
172
|
+
_proto._clearPendingAction = function _clearPendingAction() {
|
|
185
173
|
if (this._timeoutID) {
|
|
186
174
|
clearTimeout(this._timeoutID);
|
|
187
175
|
this._timeoutID = null;
|
|
188
176
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
_setActiveState(active, instant) {
|
|
177
|
+
};
|
|
178
|
+
_proto._setActiveState = function _setActiveState(active, instant) {
|
|
192
179
|
if (this._stolenFromUs || active !== this.state.active || !this.state.active && this._timeoutID) {
|
|
193
180
|
this._clearPendingAction();
|
|
194
181
|
} else if (active === this.state.active && !this._timeoutID) {
|
|
195
182
|
return;
|
|
196
183
|
}
|
|
197
|
-
|
|
198
184
|
instant = instant || active && TRACKER.steal(this);
|
|
199
|
-
|
|
200
185
|
if (instant) {
|
|
201
186
|
if (active) {
|
|
202
187
|
document.addEventListener("keyup", this._handleKeyUp);
|
|
203
188
|
} else {
|
|
204
189
|
document.removeEventListener("keyup", this._handleKeyUp);
|
|
205
190
|
}
|
|
206
|
-
|
|
207
191
|
this.setState({
|
|
208
192
|
active
|
|
209
193
|
});
|
|
210
194
|
this.props.onActiveChanged(active);
|
|
211
|
-
|
|
212
195
|
if (!this._stolenFromUs && !active) {
|
|
213
196
|
TRACKER.giveup();
|
|
214
197
|
}
|
|
215
|
-
|
|
216
198
|
this._stolenFromUs = false;
|
|
217
199
|
} else {
|
|
218
200
|
const delay = active ? TooltipAppearanceDelay : TooltipDisappearanceDelay;
|
|
219
201
|
this._timeoutID = setTimeout(() => {
|
|
220
202
|
this._timeoutID = null;
|
|
221
|
-
|
|
222
203
|
this._setActiveState(active, true);
|
|
223
204
|
}, delay);
|
|
224
205
|
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
_renderAnchorableChildren() {
|
|
206
|
+
};
|
|
207
|
+
_proto._renderAnchorableChildren = function _renderAnchorableChildren() {
|
|
228
208
|
const {
|
|
229
209
|
children
|
|
230
210
|
} = this.props;
|
|
231
211
|
return typeof children === "string" ? React.createElement(Text$1, null, children) : children;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
_renderAccessibleChildren(ids) {
|
|
212
|
+
};
|
|
213
|
+
_proto._renderAccessibleChildren = function _renderAccessibleChildren(ids) {
|
|
235
214
|
const anchorableChildren = this._renderAnchorableChildren();
|
|
236
|
-
|
|
237
215
|
return React.cloneElement(anchorableChildren, {
|
|
238
216
|
"aria-describedby": ids.get(TooltipAnchor.ariaContentId)
|
|
239
217
|
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
render() {
|
|
218
|
+
};
|
|
219
|
+
_proto.render = function render() {
|
|
243
220
|
if (this.props.ids) {
|
|
244
221
|
return this._renderAccessibleChildren(this.props.ids);
|
|
245
222
|
}
|
|
246
|
-
|
|
247
223
|
return this._renderAnchorableChildren();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
}
|
|
224
|
+
};
|
|
225
|
+
return TooltipAnchor;
|
|
226
|
+
}(React.Component);
|
|
251
227
|
TooltipAnchor.defaultProps = {
|
|
252
228
|
forceAnchorFocusivity: true
|
|
253
229
|
};
|
|
254
230
|
TooltipAnchor.ariaContentId = "aria-content";
|
|
255
231
|
|
|
232
|
+
function _extends() {
|
|
233
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
234
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
235
|
+
var source = arguments[i];
|
|
236
|
+
for (var key in source) {
|
|
237
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
238
|
+
target[key] = source[key];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return target;
|
|
243
|
+
};
|
|
244
|
+
return _extends.apply(this, arguments);
|
|
245
|
+
}
|
|
246
|
+
|
|
256
247
|
let tempIdCounter = 0;
|
|
257
|
-
|
|
258
|
-
|
|
248
|
+
let TooltipTail = function (_React$Component) {
|
|
249
|
+
_inheritsLoose(TooltipTail, _React$Component);
|
|
250
|
+
function TooltipTail() {
|
|
251
|
+
return _React$Component.apply(this, arguments) || this;
|
|
252
|
+
}
|
|
253
|
+
var _proto = TooltipTail.prototype;
|
|
254
|
+
_proto._calculateDimensionsFromPlacement = function _calculateDimensionsFromPlacement() {
|
|
259
255
|
const {
|
|
260
256
|
placement
|
|
261
257
|
} = this.props;
|
|
262
258
|
const trimlineOffset = 0.5;
|
|
263
|
-
|
|
264
259
|
switch (placement) {
|
|
265
260
|
case "top":
|
|
266
261
|
return {
|
|
@@ -269,7 +264,6 @@ class TooltipTail extends React.Component {
|
|
|
269
264
|
height: ARROW_HEIGHT,
|
|
270
265
|
width: ARROW_WIDTH
|
|
271
266
|
};
|
|
272
|
-
|
|
273
267
|
case "right":
|
|
274
268
|
return {
|
|
275
269
|
trimlinePoints: [`${ARROW_HEIGHT + trimlineOffset},0`, `${ARROW_HEIGHT + trimlineOffset},${ARROW_WIDTH}`],
|
|
@@ -277,7 +271,6 @@ class TooltipTail extends React.Component {
|
|
|
277
271
|
width: ARROW_HEIGHT,
|
|
278
272
|
height: ARROW_WIDTH
|
|
279
273
|
};
|
|
280
|
-
|
|
281
274
|
case "bottom":
|
|
282
275
|
return {
|
|
283
276
|
trimlinePoints: [`0, ${ARROW_HEIGHT + trimlineOffset}`, `${ARROW_WIDTH},${ARROW_HEIGHT + trimlineOffset}`],
|
|
@@ -285,7 +278,6 @@ class TooltipTail extends React.Component {
|
|
|
285
278
|
width: ARROW_WIDTH,
|
|
286
279
|
height: ARROW_HEIGHT
|
|
287
280
|
};
|
|
288
|
-
|
|
289
281
|
case "left":
|
|
290
282
|
return {
|
|
291
283
|
trimlinePoints: [`-${trimlineOffset},0`, `-${trimlineOffset},${ARROW_WIDTH}`],
|
|
@@ -293,17 +285,14 @@ class TooltipTail extends React.Component {
|
|
|
293
285
|
width: ARROW_HEIGHT,
|
|
294
286
|
height: ARROW_WIDTH
|
|
295
287
|
};
|
|
296
|
-
|
|
297
288
|
default:
|
|
298
289
|
throw new Error(`Unknown placement: ${placement}`);
|
|
299
290
|
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
_getFilterPositioning() {
|
|
291
|
+
};
|
|
292
|
+
_proto._getFilterPositioning = function _getFilterPositioning() {
|
|
303
293
|
const {
|
|
304
294
|
placement
|
|
305
295
|
} = this.props;
|
|
306
|
-
|
|
307
296
|
switch (placement) {
|
|
308
297
|
case "top":
|
|
309
298
|
return {
|
|
@@ -311,36 +300,29 @@ class TooltipTail extends React.Component {
|
|
|
311
300
|
x: "-50%",
|
|
312
301
|
offsetShadowX: 0
|
|
313
302
|
};
|
|
314
|
-
|
|
315
303
|
case "bottom":
|
|
316
304
|
return null;
|
|
317
|
-
|
|
318
305
|
case "left":
|
|
319
306
|
return {
|
|
320
307
|
y: "-50%",
|
|
321
308
|
x: "0%",
|
|
322
309
|
offsetShadowX: 1
|
|
323
310
|
};
|
|
324
|
-
|
|
325
311
|
case "right":
|
|
326
312
|
return {
|
|
327
313
|
y: "-50%",
|
|
328
314
|
x: "-100%",
|
|
329
315
|
offsetShadowX: -1
|
|
330
316
|
};
|
|
331
|
-
|
|
332
317
|
default:
|
|
333
318
|
throw new Error(`Unknown placement: ${placement}`);
|
|
334
319
|
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
_maybeRenderDropshadow(points) {
|
|
320
|
+
};
|
|
321
|
+
_proto._maybeRenderDropshadow = function _maybeRenderDropshadow(points) {
|
|
338
322
|
const position = this._getFilterPositioning();
|
|
339
|
-
|
|
340
323
|
if (!position) {
|
|
341
324
|
return null;
|
|
342
325
|
}
|
|
343
|
-
|
|
344
326
|
const {
|
|
345
327
|
placement
|
|
346
328
|
} = this.props;
|
|
@@ -372,25 +354,19 @@ class TooltipTail extends React.Component {
|
|
|
372
354
|
stroke: Colors.offBlack32,
|
|
373
355
|
filter: `url(#${dropShadowFilterId})`
|
|
374
356
|
}))];
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
_getFullTailWidth() {
|
|
357
|
+
};
|
|
358
|
+
_proto._getFullTailWidth = function _getFullTailWidth() {
|
|
378
359
|
return ARROW_WIDTH + 2 * MIN_DISTANCE_FROM_CORNERS;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
_getFullTailHeight() {
|
|
360
|
+
};
|
|
361
|
+
_proto._getFullTailHeight = function _getFullTailHeight() {
|
|
382
362
|
return ARROW_HEIGHT + DISTANCE_FROM_ANCHOR;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
_getContainerStyle() {
|
|
363
|
+
};
|
|
364
|
+
_proto._getContainerStyle = function _getContainerStyle() {
|
|
386
365
|
const {
|
|
387
366
|
placement
|
|
388
367
|
} = this.props;
|
|
389
|
-
|
|
390
368
|
const fullTailWidth = this._getFullTailWidth();
|
|
391
|
-
|
|
392
369
|
const fullTailHeight = this._getFullTailHeight();
|
|
393
|
-
|
|
394
370
|
switch (placement) {
|
|
395
371
|
case "top":
|
|
396
372
|
return {
|
|
@@ -398,38 +374,32 @@ class TooltipTail extends React.Component {
|
|
|
398
374
|
width: fullTailWidth,
|
|
399
375
|
height: fullTailHeight
|
|
400
376
|
};
|
|
401
|
-
|
|
402
377
|
case "right":
|
|
403
378
|
return {
|
|
404
379
|
left: 1,
|
|
405
380
|
width: fullTailHeight,
|
|
406
381
|
height: fullTailWidth
|
|
407
382
|
};
|
|
408
|
-
|
|
409
383
|
case "bottom":
|
|
410
384
|
return {
|
|
411
385
|
top: 1,
|
|
412
386
|
width: fullTailWidth,
|
|
413
387
|
height: fullTailHeight
|
|
414
388
|
};
|
|
415
|
-
|
|
416
389
|
case "left":
|
|
417
390
|
return {
|
|
418
391
|
left: -1,
|
|
419
392
|
width: fullTailHeight,
|
|
420
393
|
height: fullTailWidth
|
|
421
394
|
};
|
|
422
|
-
|
|
423
395
|
default:
|
|
424
396
|
throw new Error(`Unknown placement: ${placement}`);
|
|
425
397
|
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
_getArrowStyle() {
|
|
398
|
+
};
|
|
399
|
+
_proto._getArrowStyle = function _getArrowStyle() {
|
|
429
400
|
const {
|
|
430
401
|
placement
|
|
431
402
|
} = this.props;
|
|
432
|
-
|
|
433
403
|
switch (placement) {
|
|
434
404
|
case "top":
|
|
435
405
|
return {
|
|
@@ -437,41 +407,35 @@ class TooltipTail extends React.Component {
|
|
|
437
407
|
marginRight: MIN_DISTANCE_FROM_CORNERS,
|
|
438
408
|
paddingBottom: DISTANCE_FROM_ANCHOR
|
|
439
409
|
};
|
|
440
|
-
|
|
441
410
|
case "right":
|
|
442
411
|
return {
|
|
443
412
|
marginTop: MIN_DISTANCE_FROM_CORNERS,
|
|
444
413
|
marginBottom: MIN_DISTANCE_FROM_CORNERS,
|
|
445
414
|
paddingLeft: DISTANCE_FROM_ANCHOR
|
|
446
415
|
};
|
|
447
|
-
|
|
448
416
|
case "bottom":
|
|
449
417
|
return {
|
|
450
418
|
marginLeft: MIN_DISTANCE_FROM_CORNERS,
|
|
451
419
|
marginRight: MIN_DISTANCE_FROM_CORNERS,
|
|
452
420
|
paddingTop: DISTANCE_FROM_ANCHOR
|
|
453
421
|
};
|
|
454
|
-
|
|
455
422
|
case "left":
|
|
456
423
|
return {
|
|
457
424
|
marginTop: MIN_DISTANCE_FROM_CORNERS,
|
|
458
425
|
marginBottom: MIN_DISTANCE_FROM_CORNERS,
|
|
459
426
|
paddingRight: DISTANCE_FROM_ANCHOR
|
|
460
427
|
};
|
|
461
|
-
|
|
462
428
|
default:
|
|
463
429
|
throw new Error(`Unknown placement: ${placement}`);
|
|
464
430
|
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
_renderArrow() {
|
|
431
|
+
};
|
|
432
|
+
_proto._renderArrow = function _renderArrow() {
|
|
468
433
|
const {
|
|
469
434
|
trimlinePoints,
|
|
470
435
|
points,
|
|
471
436
|
height,
|
|
472
437
|
width
|
|
473
438
|
} = this._calculateDimensionsFromPlacement();
|
|
474
|
-
|
|
475
439
|
const {
|
|
476
440
|
color
|
|
477
441
|
} = this.props;
|
|
@@ -493,9 +457,8 @@ class TooltipTail extends React.Component {
|
|
|
493
457
|
stroke: Colors[color],
|
|
494
458
|
points: trimlinePoints.join(" ")
|
|
495
459
|
}));
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
render() {
|
|
460
|
+
};
|
|
461
|
+
_proto.render = function render() {
|
|
499
462
|
const {
|
|
500
463
|
offset,
|
|
501
464
|
placement,
|
|
@@ -506,9 +469,9 @@ class TooltipTail extends React.Component {
|
|
|
506
469
|
"data-placement": placement,
|
|
507
470
|
ref: updateRef
|
|
508
471
|
}, this._renderArrow());
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
}
|
|
472
|
+
};
|
|
473
|
+
return TooltipTail;
|
|
474
|
+
}(React.Component);
|
|
512
475
|
TooltipTail.defaultProps = {
|
|
513
476
|
color: "white"
|
|
514
477
|
};
|
|
@@ -526,30 +489,30 @@ const styles$2 = StyleSheet.create({
|
|
|
526
489
|
}
|
|
527
490
|
});
|
|
528
491
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
492
|
+
let TooltipBubble = function (_React$Component) {
|
|
493
|
+
_inheritsLoose(TooltipBubble, _React$Component);
|
|
494
|
+
function TooltipBubble(...args) {
|
|
495
|
+
var _this;
|
|
496
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
497
|
+
_this.state = {
|
|
533
498
|
active: false
|
|
534
499
|
};
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
this._setActiveState(true);
|
|
500
|
+
_this.handleMouseEnter = () => {
|
|
501
|
+
_this._setActiveState(true);
|
|
538
502
|
};
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
this.props.onActiveChanged(false);
|
|
503
|
+
_this.handleMouseLeave = () => {
|
|
504
|
+
_this.props.onActiveChanged(false);
|
|
542
505
|
};
|
|
506
|
+
return _this;
|
|
543
507
|
}
|
|
544
|
-
|
|
545
|
-
_setActiveState(active) {
|
|
508
|
+
var _proto = TooltipBubble.prototype;
|
|
509
|
+
_proto._setActiveState = function _setActiveState(active) {
|
|
546
510
|
this.setState({
|
|
547
511
|
active
|
|
548
512
|
});
|
|
549
513
|
this.props.onActiveChanged(active);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
render() {
|
|
514
|
+
};
|
|
515
|
+
_proto.render = function render() {
|
|
553
516
|
const {
|
|
554
517
|
id,
|
|
555
518
|
children,
|
|
@@ -575,9 +538,9 @@ class TooltipBubble extends React.Component {
|
|
|
575
538
|
placement: placement,
|
|
576
539
|
offset: tailOffset
|
|
577
540
|
}));
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
}
|
|
541
|
+
};
|
|
542
|
+
return TooltipBubble;
|
|
543
|
+
}(React.Component);
|
|
581
544
|
const styles$1 = StyleSheet.create({
|
|
582
545
|
bubble: {
|
|
583
546
|
position: "absolute"
|
|
@@ -610,12 +573,16 @@ const styles$1 = StyleSheet.create({
|
|
|
610
573
|
}
|
|
611
574
|
});
|
|
612
575
|
|
|
613
|
-
|
|
614
|
-
|
|
576
|
+
let TooltipContent = function (_React$Component) {
|
|
577
|
+
_inheritsLoose(TooltipContent, _React$Component);
|
|
578
|
+
function TooltipContent() {
|
|
579
|
+
return _React$Component.apply(this, arguments) || this;
|
|
580
|
+
}
|
|
581
|
+
var _proto = TooltipContent.prototype;
|
|
582
|
+
_proto._renderTitle = function _renderTitle() {
|
|
615
583
|
const {
|
|
616
584
|
title
|
|
617
585
|
} = this.props;
|
|
618
|
-
|
|
619
586
|
if (title) {
|
|
620
587
|
if (typeof title === "string") {
|
|
621
588
|
return React.createElement(HeadingSmall, null, title);
|
|
@@ -623,36 +590,30 @@ class TooltipContent extends React.Component {
|
|
|
623
590
|
return title;
|
|
624
591
|
}
|
|
625
592
|
}
|
|
626
|
-
|
|
627
593
|
return null;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
_renderChildren() {
|
|
594
|
+
};
|
|
595
|
+
_proto._renderChildren = function _renderChildren() {
|
|
631
596
|
const {
|
|
632
597
|
children
|
|
633
598
|
} = this.props;
|
|
634
|
-
|
|
635
599
|
if (typeof children === "string") {
|
|
636
600
|
return React.createElement(LabelMedium, null, children);
|
|
637
601
|
} else {
|
|
638
602
|
return children;
|
|
639
603
|
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
render() {
|
|
604
|
+
};
|
|
605
|
+
_proto.render = function render() {
|
|
643
606
|
const title = this._renderTitle();
|
|
644
|
-
|
|
645
607
|
const children = this._renderChildren();
|
|
646
|
-
|
|
647
608
|
const containerStyle = title ? styles.withTitle : styles.withoutTitle;
|
|
648
609
|
return React.createElement(View, {
|
|
649
610
|
style: containerStyle
|
|
650
611
|
}, title, title && children && React.createElement(Strut, {
|
|
651
612
|
size: Spacing.xxxSmall_4
|
|
652
613
|
}), children);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
}
|
|
614
|
+
};
|
|
615
|
+
return TooltipContent;
|
|
616
|
+
}(React.Component);
|
|
656
617
|
const styles = StyleSheet.create({
|
|
657
618
|
withoutTitle: {
|
|
658
619
|
padding: `10px ${Spacing.medium_16}px`
|
|
@@ -662,53 +623,49 @@ const styles = StyleSheet.create({
|
|
|
662
623
|
}
|
|
663
624
|
});
|
|
664
625
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
626
|
+
let RefTracker = function RefTracker() {
|
|
627
|
+
this._lastRef = void 0;
|
|
628
|
+
this._targetFn = void 0;
|
|
629
|
+
this.updateRef = ref => {
|
|
630
|
+
if (ref) {
|
|
631
|
+
const domNode = ReactDOM.findDOMNode(ref);
|
|
632
|
+
if (domNode instanceof HTMLElement && domNode !== this._lastRef) {
|
|
633
|
+
var _this$_targetFn;
|
|
634
|
+
this._lastRef = domNode;
|
|
635
|
+
(_this$_targetFn = this._targetFn) == null ? void 0 : _this$_targetFn.call(this, domNode);
|
|
675
636
|
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
this._targetFn = targetFn || null;
|
|
685
|
-
|
|
686
|
-
if (this._lastRef && this._targetFn) {
|
|
687
|
-
this._targetFn(this._lastRef);
|
|
688
|
-
}
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
this.setCallback = targetFn => {
|
|
640
|
+
if (this._targetFn !== targetFn) {
|
|
641
|
+
if (targetFn && typeof targetFn !== "function") {
|
|
642
|
+
throw new Error("targetFn must be a function");
|
|
689
643
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
super(...args);
|
|
698
|
-
this._bubbleRefTracker = new RefTracker();
|
|
699
|
-
this._tailRefTracker = new RefTracker();
|
|
700
|
-
}
|
|
644
|
+
this._targetFn = targetFn || null;
|
|
645
|
+
if (this._lastRef && this._targetFn) {
|
|
646
|
+
this._targetFn(this._lastRef);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
};
|
|
701
651
|
|
|
702
|
-
|
|
652
|
+
let TooltipPopper = function (_React$Component) {
|
|
653
|
+
_inheritsLoose(TooltipPopper, _React$Component);
|
|
654
|
+
function TooltipPopper(...args) {
|
|
655
|
+
var _this;
|
|
656
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
657
|
+
_this._bubbleRefTracker = new RefTracker();
|
|
658
|
+
_this._tailRefTracker = new RefTracker();
|
|
659
|
+
return _this;
|
|
660
|
+
}
|
|
661
|
+
var _proto = TooltipPopper.prototype;
|
|
662
|
+
_proto._renderPositionedContent = function _renderPositionedContent(popperProps) {
|
|
703
663
|
const {
|
|
704
664
|
children
|
|
705
665
|
} = this.props;
|
|
706
666
|
const placement = popperProps.placement || this.props.placement;
|
|
707
|
-
|
|
708
667
|
this._bubbleRefTracker.setCallback(popperProps.ref);
|
|
709
|
-
|
|
710
668
|
this._tailRefTracker.setCallback(popperProps.arrowProps.ref);
|
|
711
|
-
|
|
712
669
|
const bubbleProps = {
|
|
713
670
|
placement,
|
|
714
671
|
style: {
|
|
@@ -731,9 +688,8 @@ class TooltipPopper extends React.Component {
|
|
|
731
688
|
isReferenceHidden: popperProps.isReferenceHidden
|
|
732
689
|
};
|
|
733
690
|
return children(bubbleProps);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
render() {
|
|
691
|
+
};
|
|
692
|
+
_proto.render = function render() {
|
|
737
693
|
const {
|
|
738
694
|
anchorElement,
|
|
739
695
|
placement
|
|
@@ -749,40 +705,40 @@ class TooltipPopper extends React.Component {
|
|
|
749
705
|
}
|
|
750
706
|
}]
|
|
751
707
|
}, props => this._renderPositionedContent(props));
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
708
|
+
};
|
|
709
|
+
return TooltipPopper;
|
|
710
|
+
}(React.Component);
|
|
711
|
+
|
|
712
|
+
let Tooltip = function (_React$Component) {
|
|
713
|
+
_inheritsLoose(Tooltip, _React$Component);
|
|
714
|
+
function Tooltip(...args) {
|
|
715
|
+
var _this;
|
|
716
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
717
|
+
_this.state = {
|
|
760
718
|
active: false,
|
|
761
719
|
activeBubble: false,
|
|
762
720
|
anchorElement: null
|
|
763
721
|
};
|
|
722
|
+
return _this;
|
|
764
723
|
}
|
|
765
|
-
|
|
766
|
-
static getDerivedStateFromProps(props, state) {
|
|
724
|
+
Tooltip.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
|
|
767
725
|
return {
|
|
768
726
|
active: typeof props.opened === "boolean" ? props.opened : state.active
|
|
769
727
|
};
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
_updateAnchorElement(ref) {
|
|
728
|
+
};
|
|
729
|
+
var _proto = Tooltip.prototype;
|
|
730
|
+
_proto._updateAnchorElement = function _updateAnchorElement(ref) {
|
|
773
731
|
if (ref && ref !== this.state.anchorElement) {
|
|
774
732
|
this.setState({
|
|
775
733
|
anchorElement: ref
|
|
776
734
|
});
|
|
777
735
|
}
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
_renderBubbleContent() {
|
|
736
|
+
};
|
|
737
|
+
_proto._renderBubbleContent = function _renderBubbleContent() {
|
|
781
738
|
const {
|
|
782
739
|
title,
|
|
783
740
|
content
|
|
784
741
|
} = this.props;
|
|
785
|
-
|
|
786
742
|
if (typeof content === "string") {
|
|
787
743
|
return React.createElement(TooltipContent, {
|
|
788
744
|
title: title
|
|
@@ -794,18 +750,15 @@ class Tooltip extends React.Component {
|
|
|
794
750
|
} else {
|
|
795
751
|
return content;
|
|
796
752
|
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
_renderPopper(ids) {
|
|
753
|
+
};
|
|
754
|
+
_proto._renderPopper = function _renderPopper(ids) {
|
|
800
755
|
const {
|
|
801
756
|
id
|
|
802
757
|
} = this.props;
|
|
803
758
|
const bubbleId = ids ? ids.get(Tooltip.ariaContentId) : id;
|
|
804
|
-
|
|
805
759
|
if (!bubbleId) {
|
|
806
760
|
throw new Error("Did not get an identifier factory nor a id prop");
|
|
807
761
|
}
|
|
808
|
-
|
|
809
762
|
const {
|
|
810
763
|
placement
|
|
811
764
|
} = this.props;
|
|
@@ -824,16 +777,14 @@ class Tooltip extends React.Component {
|
|
|
824
777
|
activeBubble: active
|
|
825
778
|
})
|
|
826
779
|
}, this._renderBubbleContent()));
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
_getHost() {
|
|
780
|
+
};
|
|
781
|
+
_proto._getHost = function _getHost() {
|
|
830
782
|
const {
|
|
831
783
|
anchorElement
|
|
832
784
|
} = this.state;
|
|
833
785
|
return maybeGetPortalMountedModalHostElement(anchorElement) || document.body;
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
_renderTooltipAnchor(ids) {
|
|
786
|
+
};
|
|
787
|
+
_proto._renderTooltipAnchor = function _renderTooltipAnchor(ids) {
|
|
837
788
|
const {
|
|
838
789
|
children,
|
|
839
790
|
forceAnchorFocusivity
|
|
@@ -842,9 +793,7 @@ class Tooltip extends React.Component {
|
|
|
842
793
|
active,
|
|
843
794
|
activeBubble
|
|
844
795
|
} = this.state;
|
|
845
|
-
|
|
846
796
|
const popperHost = this._getHost();
|
|
847
|
-
|
|
848
797
|
return React.createElement(React.Fragment, null, React.createElement(TooltipAnchor, {
|
|
849
798
|
forceAnchorFocusivity: forceAnchorFocusivity,
|
|
850
799
|
anchorRef: r => this._updateAnchorElement(r),
|
|
@@ -853,13 +802,11 @@ class Tooltip extends React.Component {
|
|
|
853
802
|
}),
|
|
854
803
|
ids: ids
|
|
855
804
|
}, children), popperHost && (active || activeBubble) && ReactDOM.createPortal(this._renderPopper(ids), popperHost));
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
render() {
|
|
805
|
+
};
|
|
806
|
+
_proto.render = function render() {
|
|
859
807
|
const {
|
|
860
808
|
id
|
|
861
809
|
} = this.props;
|
|
862
|
-
|
|
863
810
|
if (id) {
|
|
864
811
|
return this._renderTooltipAnchor();
|
|
865
812
|
} else {
|
|
@@ -868,9 +815,9 @@ class Tooltip extends React.Component {
|
|
|
868
815
|
mockOnFirstRender: true
|
|
869
816
|
}, ids => this._renderTooltipAnchor(ids));
|
|
870
817
|
}
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
}
|
|
818
|
+
};
|
|
819
|
+
return Tooltip;
|
|
820
|
+
}(React.Component);
|
|
874
821
|
Tooltip.defaultProps = {
|
|
875
822
|
forceAnchorFocusivity: true,
|
|
876
823
|
placement: "top"
|