@zendeskgarden/react-tooltips 9.0.0-next.1 → 9.0.0-next.10

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.esm.js DELETED
@@ -1,361 +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
-
8
- import React, { useContext, useRef, useEffect, cloneElement, forwardRef } from 'react';
9
- import { createPortal } from 'react-dom';
10
- import PropTypes from 'prop-types';
11
- import styled, { css, ThemeContext } from 'styled-components';
12
- import { mergeRefs } from 'react-merge-refs';
13
- import { useTooltip } from '@zendeskgarden/container-tooltip';
14
- import { getControlledValue, composeEventHandlers } from '@zendeskgarden/container-utilities';
15
- import { Manager, Reference, Popper } from 'react-popper';
16
- import { retrieveComponentStyles, DEFAULT_THEME, getLineHeight, arrowStyles, getColor } from '@zendeskgarden/react-theming';
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
- }
69
-
70
- const COMPONENT_ID$2 = 'tooltip.paragraph';
71
- const StyledParagraph = styled.p.attrs({
72
- 'data-garden-id': COMPONENT_ID$2,
73
- 'data-garden-version': '9.0.0-next.1'
74
- }).withConfig({
75
- displayName: "StyledParagraph",
76
- componentId: "sc-wuqkfc-0"
77
- })(["margin:0;", ";"], props => retrieveComponentStyles(COMPONENT_ID$2, props));
78
- StyledParagraph.defaultProps = {
79
- theme: DEFAULT_THEME
80
- };
81
-
82
- const COMPONENT_ID$1 = 'tooltip.title';
83
- const StyledTitle = styled.strong.attrs({
84
- 'data-garden-id': COMPONENT_ID$1,
85
- 'data-garden-version': '9.0.0-next.1'
86
- }).withConfig({
87
- displayName: "StyledTitle",
88
- componentId: "sc-vnjcvz-0"
89
- })(["display:none;margin:0;font-weight:", ";", ";"], props => props.theme.fontWeights.semibold, props => retrieveComponentStyles(COMPONENT_ID$1, props));
90
- StyledTitle.defaultProps = {
91
- theme: DEFAULT_THEME
92
- };
93
-
94
- const COMPONENT_ID = 'tooltip.tooltip';
95
- const sizeStyles = _ref => {
96
- let {
97
- theme,
98
- size,
99
- type,
100
- placement,
101
- hasArrow
102
- } = _ref;
103
- let margin = `${theme.space.base * 1.5}px`;
104
- let borderRadius = theme.borderRadii.sm;
105
- let padding = '0 1em';
106
- let maxWidth;
107
- let overflowWrap;
108
- let whiteSpace = 'nowrap';
109
- let lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.sm);
110
- let fontSize = theme.fontSizes.sm;
111
- let titleDisplay;
112
- let paragraphMarginTop;
113
- let wordWrap;
114
- if (size !== 'small') {
115
- borderRadius = theme.borderRadii.md;
116
- overflowWrap = 'break-word';
117
- whiteSpace = 'normal';
118
- wordWrap = 'break-word';
119
- }
120
- if (size === 'extra-large') {
121
- padding = `${theme.space.base * 10}px`;
122
- maxWidth = `460px`;
123
- lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
124
- paragraphMarginTop = `${theme.space.base * 2.5}px`;
125
- } else if (size === 'large') {
126
- padding = `${theme.space.base * 5}px`;
127
- maxWidth = `270px`;
128
- lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
129
- paragraphMarginTop = `${theme.space.base * 2}px`;
130
- } else if (size === 'medium') {
131
- padding = '1em';
132
- maxWidth = `140px`;
133
- lineHeight = getLineHeight(theme.space.base * 4, theme.fontSizes.sm);
134
- }
135
- if (size === 'extra-large' || size === 'large') {
136
- fontSize = theme.fontSizes.md;
137
- titleDisplay = 'block';
138
- }
139
- let arrowSize;
140
- let arrowInset;
141
- if (hasArrow) {
142
- if (size === 'small' || size === 'medium') {
143
- arrowSize = margin;
144
- arrowInset = type === 'dark' ? '1px' : '0';
145
- } else {
146
- arrowInset = type === 'dark' ? '2px' : '1px';
147
- if (size === 'large') {
148
- margin = `${theme.space.base * 2}px`;
149
- arrowSize = margin;
150
- } else if (size === 'extra-large') {
151
- margin = `${theme.space.base * 3}px`;
152
- arrowSize = `${theme.space.base * 2.5}px`;
153
- }
154
- }
155
- }
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), {
157
- size: arrowSize,
158
- inset: arrowInset
159
- }), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
160
- };
161
- const colorStyles = _ref2 => {
162
- let {
163
- theme,
164
- type
165
- } = _ref2;
166
- let border;
167
- let boxShadow = theme.shadows.lg(`${theme.space.base}px`, `${theme.space.base * 2}px`, getColor('chromeHue', 600, theme, 0.15));
168
- let backgroundColor = getColor('chromeHue', 700, theme);
169
- let color = theme.colors.background;
170
- let titleColor;
171
- if (type === 'light') {
172
- boxShadow = theme.shadows.lg(`${theme.space.base * 3}px`, `${theme.space.base * 5}px`, getColor('chromeHue', 600, theme, 0.15));
173
- border = `${theme.borders.sm} ${getColor('neutralHue', 300, theme)}`;
174
- backgroundColor = theme.colors.background;
175
- color = getColor('neutralHue', 700, theme);
176
- titleColor = theme.colors.foreground;
177
- }
178
- return css(["border:", ";box-shadow:", ";background-color:", ";color:", ";", "{color:", ";}"], border, boxShadow, backgroundColor, color, StyledTitle, titleColor);
179
- };
180
- const StyledTooltip = styled.div.attrs({
181
- 'data-garden-id': COMPONENT_ID,
182
- 'data-garden-version': '9.0.0-next.1'
183
- }).withConfig({
184
- displayName: "StyledTooltip",
185
- componentId: "sc-gzzjq4-0"
186
- })(["display:inline-block;box-sizing:border-box;direction:", ";text-align:", ";font-weight:", ";", ";&[aria-hidden='true']{display:none;}", ";", ";"], props => props.theme.rtl && 'rtl', props => props.theme.rtl ? 'right' : 'left', props => props.theme.fontWeights.regular, props => sizeStyles(props), colorStyles, props => retrieveComponentStyles(COMPONENT_ID, props));
187
- StyledTooltip.defaultProps = {
188
- theme: DEFAULT_THEME
189
- };
190
-
191
- const StyledTooltipWrapper = styled.div.withConfig({
192
- displayName: "StyledTooltipWrapper",
193
- componentId: "sc-1b7q9q6-0"
194
- })(["transition:opacity 10ms;opacity:1;z-index:", ";&[aria-hidden='true']{visibility:hidden;opacity:0;}"], props => props.zIndex);
195
- StyledTooltipWrapper.defaultProps = {
196
- theme: DEFAULT_THEME
197
- };
198
-
199
- const SHARED_PLACEMENT = ['auto', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end'];
200
- const PLACEMENT = [...SHARED_PLACEMENT, 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
201
- const SIZE = ['small', 'medium', 'large', 'extra-large'];
202
- const TYPE = ['light', 'dark'];
203
-
204
- const Tooltip = _ref => {
205
- let {
206
- id,
207
- delayMS,
208
- isInitialVisible,
209
- content,
210
- refKey,
211
- placement,
212
- eventsEnabled,
213
- popperModifiers,
214
- children,
215
- hasArrow,
216
- size,
217
- type,
218
- appendToNode,
219
- zIndex,
220
- isVisible: externalIsVisible,
221
- ...otherProps
222
- } = _ref;
223
- const {
224
- rtl
225
- } = useContext(ThemeContext);
226
- const scheduleUpdateRef = useRef();
227
- const {
228
- isVisible,
229
- getTooltipProps,
230
- getTriggerProps,
231
- openTooltip,
232
- closeTooltip
233
- } = useTooltip({
234
- id,
235
- delayMilliseconds: delayMS,
236
- isVisible: isInitialVisible
237
- });
238
- const controlledIsVisible = getControlledValue(externalIsVisible, isVisible);
239
- useEffect(() => {
240
- if (controlledIsVisible && scheduleUpdateRef.current) {
241
- scheduleUpdateRef.current();
242
- }
243
- }, [controlledIsVisible, content]);
244
- const popperPlacement = rtl ? getRtlPopperPlacement(placement) : getPopperPlacement(placement);
245
- const singleChild = React.Children.only(children);
246
- const modifiers = {
247
- preventOverflow: {
248
- boundariesElement: 'window'
249
- },
250
- ...popperModifiers
251
- };
252
- return React.createElement(Manager, null, React.createElement(Reference, null, _ref2 => {
253
- let {
254
- ref
255
- } = _ref2;
256
- return cloneElement(singleChild, getTriggerProps({
257
- ...singleChild.props,
258
- [refKey]: mergeRefs([ref, singleChild.ref ? singleChild.ref : null])
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);
307
- }
308
- return tooltip;
309
- }));
310
- };
311
- Tooltip.displayName = 'Tooltip';
312
- Tooltip.propTypes = {
313
- appendToNode: PropTypes.any,
314
- hasArrow: PropTypes.bool,
315
- delayMS: PropTypes.number,
316
- eventsEnabled: PropTypes.bool,
317
- id: PropTypes.string,
318
- content: PropTypes.node.isRequired,
319
- placement: PropTypes.oneOf(PLACEMENT),
320
- popperModifiers: PropTypes.any,
321
- size: PropTypes.oneOf(SIZE),
322
- type: PropTypes.oneOf(TYPE),
323
- zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
324
- isInitialVisible: PropTypes.bool,
325
- refKey: PropTypes.string
326
- };
327
- Tooltip.defaultProps = {
328
- hasArrow: true,
329
- eventsEnabled: true,
330
- type: 'dark',
331
- placement: 'top',
332
- delayMS: 500,
333
- refKey: 'ref'
334
- };
335
-
336
- function _extends() {
337
- _extends = Object.assign ? Object.assign.bind() : function (target) {
338
- for (var i = 1; i < arguments.length; i++) {
339
- var source = arguments[i];
340
- for (var key in source) {
341
- if (Object.prototype.hasOwnProperty.call(source, key)) {
342
- target[key] = source[key];
343
- }
344
- }
345
- }
346
- return target;
347
- };
348
- return _extends.apply(this, arguments);
349
- }
350
-
351
- const Paragraph = forwardRef((props, ref) => React.createElement(StyledParagraph, _extends({
352
- ref: ref
353
- }, props)));
354
- Paragraph.displayName = 'Paragraph';
355
-
356
- const Title = forwardRef((props, ref) => React.createElement(StyledTitle, _extends({
357
- ref: ref
358
- }, props)));
359
- Title.displayName = 'Title';
360
-
361
- export { Paragraph, Title, Tooltip };
@@ -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";