@zendeskgarden/react-tooltips 9.0.0-next.0 → 9.0.0-next.2
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/index.cjs.js +69 -141
- package/dist/index.esm.js +69 -141
- package/dist/typings/elements/Tooltip.d.ts +3 -5
- package/dist/typings/elements/utils.d.ts +16 -0
- package/dist/typings/styled/StyledTooltip.d.ts +3 -3
- package/dist/typings/styled/StyledTooltipWrapper.d.ts +0 -9
- package/dist/typings/types/index.d.ts +1 -10
- package/package.json +6 -6
- package/dist/typings/utils/gardenPlacements.d.ts +0 -22
package/dist/index.cjs.js
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
10
|
var React = require('react');
|
|
11
|
-
var reactDom = require('react-dom');
|
|
11
|
+
var reactDom$1 = require('react-dom');
|
|
12
12
|
var PropTypes = require('prop-types');
|
|
13
13
|
var styled = require('styled-components');
|
|
14
14
|
var reactMergeRefs = require('react-merge-refs');
|
|
15
15
|
var containerTooltip = require('@zendeskgarden/container-tooltip');
|
|
16
16
|
var containerUtilities = require('@zendeskgarden/container-utilities');
|
|
17
|
-
var reactPopper = require('react-popper');
|
|
18
17
|
var reactTheming = require('@zendeskgarden/react-theming');
|
|
18
|
+
var reactDom = require('@floating-ui/react-dom');
|
|
19
19
|
|
|
20
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
21
|
|
|
@@ -23,62 +23,10 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
23
23
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
24
24
|
var styled__default = /*#__PURE__*/_interopDefault(styled);
|
|
25
25
|
|
|
26
|
-
function getPopperPlacement(gardenPlacement) {
|
|
27
|
-
const gardenToPopperMapping = {
|
|
28
|
-
auto: 'auto',
|
|
29
|
-
top: 'top',
|
|
30
|
-
'top-start': 'top-start',
|
|
31
|
-
'top-end': 'top-end',
|
|
32
|
-
bottom: 'bottom',
|
|
33
|
-
'bottom-start': 'bottom-start',
|
|
34
|
-
'bottom-end': 'bottom-end',
|
|
35
|
-
end: 'right',
|
|
36
|
-
'end-top': 'right-start',
|
|
37
|
-
'end-bottom': 'right-end',
|
|
38
|
-
start: 'left',
|
|
39
|
-
'start-top': 'left-start',
|
|
40
|
-
'start-bottom': 'left-end'
|
|
41
|
-
};
|
|
42
|
-
return gardenToPopperMapping[gardenPlacement];
|
|
43
|
-
}
|
|
44
|
-
function getRtlPopperPlacement(gardenPlacement) {
|
|
45
|
-
const rtlPlacementMappings = {
|
|
46
|
-
left: 'right',
|
|
47
|
-
'left-start': 'right-start',
|
|
48
|
-
'left-end': 'right-end',
|
|
49
|
-
'top-start': 'top-end',
|
|
50
|
-
'top-end': 'top-start',
|
|
51
|
-
right: 'left',
|
|
52
|
-
'right-start': 'left-start',
|
|
53
|
-
'right-end': 'left-end',
|
|
54
|
-
'bottom-start': 'bottom-end',
|
|
55
|
-
'bottom-end': 'bottom-start'
|
|
56
|
-
};
|
|
57
|
-
const popperPlacement = getPopperPlacement(gardenPlacement);
|
|
58
|
-
return rtlPlacementMappings[popperPlacement] || popperPlacement;
|
|
59
|
-
}
|
|
60
|
-
function getArrowPosition(popperPlacement) {
|
|
61
|
-
const arrowPositionMappings = {
|
|
62
|
-
top: 'bottom',
|
|
63
|
-
'top-start': 'bottom-left',
|
|
64
|
-
'top-end': 'bottom-right',
|
|
65
|
-
right: 'left',
|
|
66
|
-
'right-start': 'left-top',
|
|
67
|
-
'right-end': 'left-bottom',
|
|
68
|
-
bottom: 'top',
|
|
69
|
-
'bottom-start': 'top-left',
|
|
70
|
-
'bottom-end': 'top-right',
|
|
71
|
-
left: 'right',
|
|
72
|
-
'left-start': 'right-top',
|
|
73
|
-
'left-end': 'right-bottom'
|
|
74
|
-
};
|
|
75
|
-
return arrowPositionMappings[popperPlacement] || 'top';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
26
|
const COMPONENT_ID$2 = 'tooltip.paragraph';
|
|
79
27
|
const StyledParagraph = styled__default.default.p.attrs({
|
|
80
28
|
'data-garden-id': COMPONENT_ID$2,
|
|
81
|
-
'data-garden-version': '9.0.0-next.
|
|
29
|
+
'data-garden-version': '9.0.0-next.2'
|
|
82
30
|
}).withConfig({
|
|
83
31
|
displayName: "StyledParagraph",
|
|
84
32
|
componentId: "sc-wuqkfc-0"
|
|
@@ -90,7 +38,7 @@ StyledParagraph.defaultProps = {
|
|
|
90
38
|
const COMPONENT_ID$1 = 'tooltip.title';
|
|
91
39
|
const StyledTitle = styled__default.default.strong.attrs({
|
|
92
40
|
'data-garden-id': COMPONENT_ID$1,
|
|
93
|
-
'data-garden-version': '9.0.0-next.
|
|
41
|
+
'data-garden-version': '9.0.0-next.2'
|
|
94
42
|
}).withConfig({
|
|
95
43
|
displayName: "StyledTitle",
|
|
96
44
|
componentId: "sc-vnjcvz-0"
|
|
@@ -161,7 +109,7 @@ const sizeStyles = _ref => {
|
|
|
161
109
|
}
|
|
162
110
|
}
|
|
163
111
|
}
|
|
164
|
-
return styled.css(["margin:", ";border-radius:", ";padding:", ";max-width:", ";line-height:", ";word-wrap:", ";white-space:", ";font-size:", ";overflow-wrap:", ";", ";", "{margin-top:", ";}", "{display:", ";}"], margin, borderRadius, padding, maxWidth, lineHeight, wordWrap, whiteSpace, fontSize, overflowWrap, hasArrow && reactTheming.arrowStyles(getArrowPosition(placement), {
|
|
112
|
+
return styled.css(["margin:", ";border-radius:", ";padding:", ";max-width:", ";line-height:", ";word-wrap:", ";white-space:", ";font-size:", ";overflow-wrap:", ";", ";", "{margin-top:", ";}", "{display:", ";}"], margin, borderRadius, padding, maxWidth, lineHeight, wordWrap, whiteSpace, fontSize, overflowWrap, hasArrow && reactTheming.arrowStyles(reactTheming.getArrowPosition(theme, placement), {
|
|
165
113
|
size: arrowSize,
|
|
166
114
|
inset: arrowInset
|
|
167
115
|
}), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
|
|
@@ -187,7 +135,7 @@ const colorStyles = _ref2 => {
|
|
|
187
135
|
};
|
|
188
136
|
const StyledTooltip = styled__default.default.div.attrs({
|
|
189
137
|
'data-garden-id': COMPONENT_ID,
|
|
190
|
-
'data-garden-version': '9.0.0-next.
|
|
138
|
+
'data-garden-version': '9.0.0-next.2'
|
|
191
139
|
}).withConfig({
|
|
192
140
|
displayName: "StyledTooltip",
|
|
193
141
|
componentId: "sc-gzzjq4-0"
|
|
@@ -199,16 +147,24 @@ StyledTooltip.defaultProps = {
|
|
|
199
147
|
const StyledTooltipWrapper = styled__default.default.div.withConfig({
|
|
200
148
|
displayName: "StyledTooltipWrapper",
|
|
201
149
|
componentId: "sc-1b7q9q6-0"
|
|
202
|
-
})(["transition:opacity 10ms;opacity:1;z-index:", ";&[aria-hidden='true']{visibility:hidden;opacity:0;}"], props => props.zIndex);
|
|
150
|
+
})(["position:absolute;top:0;left:0;transition:opacity 10ms;opacity:1;z-index:", ";&[aria-hidden='true']{visibility:hidden;opacity:0;}"], props => props.zIndex);
|
|
203
151
|
StyledTooltipWrapper.defaultProps = {
|
|
204
152
|
theme: reactTheming.DEFAULT_THEME
|
|
205
153
|
};
|
|
206
154
|
|
|
207
|
-
const
|
|
208
|
-
const PLACEMENT = [...SHARED_PLACEMENT, 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
|
|
155
|
+
const PLACEMENT = ['auto', ...reactTheming.PLACEMENT];
|
|
209
156
|
const SIZE = ['small', 'medium', 'large', 'extra-large'];
|
|
210
157
|
const TYPE = ['light', 'dark'];
|
|
211
158
|
|
|
159
|
+
const toSize = (size, type) => {
|
|
160
|
+
let retVal = size;
|
|
161
|
+
if (retVal === undefined) {
|
|
162
|
+
retVal = type === 'dark' ? 'small' : 'large';
|
|
163
|
+
}
|
|
164
|
+
return retVal;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const PLACEMENT_DEFAULT = 'top';
|
|
212
168
|
const Tooltip = _ref => {
|
|
213
169
|
let {
|
|
214
170
|
id,
|
|
@@ -216,9 +172,7 @@ const Tooltip = _ref => {
|
|
|
216
172
|
isInitialVisible,
|
|
217
173
|
content,
|
|
218
174
|
refKey,
|
|
219
|
-
placement,
|
|
220
|
-
eventsEnabled,
|
|
221
|
-
popperModifiers,
|
|
175
|
+
placement: _placement,
|
|
222
176
|
children,
|
|
223
177
|
hasArrow,
|
|
224
178
|
size,
|
|
@@ -226,12 +180,13 @@ const Tooltip = _ref => {
|
|
|
226
180
|
appendToNode,
|
|
227
181
|
zIndex,
|
|
228
182
|
isVisible: externalIsVisible,
|
|
229
|
-
|
|
183
|
+
onFocus,
|
|
184
|
+
onBlur,
|
|
185
|
+
...props
|
|
230
186
|
} = _ref;
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const scheduleUpdateRef = React.useRef();
|
|
187
|
+
const theme = React.useContext(styled.ThemeContext) || reactTheming.DEFAULT_THEME;
|
|
188
|
+
const triggerRef = React.useRef(null);
|
|
189
|
+
const floatingRef = React.useRef(null);
|
|
235
190
|
const {
|
|
236
191
|
isVisible,
|
|
237
192
|
getTooltipProps,
|
|
@@ -244,88 +199,62 @@ const Tooltip = _ref => {
|
|
|
244
199
|
isVisible: isInitialVisible
|
|
245
200
|
});
|
|
246
201
|
const controlledIsVisible = containerUtilities.getControlledValue(externalIsVisible, isVisible);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
202
|
+
const [floatingPlacement] = reactTheming.getFloatingPlacements(theme, _placement === 'auto' ? PLACEMENT_DEFAULT : _placement);
|
|
203
|
+
const {
|
|
204
|
+
refs,
|
|
205
|
+
placement,
|
|
206
|
+
update,
|
|
207
|
+
floatingStyles: {
|
|
208
|
+
transform
|
|
250
209
|
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
preventOverflow: {
|
|
256
|
-
boundariesElement: 'window'
|
|
210
|
+
} = reactDom.useFloating({
|
|
211
|
+
elements: {
|
|
212
|
+
reference: triggerRef?.current,
|
|
213
|
+
floating: floatingRef?.current
|
|
257
214
|
},
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}));
|
|
268
|
-
}), React__default.default.createElement(reactPopper.Popper, {
|
|
269
|
-
placement: popperPlacement,
|
|
270
|
-
eventsEnabled: controlledIsVisible && eventsEnabled,
|
|
271
|
-
modifiers: modifiers
|
|
272
|
-
}, _ref3 => {
|
|
273
|
-
let {
|
|
274
|
-
ref,
|
|
275
|
-
style,
|
|
276
|
-
scheduleUpdate,
|
|
277
|
-
placement: currentPlacement
|
|
278
|
-
} = _ref3;
|
|
279
|
-
scheduleUpdateRef.current = scheduleUpdate;
|
|
280
|
-
const {
|
|
281
|
-
onFocus,
|
|
282
|
-
onBlur,
|
|
283
|
-
...otherTooltipProps
|
|
284
|
-
} = otherProps;
|
|
285
|
-
let computedSize = size;
|
|
286
|
-
if (computedSize === undefined) {
|
|
287
|
-
if (type === 'dark') {
|
|
288
|
-
computedSize = 'small';
|
|
289
|
-
} else {
|
|
290
|
-
computedSize = 'large';
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
const tooltipProps = {
|
|
294
|
-
hasArrow,
|
|
295
|
-
placement: currentPlacement,
|
|
296
|
-
size: computedSize,
|
|
297
|
-
onFocus: containerUtilities.composeEventHandlers(onFocus, () => {
|
|
298
|
-
openTooltip();
|
|
299
|
-
}),
|
|
300
|
-
onBlur: containerUtilities.composeEventHandlers(onBlur, () => {
|
|
301
|
-
closeTooltip(0);
|
|
302
|
-
}),
|
|
303
|
-
'aria-hidden': !controlledIsVisible,
|
|
304
|
-
type,
|
|
305
|
-
...otherTooltipProps
|
|
306
|
-
};
|
|
307
|
-
const tooltip = React__default.default.createElement(StyledTooltipWrapper, {
|
|
308
|
-
ref: controlledIsVisible ? ref : null,
|
|
309
|
-
style: style,
|
|
310
|
-
zIndex: zIndex,
|
|
311
|
-
"aria-hidden": !controlledIsVisible
|
|
312
|
-
}, React__default.default.createElement(StyledTooltip, getTooltipProps(tooltipProps), content));
|
|
313
|
-
if (appendToNode) {
|
|
314
|
-
return reactDom.createPortal(tooltip, appendToNode);
|
|
215
|
+
placement: floatingPlacement,
|
|
216
|
+
middleware: _placement === 'auto' ? [reactDom.autoPlacement()] : undefined
|
|
217
|
+
});
|
|
218
|
+
React.useEffect(() => {
|
|
219
|
+
let cleanup;
|
|
220
|
+
if (controlledIsVisible && refs.reference.current && refs.floating.current) {
|
|
221
|
+
cleanup = reactDom.autoUpdate(refs.reference.current, refs.floating.current, update, {
|
|
222
|
+
elementResize: typeof ResizeObserver === 'function'
|
|
223
|
+
});
|
|
315
224
|
}
|
|
316
|
-
return
|
|
317
|
-
})
|
|
225
|
+
return () => cleanup && cleanup();
|
|
226
|
+
}, [controlledIsVisible, refs.reference, refs.floating, update]);
|
|
227
|
+
const Child = React__default.default.Children.only(children);
|
|
228
|
+
const Node = React__default.default.createElement(StyledTooltipWrapper, {
|
|
229
|
+
ref: floatingRef,
|
|
230
|
+
style: {
|
|
231
|
+
transform
|
|
232
|
+
},
|
|
233
|
+
zIndex: zIndex,
|
|
234
|
+
"aria-hidden": !controlledIsVisible
|
|
235
|
+
}, React__default.default.createElement(StyledTooltip, getTooltipProps({
|
|
236
|
+
hasArrow,
|
|
237
|
+
placement,
|
|
238
|
+
size: toSize(size, type),
|
|
239
|
+
onFocus: containerUtilities.composeEventHandlers(onFocus, openTooltip),
|
|
240
|
+
onBlur: containerUtilities.composeEventHandlers(onBlur, () => closeTooltip(0)),
|
|
241
|
+
'aria-hidden': !controlledIsVisible,
|
|
242
|
+
type,
|
|
243
|
+
...props
|
|
244
|
+
}), content));
|
|
245
|
+
return React__default.default.createElement(React__default.default.Fragment, null, React.cloneElement(Child, getTriggerProps({
|
|
246
|
+
...Child.props,
|
|
247
|
+
[refKey]: reactMergeRefs.mergeRefs([triggerRef, Child.ref ? Child.ref : null])
|
|
248
|
+
})), appendToNode ? reactDom$1.createPortal(Node, appendToNode) : Node);
|
|
318
249
|
};
|
|
319
250
|
Tooltip.displayName = 'Tooltip';
|
|
320
251
|
Tooltip.propTypes = {
|
|
321
252
|
appendToNode: PropTypes__default.default.any,
|
|
322
253
|
hasArrow: PropTypes__default.default.bool,
|
|
323
254
|
delayMS: PropTypes__default.default.number,
|
|
324
|
-
eventsEnabled: PropTypes__default.default.bool,
|
|
325
255
|
id: PropTypes__default.default.string,
|
|
326
256
|
content: PropTypes__default.default.node.isRequired,
|
|
327
257
|
placement: PropTypes__default.default.oneOf(PLACEMENT),
|
|
328
|
-
popperModifiers: PropTypes__default.default.any,
|
|
329
258
|
size: PropTypes__default.default.oneOf(SIZE),
|
|
330
259
|
type: PropTypes__default.default.oneOf(TYPE),
|
|
331
260
|
zIndex: PropTypes__default.default.oneOfType([PropTypes__default.default.number, PropTypes__default.default.string]),
|
|
@@ -334,9 +263,8 @@ Tooltip.propTypes = {
|
|
|
334
263
|
};
|
|
335
264
|
Tooltip.defaultProps = {
|
|
336
265
|
hasArrow: true,
|
|
337
|
-
eventsEnabled: true,
|
|
338
266
|
type: 'dark',
|
|
339
|
-
placement:
|
|
267
|
+
placement: PLACEMENT_DEFAULT,
|
|
340
268
|
delayMS: 500,
|
|
341
269
|
refKey: 'ref'
|
|
342
270
|
};
|
package/dist/index.esm.js
CHANGED
|
@@ -12,65 +12,13 @@ import styled, { css, ThemeContext } from 'styled-components';
|
|
|
12
12
|
import { mergeRefs } from 'react-merge-refs';
|
|
13
13
|
import { useTooltip } from '@zendeskgarden/container-tooltip';
|
|
14
14
|
import { getControlledValue, composeEventHandlers } from '@zendeskgarden/container-utilities';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
function getPopperPlacement(gardenPlacement) {
|
|
19
|
-
const gardenToPopperMapping = {
|
|
20
|
-
auto: 'auto',
|
|
21
|
-
top: 'top',
|
|
22
|
-
'top-start': 'top-start',
|
|
23
|
-
'top-end': 'top-end',
|
|
24
|
-
bottom: 'bottom',
|
|
25
|
-
'bottom-start': 'bottom-start',
|
|
26
|
-
'bottom-end': 'bottom-end',
|
|
27
|
-
end: 'right',
|
|
28
|
-
'end-top': 'right-start',
|
|
29
|
-
'end-bottom': 'right-end',
|
|
30
|
-
start: 'left',
|
|
31
|
-
'start-top': 'left-start',
|
|
32
|
-
'start-bottom': 'left-end'
|
|
33
|
-
};
|
|
34
|
-
return gardenToPopperMapping[gardenPlacement];
|
|
35
|
-
}
|
|
36
|
-
function getRtlPopperPlacement(gardenPlacement) {
|
|
37
|
-
const rtlPlacementMappings = {
|
|
38
|
-
left: 'right',
|
|
39
|
-
'left-start': 'right-start',
|
|
40
|
-
'left-end': 'right-end',
|
|
41
|
-
'top-start': 'top-end',
|
|
42
|
-
'top-end': 'top-start',
|
|
43
|
-
right: 'left',
|
|
44
|
-
'right-start': 'left-start',
|
|
45
|
-
'right-end': 'left-end',
|
|
46
|
-
'bottom-start': 'bottom-end',
|
|
47
|
-
'bottom-end': 'bottom-start'
|
|
48
|
-
};
|
|
49
|
-
const popperPlacement = getPopperPlacement(gardenPlacement);
|
|
50
|
-
return rtlPlacementMappings[popperPlacement] || popperPlacement;
|
|
51
|
-
}
|
|
52
|
-
function getArrowPosition(popperPlacement) {
|
|
53
|
-
const arrowPositionMappings = {
|
|
54
|
-
top: 'bottom',
|
|
55
|
-
'top-start': 'bottom-left',
|
|
56
|
-
'top-end': 'bottom-right',
|
|
57
|
-
right: 'left',
|
|
58
|
-
'right-start': 'left-top',
|
|
59
|
-
'right-end': 'left-bottom',
|
|
60
|
-
bottom: 'top',
|
|
61
|
-
'bottom-start': 'top-left',
|
|
62
|
-
'bottom-end': 'top-right',
|
|
63
|
-
left: 'right',
|
|
64
|
-
'left-start': 'right-top',
|
|
65
|
-
'left-end': 'right-bottom'
|
|
66
|
-
};
|
|
67
|
-
return arrowPositionMappings[popperPlacement] || 'top';
|
|
68
|
-
}
|
|
15
|
+
import { retrieveComponentStyles, DEFAULT_THEME, getLineHeight, arrowStyles, getArrowPosition, getColor, PLACEMENT as PLACEMENT$1, getFloatingPlacements } from '@zendeskgarden/react-theming';
|
|
16
|
+
import { useFloating, autoPlacement, autoUpdate } from '@floating-ui/react-dom';
|
|
69
17
|
|
|
70
18
|
const COMPONENT_ID$2 = 'tooltip.paragraph';
|
|
71
19
|
const StyledParagraph = styled.p.attrs({
|
|
72
20
|
'data-garden-id': COMPONENT_ID$2,
|
|
73
|
-
'data-garden-version': '9.0.0-next.
|
|
21
|
+
'data-garden-version': '9.0.0-next.2'
|
|
74
22
|
}).withConfig({
|
|
75
23
|
displayName: "StyledParagraph",
|
|
76
24
|
componentId: "sc-wuqkfc-0"
|
|
@@ -82,7 +30,7 @@ StyledParagraph.defaultProps = {
|
|
|
82
30
|
const COMPONENT_ID$1 = 'tooltip.title';
|
|
83
31
|
const StyledTitle = styled.strong.attrs({
|
|
84
32
|
'data-garden-id': COMPONENT_ID$1,
|
|
85
|
-
'data-garden-version': '9.0.0-next.
|
|
33
|
+
'data-garden-version': '9.0.0-next.2'
|
|
86
34
|
}).withConfig({
|
|
87
35
|
displayName: "StyledTitle",
|
|
88
36
|
componentId: "sc-vnjcvz-0"
|
|
@@ -153,7 +101,7 @@ const sizeStyles = _ref => {
|
|
|
153
101
|
}
|
|
154
102
|
}
|
|
155
103
|
}
|
|
156
|
-
return css(["margin:", ";border-radius:", ";padding:", ";max-width:", ";line-height:", ";word-wrap:", ";white-space:", ";font-size:", ";overflow-wrap:", ";", ";", "{margin-top:", ";}", "{display:", ";}"], margin, borderRadius, padding, maxWidth, lineHeight, wordWrap, whiteSpace, fontSize, overflowWrap, hasArrow && arrowStyles(getArrowPosition(placement), {
|
|
104
|
+
return css(["margin:", ";border-radius:", ";padding:", ";max-width:", ";line-height:", ";word-wrap:", ";white-space:", ";font-size:", ";overflow-wrap:", ";", ";", "{margin-top:", ";}", "{display:", ";}"], margin, borderRadius, padding, maxWidth, lineHeight, wordWrap, whiteSpace, fontSize, overflowWrap, hasArrow && arrowStyles(getArrowPosition(theme, placement), {
|
|
157
105
|
size: arrowSize,
|
|
158
106
|
inset: arrowInset
|
|
159
107
|
}), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
|
|
@@ -179,7 +127,7 @@ const colorStyles = _ref2 => {
|
|
|
179
127
|
};
|
|
180
128
|
const StyledTooltip = styled.div.attrs({
|
|
181
129
|
'data-garden-id': COMPONENT_ID,
|
|
182
|
-
'data-garden-version': '9.0.0-next.
|
|
130
|
+
'data-garden-version': '9.0.0-next.2'
|
|
183
131
|
}).withConfig({
|
|
184
132
|
displayName: "StyledTooltip",
|
|
185
133
|
componentId: "sc-gzzjq4-0"
|
|
@@ -191,16 +139,24 @@ StyledTooltip.defaultProps = {
|
|
|
191
139
|
const StyledTooltipWrapper = styled.div.withConfig({
|
|
192
140
|
displayName: "StyledTooltipWrapper",
|
|
193
141
|
componentId: "sc-1b7q9q6-0"
|
|
194
|
-
})(["transition:opacity 10ms;opacity:1;z-index:", ";&[aria-hidden='true']{visibility:hidden;opacity:0;}"], props => props.zIndex);
|
|
142
|
+
})(["position:absolute;top:0;left:0;transition:opacity 10ms;opacity:1;z-index:", ";&[aria-hidden='true']{visibility:hidden;opacity:0;}"], props => props.zIndex);
|
|
195
143
|
StyledTooltipWrapper.defaultProps = {
|
|
196
144
|
theme: DEFAULT_THEME
|
|
197
145
|
};
|
|
198
146
|
|
|
199
|
-
const
|
|
200
|
-
const PLACEMENT = [...SHARED_PLACEMENT, 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
|
|
147
|
+
const PLACEMENT = ['auto', ...PLACEMENT$1];
|
|
201
148
|
const SIZE = ['small', 'medium', 'large', 'extra-large'];
|
|
202
149
|
const TYPE = ['light', 'dark'];
|
|
203
150
|
|
|
151
|
+
const toSize = (size, type) => {
|
|
152
|
+
let retVal = size;
|
|
153
|
+
if (retVal === undefined) {
|
|
154
|
+
retVal = type === 'dark' ? 'small' : 'large';
|
|
155
|
+
}
|
|
156
|
+
return retVal;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const PLACEMENT_DEFAULT = 'top';
|
|
204
160
|
const Tooltip = _ref => {
|
|
205
161
|
let {
|
|
206
162
|
id,
|
|
@@ -208,9 +164,7 @@ const Tooltip = _ref => {
|
|
|
208
164
|
isInitialVisible,
|
|
209
165
|
content,
|
|
210
166
|
refKey,
|
|
211
|
-
placement,
|
|
212
|
-
eventsEnabled,
|
|
213
|
-
popperModifiers,
|
|
167
|
+
placement: _placement,
|
|
214
168
|
children,
|
|
215
169
|
hasArrow,
|
|
216
170
|
size,
|
|
@@ -218,12 +172,13 @@ const Tooltip = _ref => {
|
|
|
218
172
|
appendToNode,
|
|
219
173
|
zIndex,
|
|
220
174
|
isVisible: externalIsVisible,
|
|
221
|
-
|
|
175
|
+
onFocus,
|
|
176
|
+
onBlur,
|
|
177
|
+
...props
|
|
222
178
|
} = _ref;
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const scheduleUpdateRef = useRef();
|
|
179
|
+
const theme = useContext(ThemeContext) || DEFAULT_THEME;
|
|
180
|
+
const triggerRef = useRef(null);
|
|
181
|
+
const floatingRef = useRef(null);
|
|
227
182
|
const {
|
|
228
183
|
isVisible,
|
|
229
184
|
getTooltipProps,
|
|
@@ -236,88 +191,62 @@ const Tooltip = _ref => {
|
|
|
236
191
|
isVisible: isInitialVisible
|
|
237
192
|
});
|
|
238
193
|
const controlledIsVisible = getControlledValue(externalIsVisible, isVisible);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
194
|
+
const [floatingPlacement] = getFloatingPlacements(theme, _placement === 'auto' ? PLACEMENT_DEFAULT : _placement);
|
|
195
|
+
const {
|
|
196
|
+
refs,
|
|
197
|
+
placement,
|
|
198
|
+
update,
|
|
199
|
+
floatingStyles: {
|
|
200
|
+
transform
|
|
242
201
|
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
preventOverflow: {
|
|
248
|
-
boundariesElement: 'window'
|
|
202
|
+
} = useFloating({
|
|
203
|
+
elements: {
|
|
204
|
+
reference: triggerRef?.current,
|
|
205
|
+
floating: floatingRef?.current
|
|
249
206
|
},
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}));
|
|
260
|
-
}), React.createElement(Popper, {
|
|
261
|
-
placement: popperPlacement,
|
|
262
|
-
eventsEnabled: controlledIsVisible && eventsEnabled,
|
|
263
|
-
modifiers: modifiers
|
|
264
|
-
}, _ref3 => {
|
|
265
|
-
let {
|
|
266
|
-
ref,
|
|
267
|
-
style,
|
|
268
|
-
scheduleUpdate,
|
|
269
|
-
placement: currentPlacement
|
|
270
|
-
} = _ref3;
|
|
271
|
-
scheduleUpdateRef.current = scheduleUpdate;
|
|
272
|
-
const {
|
|
273
|
-
onFocus,
|
|
274
|
-
onBlur,
|
|
275
|
-
...otherTooltipProps
|
|
276
|
-
} = otherProps;
|
|
277
|
-
let computedSize = size;
|
|
278
|
-
if (computedSize === undefined) {
|
|
279
|
-
if (type === 'dark') {
|
|
280
|
-
computedSize = 'small';
|
|
281
|
-
} else {
|
|
282
|
-
computedSize = 'large';
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const tooltipProps = {
|
|
286
|
-
hasArrow,
|
|
287
|
-
placement: currentPlacement,
|
|
288
|
-
size: computedSize,
|
|
289
|
-
onFocus: composeEventHandlers(onFocus, () => {
|
|
290
|
-
openTooltip();
|
|
291
|
-
}),
|
|
292
|
-
onBlur: composeEventHandlers(onBlur, () => {
|
|
293
|
-
closeTooltip(0);
|
|
294
|
-
}),
|
|
295
|
-
'aria-hidden': !controlledIsVisible,
|
|
296
|
-
type,
|
|
297
|
-
...otherTooltipProps
|
|
298
|
-
};
|
|
299
|
-
const tooltip = React.createElement(StyledTooltipWrapper, {
|
|
300
|
-
ref: controlledIsVisible ? ref : null,
|
|
301
|
-
style: style,
|
|
302
|
-
zIndex: zIndex,
|
|
303
|
-
"aria-hidden": !controlledIsVisible
|
|
304
|
-
}, React.createElement(StyledTooltip, getTooltipProps(tooltipProps), content));
|
|
305
|
-
if (appendToNode) {
|
|
306
|
-
return createPortal(tooltip, appendToNode);
|
|
207
|
+
placement: floatingPlacement,
|
|
208
|
+
middleware: _placement === 'auto' ? [autoPlacement()] : undefined
|
|
209
|
+
});
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
let cleanup;
|
|
212
|
+
if (controlledIsVisible && refs.reference.current && refs.floating.current) {
|
|
213
|
+
cleanup = autoUpdate(refs.reference.current, refs.floating.current, update, {
|
|
214
|
+
elementResize: typeof ResizeObserver === 'function'
|
|
215
|
+
});
|
|
307
216
|
}
|
|
308
|
-
return
|
|
309
|
-
})
|
|
217
|
+
return () => cleanup && cleanup();
|
|
218
|
+
}, [controlledIsVisible, refs.reference, refs.floating, update]);
|
|
219
|
+
const Child = React.Children.only(children);
|
|
220
|
+
const Node = React.createElement(StyledTooltipWrapper, {
|
|
221
|
+
ref: floatingRef,
|
|
222
|
+
style: {
|
|
223
|
+
transform
|
|
224
|
+
},
|
|
225
|
+
zIndex: zIndex,
|
|
226
|
+
"aria-hidden": !controlledIsVisible
|
|
227
|
+
}, React.createElement(StyledTooltip, getTooltipProps({
|
|
228
|
+
hasArrow,
|
|
229
|
+
placement,
|
|
230
|
+
size: toSize(size, type),
|
|
231
|
+
onFocus: composeEventHandlers(onFocus, openTooltip),
|
|
232
|
+
onBlur: composeEventHandlers(onBlur, () => closeTooltip(0)),
|
|
233
|
+
'aria-hidden': !controlledIsVisible,
|
|
234
|
+
type,
|
|
235
|
+
...props
|
|
236
|
+
}), content));
|
|
237
|
+
return React.createElement(React.Fragment, null, cloneElement(Child, getTriggerProps({
|
|
238
|
+
...Child.props,
|
|
239
|
+
[refKey]: mergeRefs([triggerRef, Child.ref ? Child.ref : null])
|
|
240
|
+
})), appendToNode ? createPortal(Node, appendToNode) : Node);
|
|
310
241
|
};
|
|
311
242
|
Tooltip.displayName = 'Tooltip';
|
|
312
243
|
Tooltip.propTypes = {
|
|
313
244
|
appendToNode: PropTypes.any,
|
|
314
245
|
hasArrow: PropTypes.bool,
|
|
315
246
|
delayMS: PropTypes.number,
|
|
316
|
-
eventsEnabled: PropTypes.bool,
|
|
317
247
|
id: PropTypes.string,
|
|
318
248
|
content: PropTypes.node.isRequired,
|
|
319
249
|
placement: PropTypes.oneOf(PLACEMENT),
|
|
320
|
-
popperModifiers: PropTypes.any,
|
|
321
250
|
size: PropTypes.oneOf(SIZE),
|
|
322
251
|
type: PropTypes.oneOf(TYPE),
|
|
323
252
|
zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
@@ -326,9 +255,8 @@ Tooltip.propTypes = {
|
|
|
326
255
|
};
|
|
327
256
|
Tooltip.defaultProps = {
|
|
328
257
|
hasArrow: true,
|
|
329
|
-
eventsEnabled: true,
|
|
330
258
|
type: 'dark',
|
|
331
|
-
placement:
|
|
259
|
+
placement: PLACEMENT_DEFAULT,
|
|
332
260
|
delayMS: 500,
|
|
333
261
|
refKey: 'ref'
|
|
334
262
|
};
|
|
@@ -7,21 +7,20 @@
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
9
|
import { ITooltipProps } from '../types';
|
|
10
|
+
export declare const PLACEMENT_DEFAULT = "top";
|
|
10
11
|
/**
|
|
11
12
|
* @extends HTMLAttributes<HTMLDivElement>
|
|
12
13
|
*/
|
|
13
14
|
export declare const Tooltip: {
|
|
14
|
-
({ id, delayMS, isInitialVisible, content, refKey, placement
|
|
15
|
+
({ id, delayMS, isInitialVisible, content, refKey, placement: _placement, children, hasArrow, size, type, appendToNode, zIndex, isVisible: externalIsVisible, onFocus, onBlur, ...props }: ITooltipProps): React.JSX.Element;
|
|
15
16
|
displayName: string;
|
|
16
17
|
propTypes: {
|
|
17
18
|
appendToNode: PropTypes.Requireable<any>;
|
|
18
19
|
hasArrow: PropTypes.Requireable<boolean>;
|
|
19
20
|
delayMS: PropTypes.Requireable<number>;
|
|
20
|
-
eventsEnabled: PropTypes.Requireable<boolean>;
|
|
21
21
|
id: PropTypes.Requireable<string>;
|
|
22
22
|
content: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
|
|
23
|
-
placement: PropTypes.Requireable<"
|
|
24
|
-
popperModifiers: PropTypes.Requireable<any>;
|
|
23
|
+
placement: PropTypes.Requireable<"top" | "auto" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "end" | "end-top" | "end-bottom" | "start" | "start-top" | "start-bottom">;
|
|
25
24
|
size: PropTypes.Requireable<"small" | "medium" | "large" | "extra-large">;
|
|
26
25
|
type: PropTypes.Requireable<"light" | "dark">;
|
|
27
26
|
zIndex: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
|
|
@@ -30,7 +29,6 @@ export declare const Tooltip: {
|
|
|
30
29
|
};
|
|
31
30
|
defaultProps: {
|
|
32
31
|
hasArrow: boolean;
|
|
33
|
-
eventsEnabled: boolean;
|
|
34
32
|
type: string;
|
|
35
33
|
placement: string;
|
|
36
34
|
delayMS: number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import { ITooltipProps } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Convert to the intended tooltip size for the given type.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} size Tooltip size prop value
|
|
12
|
+
* @param {string} type Tooltip type prop value
|
|
13
|
+
*
|
|
14
|
+
* @returns A tooltip size.
|
|
15
|
+
*/
|
|
16
|
+
export declare const toSize: (size: ITooltipProps['size'], type: ITooltipProps['type']) => "small" | "medium" | "large" | "extra-large";
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
7
|
import { DefaultTheme } from 'styled-components';
|
|
8
|
-
import {
|
|
8
|
+
import { Placement } from '@floating-ui/react-dom';
|
|
9
|
+
import { ITooltipProps } from '../types';
|
|
9
10
|
interface IStyledTooltipProps extends Pick<ITooltipProps, 'hasArrow' | 'size' | 'zIndex'> {
|
|
10
|
-
|
|
11
|
-
placement: (typeof POPPER_PLACEMENT)[number];
|
|
11
|
+
placement: Placement;
|
|
12
12
|
type: NonNullable<ITooltipProps['type']>;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
@@ -4,15 +4,6 @@
|
|
|
4
4
|
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
8
|
-
* This wrapper allows the StyledTooltip to retain it's relative positioning.
|
|
9
|
-
* Without this container Popper would apply absolute positioning directly to
|
|
10
|
-
* the StyledTooltip which impacts arrow styling.
|
|
11
|
-
*
|
|
12
|
-
* 1. This wrapper also includes an opacity transition. It allows Popper to
|
|
13
|
-
* reposition the tooltip without having a visible shift. The transition
|
|
14
|
-
* is fast enough that it should not be perceptible.
|
|
15
|
-
*/
|
|
16
7
|
export declare const StyledTooltipWrapper: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
|
|
17
8
|
zIndex?: string | number | undefined;
|
|
18
9
|
}, never>;
|
|
@@ -5,13 +5,10 @@
|
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
7
|
import { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
8
|
-
import { Modifiers } from 'popper.js';
|
|
9
8
|
export declare const PLACEMENT: readonly ["auto", "top", "top-start", "top-end", "bottom", "bottom-start", "bottom-end", "end", "end-top", "end-bottom", "start", "start-top", "start-bottom"];
|
|
10
|
-
export declare const POPPER_PLACEMENT: readonly ["auto", "top", "top-start", "top-end", "bottom", "bottom-start", "bottom-end", "right", "right-start", "right-end", "left", "left-start", "left-end"];
|
|
11
9
|
export declare const SIZE: readonly ["small", "medium", "large", "extra-large"];
|
|
12
10
|
export declare const TYPE: readonly ["light", "dark"];
|
|
13
11
|
export type GardenPlacement = (typeof PLACEMENT)[number];
|
|
14
|
-
export type PopperPlacement = (typeof POPPER_PLACEMENT)[number];
|
|
15
12
|
export interface ITooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'content'> {
|
|
16
13
|
/** Appends the tooltip to the element provided */
|
|
17
14
|
appendToNode?: Element;
|
|
@@ -19,16 +16,10 @@ export interface ITooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'con
|
|
|
19
16
|
hasArrow?: boolean;
|
|
20
17
|
/** Adds milliseconds of delay to the opening and closing of the tooltip */
|
|
21
18
|
delayMS?: number;
|
|
22
|
-
/** Allows the tooltip to reposition during browser resize events */
|
|
23
|
-
eventsEnabled?: boolean;
|
|
24
19
|
/** Defines the content of the tooltip */
|
|
25
20
|
content: ReactNode;
|
|
26
|
-
/**
|
|
27
|
-
* Adjusts the placement of the tooltip
|
|
28
|
-
**/
|
|
21
|
+
/** Adjusts the placement of the tooltip */
|
|
29
22
|
placement?: GardenPlacement;
|
|
30
|
-
/** Passes configurations to the [Popper instance](https://popper.js.org/docs/v2/modifiers/) */
|
|
31
|
-
popperModifiers?: Modifiers;
|
|
32
23
|
/** Adjusts the padding and font size */
|
|
33
24
|
size?: (typeof SIZE)[number];
|
|
34
25
|
/** Specifies the tooltip type */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zendeskgarden/react-tooltips",
|
|
3
|
-
"version": "9.0.0-next.
|
|
3
|
+
"version": "9.0.0-next.2",
|
|
4
4
|
"description": "Collection of components and render prop containers relating to Tooltips in the Garden Design System",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Zendesk Garden <garden@zendesk.com>",
|
|
@@ -21,21 +21,21 @@
|
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"types": "dist/typings/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@floating-ui/react-dom": "^2.0.0",
|
|
24
25
|
"@zendeskgarden/container-tooltip": "^1.0.0",
|
|
25
26
|
"@zendeskgarden/container-utilities": "^2.0.0",
|
|
26
27
|
"polished": "^4.0.0",
|
|
27
28
|
"prop-types": "^15.5.7",
|
|
28
|
-
"react-merge-refs": "^2.0.0"
|
|
29
|
-
"react-popper": "^1.3.4"
|
|
29
|
+
"react-merge-refs": "^2.0.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@zendeskgarden/react-theming": "^8.1.0",
|
|
33
33
|
"react": ">=16.8.0",
|
|
34
34
|
"react-dom": ">=16.8.0",
|
|
35
|
-
"styled-components": "^
|
|
35
|
+
"styled-components": "^5.1.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@zendeskgarden/react-theming": "^9.0.0-next.
|
|
38
|
+
"@zendeskgarden/react-theming": "^9.0.0-next.2"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"components",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"zendeskgarden:src": "src/index.ts",
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "e47dd011fedf130106acdb485a023340564171af"
|
|
51
51
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright Zendesk, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
-
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
-
*/
|
|
7
|
-
import { GardenPlacement, PopperPlacement } from '../types';
|
|
8
|
-
/**
|
|
9
|
-
* Convert Garden RTL aware placement to Popper.JS valid placement
|
|
10
|
-
* @param {String} gardenPlacement
|
|
11
|
-
*/
|
|
12
|
-
export declare function getPopperPlacement(gardenPlacement: GardenPlacement): "auto" | "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "right" | "right-start" | "right-end" | "left" | "left-start" | "left-end";
|
|
13
|
-
/**
|
|
14
|
-
* Convert Garden RTL aware placement to RTL equivalent Popper.JS placement
|
|
15
|
-
* @param {String} gardenPlacement
|
|
16
|
-
*/
|
|
17
|
-
export declare function getRtlPopperPlacement(gardenPlacement: GardenPlacement): "auto" | "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "right" | "right-start" | "right-end" | "left" | "left-start" | "left-end";
|
|
18
|
-
/**
|
|
19
|
-
* Convert Popper.JS placement to corresponding arrow position
|
|
20
|
-
* @param {String} popperPlacement
|
|
21
|
-
*/
|
|
22
|
-
export declare function getArrowPosition(popperPlacement: PopperPlacement): "top" | "bottom" | "right" | "left" | "top-left" | "top-right" | "right-top" | "right-bottom" | "bottom-left" | "bottom-right" | "left-top" | "left-bottom";
|