@zendeskgarden/react-tooltips 8.75.0 → 8.76.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.
@@ -0,0 +1,18 @@
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 React, { forwardRef } from 'react';
8
+ import { StyledParagraph } from '../styled/StyledParagraph.js';
9
+ import '../styled/StyledTitle.js';
10
+ import '../styled/StyledTooltip.js';
11
+ import '../styled/StyledTooltipWrapper.js';
12
+
13
+ const Paragraph = forwardRef((props, ref) => React.createElement(StyledParagraph, Object.assign({
14
+ ref: ref
15
+ }, props)));
16
+ Paragraph.displayName = 'Paragraph';
17
+
18
+ export { Paragraph };
@@ -0,0 +1,18 @@
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 React, { forwardRef } from 'react';
8
+ import '../styled/StyledParagraph.js';
9
+ import { StyledTitle } from '../styled/StyledTitle.js';
10
+ import '../styled/StyledTooltip.js';
11
+ import '../styled/StyledTooltipWrapper.js';
12
+
13
+ const Title = forwardRef((props, ref) => React.createElement(StyledTitle, Object.assign({
14
+ ref: ref
15
+ }, props)));
16
+ Title.displayName = 'Title';
17
+
18
+ export { Title };
@@ -0,0 +1,154 @@
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 React, { useContext, useRef, useEffect, cloneElement } from 'react';
8
+ import { createPortal } from 'react-dom';
9
+ import PropTypes from 'prop-types';
10
+ import { ThemeContext } from 'styled-components';
11
+ import mergeRefs from 'react-merge-refs';
12
+ import { useTooltip } from '@zendeskgarden/container-tooltip';
13
+ import { getControlledValue, composeEventHandlers } from '@zendeskgarden/container-utilities';
14
+ import { Manager, Reference, Popper } from 'react-popper';
15
+ import { getRtlPopperPlacement, getPopperPlacement } from '../utils/gardenPlacements.js';
16
+ import '../styled/StyledParagraph.js';
17
+ import '../styled/StyledTitle.js';
18
+ import { StyledTooltip } from '../styled/StyledTooltip.js';
19
+ import { StyledTooltipWrapper } from '../styled/StyledTooltipWrapper.js';
20
+ import { PLACEMENT, SIZE, TYPE } from '../types/index.js';
21
+
22
+ const Tooltip = _ref => {
23
+ let {
24
+ id,
25
+ delayMS,
26
+ isInitialVisible,
27
+ content,
28
+ refKey,
29
+ placement,
30
+ eventsEnabled,
31
+ popperModifiers,
32
+ children,
33
+ hasArrow,
34
+ size,
35
+ type,
36
+ appendToNode,
37
+ zIndex,
38
+ isVisible: externalIsVisible,
39
+ ...otherProps
40
+ } = _ref;
41
+ const {
42
+ rtl
43
+ } = useContext(ThemeContext);
44
+ const scheduleUpdateRef = useRef();
45
+ const {
46
+ isVisible,
47
+ getTooltipProps,
48
+ getTriggerProps,
49
+ openTooltip,
50
+ closeTooltip
51
+ } = useTooltip({
52
+ id,
53
+ delayMilliseconds: delayMS,
54
+ isVisible: isInitialVisible
55
+ });
56
+ const controlledIsVisible = getControlledValue(externalIsVisible, isVisible);
57
+ useEffect(() => {
58
+ if (controlledIsVisible && scheduleUpdateRef.current) {
59
+ scheduleUpdateRef.current();
60
+ }
61
+ }, [controlledIsVisible, content]);
62
+ const popperPlacement = rtl ? getRtlPopperPlacement(placement) : getPopperPlacement(placement);
63
+ const singleChild = React.Children.only(children);
64
+ const modifiers = {
65
+ preventOverflow: {
66
+ boundariesElement: 'window'
67
+ },
68
+ ...popperModifiers
69
+ };
70
+ return React.createElement(Manager, null, React.createElement(Reference, null, _ref2 => {
71
+ let {
72
+ ref
73
+ } = _ref2;
74
+ return cloneElement(singleChild, getTriggerProps({
75
+ ...singleChild.props,
76
+ [refKey]: mergeRefs([ref, singleChild.ref ? singleChild.ref : null])
77
+ }));
78
+ }), React.createElement(Popper, {
79
+ placement: popperPlacement,
80
+ eventsEnabled: controlledIsVisible && eventsEnabled,
81
+ modifiers: modifiers
82
+ }, _ref3 => {
83
+ let {
84
+ ref,
85
+ style,
86
+ scheduleUpdate,
87
+ placement: currentPlacement
88
+ } = _ref3;
89
+ scheduleUpdateRef.current = scheduleUpdate;
90
+ const {
91
+ onFocus,
92
+ onBlur,
93
+ ...otherTooltipProps
94
+ } = otherProps;
95
+ let computedSize = size;
96
+ if (computedSize === undefined) {
97
+ if (type === 'dark') {
98
+ computedSize = 'small';
99
+ } else {
100
+ computedSize = 'large';
101
+ }
102
+ }
103
+ const tooltipProps = {
104
+ hasArrow,
105
+ placement: currentPlacement,
106
+ size: computedSize,
107
+ onFocus: composeEventHandlers(onFocus, () => {
108
+ openTooltip();
109
+ }),
110
+ onBlur: composeEventHandlers(onBlur, () => {
111
+ closeTooltip(0);
112
+ }),
113
+ 'aria-hidden': !controlledIsVisible,
114
+ type,
115
+ ...otherTooltipProps
116
+ };
117
+ const tooltip = React.createElement(StyledTooltipWrapper, {
118
+ ref: controlledIsVisible ? ref : null,
119
+ style: style,
120
+ zIndex: zIndex,
121
+ "aria-hidden": !controlledIsVisible
122
+ }, React.createElement(StyledTooltip, getTooltipProps(tooltipProps), content));
123
+ if (appendToNode) {
124
+ return createPortal(tooltip, appendToNode);
125
+ }
126
+ return tooltip;
127
+ }));
128
+ };
129
+ Tooltip.displayName = 'Tooltip';
130
+ Tooltip.propTypes = {
131
+ appendToNode: PropTypes.any,
132
+ hasArrow: PropTypes.bool,
133
+ delayMS: PropTypes.number,
134
+ eventsEnabled: PropTypes.bool,
135
+ id: PropTypes.string,
136
+ content: PropTypes.node.isRequired,
137
+ placement: PropTypes.oneOf(PLACEMENT),
138
+ popperModifiers: PropTypes.any,
139
+ size: PropTypes.oneOf(SIZE),
140
+ type: PropTypes.oneOf(TYPE),
141
+ zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
142
+ isInitialVisible: PropTypes.bool,
143
+ refKey: PropTypes.string
144
+ };
145
+ Tooltip.defaultProps = {
146
+ hasArrow: true,
147
+ eventsEnabled: true,
148
+ type: 'dark',
149
+ placement: 'top',
150
+ delayMS: 500,
151
+ refKey: 'ref'
152
+ };
153
+
154
+ export { Tooltip };
@@ -0,0 +1,9 @@
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
+ export { Tooltip } from './elements/Tooltip.js';
8
+ export { Paragraph } from './elements/Paragraph.js';
9
+ export { Title } from './elements/Title.js';
@@ -0,0 +1,22 @@
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 styled from 'styled-components';
8
+ import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
9
+
10
+ const COMPONENT_ID = 'tooltip.paragraph';
11
+ const StyledParagraph = styled.p.attrs({
12
+ 'data-garden-id': COMPONENT_ID,
13
+ 'data-garden-version': '8.76.0'
14
+ }).withConfig({
15
+ displayName: "StyledParagraph",
16
+ componentId: "sc-wuqkfc-0"
17
+ })(["margin:0;", ";"], props => retrieveComponentStyles(COMPONENT_ID, props));
18
+ StyledParagraph.defaultProps = {
19
+ theme: DEFAULT_THEME
20
+ };
21
+
22
+ export { StyledParagraph };
@@ -0,0 +1,22 @@
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 styled from 'styled-components';
8
+ import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
9
+
10
+ const COMPONENT_ID = 'tooltip.title';
11
+ const StyledTitle = styled.strong.attrs({
12
+ 'data-garden-id': COMPONENT_ID,
13
+ 'data-garden-version': '8.76.0'
14
+ }).withConfig({
15
+ displayName: "StyledTitle",
16
+ componentId: "sc-vnjcvz-0"
17
+ })(["display:none;margin:0;font-weight:", ";", ";"], props => props.theme.fontWeights.semibold, props => retrieveComponentStyles(COMPONENT_ID, props));
18
+ StyledTitle.defaultProps = {
19
+ theme: DEFAULT_THEME
20
+ };
21
+
22
+ export { StyledTitle };
@@ -0,0 +1,110 @@
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 styled, { css } from 'styled-components';
8
+ import { retrieveComponentStyles, DEFAULT_THEME, getLineHeight, arrowStyles, getColorV8 } from '@zendeskgarden/react-theming';
9
+ import { getArrowPosition } from '../utils/gardenPlacements.js';
10
+ import { StyledParagraph } from './StyledParagraph.js';
11
+ import { StyledTitle } from './StyledTitle.js';
12
+
13
+ const COMPONENT_ID = 'tooltip.tooltip';
14
+ const sizeStyles = _ref => {
15
+ let {
16
+ theme,
17
+ size,
18
+ type,
19
+ placement,
20
+ hasArrow
21
+ } = _ref;
22
+ let margin = `${theme.space.base * 1.5}px`;
23
+ let borderRadius = theme.borderRadii.sm;
24
+ let padding = '0 1em';
25
+ let maxWidth;
26
+ let overflowWrap;
27
+ let whiteSpace = 'nowrap';
28
+ let lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.sm);
29
+ let fontSize = theme.fontSizes.sm;
30
+ let titleDisplay;
31
+ let paragraphMarginTop;
32
+ let wordWrap;
33
+ if (size !== 'small') {
34
+ borderRadius = theme.borderRadii.md;
35
+ overflowWrap = 'break-word';
36
+ whiteSpace = 'normal';
37
+ wordWrap = 'break-word';
38
+ }
39
+ if (size === 'extra-large') {
40
+ padding = `${theme.space.base * 10}px`;
41
+ maxWidth = `460px`;
42
+ lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
43
+ paragraphMarginTop = `${theme.space.base * 2.5}px`;
44
+ } else if (size === 'large') {
45
+ padding = `${theme.space.base * 5}px`;
46
+ maxWidth = `270px`;
47
+ lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
48
+ paragraphMarginTop = `${theme.space.base * 2}px`;
49
+ } else if (size === 'medium') {
50
+ padding = '1em';
51
+ maxWidth = `140px`;
52
+ lineHeight = getLineHeight(theme.space.base * 4, theme.fontSizes.sm);
53
+ }
54
+ if (size === 'extra-large' || size === 'large') {
55
+ fontSize = theme.fontSizes.md;
56
+ titleDisplay = 'block';
57
+ }
58
+ let arrowSize;
59
+ let arrowInset;
60
+ if (hasArrow) {
61
+ if (size === 'small' || size === 'medium') {
62
+ arrowSize = margin;
63
+ arrowInset = type === 'dark' ? '1px' : '0';
64
+ } else {
65
+ arrowInset = type === 'dark' ? '2px' : '1px';
66
+ if (size === 'large') {
67
+ margin = `${theme.space.base * 2}px`;
68
+ arrowSize = margin;
69
+ } else if (size === 'extra-large') {
70
+ margin = `${theme.space.base * 3}px`;
71
+ arrowSize = `${theme.space.base * 2.5}px`;
72
+ }
73
+ }
74
+ }
75
+ 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), {
76
+ size: arrowSize,
77
+ inset: arrowInset
78
+ }), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
79
+ };
80
+ const colorStyles = _ref2 => {
81
+ let {
82
+ theme,
83
+ type
84
+ } = _ref2;
85
+ let border;
86
+ let boxShadow = theme.shadows.lg(`${theme.space.base}px`, `${theme.space.base * 2}px`, getColorV8('chromeHue', 600, theme, 0.15));
87
+ let backgroundColor = getColorV8('chromeHue', 700, theme);
88
+ let color = getColorV8('background', 600 , theme);
89
+ let titleColor;
90
+ if (type === 'light') {
91
+ boxShadow = theme.shadows.lg(`${theme.space.base * 3}px`, `${theme.space.base * 5}px`, getColorV8('chromeHue', 600, theme, 0.15));
92
+ border = `${theme.borders.sm} ${getColorV8('neutralHue', 300, theme)}`;
93
+ backgroundColor = getColorV8('background', 600 , theme);
94
+ color = getColorV8('neutralHue', 700, theme);
95
+ titleColor = getColorV8('foreground', 600 , theme);
96
+ }
97
+ return css(["border:", ";box-shadow:", ";background-color:", ";color:", ";", "{color:", ";}"], border, boxShadow, backgroundColor, color, StyledTitle, titleColor);
98
+ };
99
+ const StyledTooltip = styled.div.attrs({
100
+ 'data-garden-id': COMPONENT_ID,
101
+ 'data-garden-version': '8.76.0'
102
+ }).withConfig({
103
+ displayName: "StyledTooltip",
104
+ componentId: "sc-gzzjq4-0"
105
+ })(["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));
106
+ StyledTooltip.defaultProps = {
107
+ theme: DEFAULT_THEME
108
+ };
109
+
110
+ export { StyledTooltip };
@@ -0,0 +1,18 @@
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 styled from 'styled-components';
8
+ import { DEFAULT_THEME } from '@zendeskgarden/react-theming';
9
+
10
+ const StyledTooltipWrapper = styled.div.withConfig({
11
+ displayName: "StyledTooltipWrapper",
12
+ componentId: "sc-1b7q9q6-0"
13
+ })(["transition:opacity 10ms;opacity:1;z-index:", ";&[aria-hidden='true']{visibility:hidden;opacity:0;}"], props => props.zIndex);
14
+ StyledTooltipWrapper.defaultProps = {
15
+ theme: DEFAULT_THEME
16
+ };
17
+
18
+ export { StyledTooltipWrapper };
@@ -0,0 +1,12 @@
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
+ const SHARED_PLACEMENT = ['auto', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end'];
8
+ const PLACEMENT = [...SHARED_PLACEMENT, 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
9
+ const SIZE = ['small', 'medium', 'large', 'extra-large'];
10
+ const TYPE = ['light', 'dark'];
11
+
12
+ export { PLACEMENT, SIZE, TYPE };
@@ -0,0 +1,59 @@
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
+ function getPopperPlacement(gardenPlacement) {
8
+ const gardenToPopperMapping = {
9
+ auto: 'auto',
10
+ top: 'top',
11
+ 'top-start': 'top-start',
12
+ 'top-end': 'top-end',
13
+ bottom: 'bottom',
14
+ 'bottom-start': 'bottom-start',
15
+ 'bottom-end': 'bottom-end',
16
+ end: 'right',
17
+ 'end-top': 'right-start',
18
+ 'end-bottom': 'right-end',
19
+ start: 'left',
20
+ 'start-top': 'left-start',
21
+ 'start-bottom': 'left-end'
22
+ };
23
+ return gardenToPopperMapping[gardenPlacement];
24
+ }
25
+ function getRtlPopperPlacement(gardenPlacement) {
26
+ const rtlPlacementMappings = {
27
+ left: 'right',
28
+ 'left-start': 'right-start',
29
+ 'left-end': 'right-end',
30
+ 'top-start': 'top-end',
31
+ 'top-end': 'top-start',
32
+ right: 'left',
33
+ 'right-start': 'left-start',
34
+ 'right-end': 'left-end',
35
+ 'bottom-start': 'bottom-end',
36
+ 'bottom-end': 'bottom-start'
37
+ };
38
+ const popperPlacement = getPopperPlacement(gardenPlacement);
39
+ return rtlPlacementMappings[popperPlacement] || popperPlacement;
40
+ }
41
+ function getArrowPosition(popperPlacement) {
42
+ const arrowPositionMappings = {
43
+ top: 'bottom',
44
+ 'top-start': 'bottom-left',
45
+ 'top-end': 'bottom-right',
46
+ right: 'left',
47
+ 'right-start': 'left-top',
48
+ 'right-end': 'left-bottom',
49
+ bottom: 'top',
50
+ 'bottom-start': 'top-left',
51
+ 'bottom-end': 'top-right',
52
+ left: 'right',
53
+ 'left-start': 'right-top',
54
+ 'left-end': 'right-bottom'
55
+ };
56
+ return arrowPositionMappings[popperPlacement] || 'top';
57
+ }
58
+
59
+ export { getArrowPosition, getPopperPlacement, getRtlPopperPlacement };
package/dist/index.cjs.js CHANGED
@@ -1,10 +1,9 @@
1
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
-
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
+ */
8
7
  'use strict';
9
8
 
10
9
  var React = require('react');
@@ -79,7 +78,7 @@ function getArrowPosition(popperPlacement) {
79
78
  const COMPONENT_ID$2 = 'tooltip.paragraph';
80
79
  const StyledParagraph = styled__default.default.p.attrs({
81
80
  'data-garden-id': COMPONENT_ID$2,
82
- 'data-garden-version': '8.75.0'
81
+ 'data-garden-version': '8.76.0'
83
82
  }).withConfig({
84
83
  displayName: "StyledParagraph",
85
84
  componentId: "sc-wuqkfc-0"
@@ -91,7 +90,7 @@ StyledParagraph.defaultProps = {
91
90
  const COMPONENT_ID$1 = 'tooltip.title';
92
91
  const StyledTitle = styled__default.default.strong.attrs({
93
92
  'data-garden-id': COMPONENT_ID$1,
94
- 'data-garden-version': '8.75.0'
93
+ 'data-garden-version': '8.76.0'
95
94
  }).withConfig({
96
95
  displayName: "StyledTitle",
97
96
  componentId: "sc-vnjcvz-0"
@@ -188,7 +187,7 @@ const colorStyles = _ref2 => {
188
187
  };
189
188
  const StyledTooltip = styled__default.default.div.attrs({
190
189
  'data-garden-id': COMPONENT_ID,
191
- 'data-garden-version': '8.75.0'
190
+ 'data-garden-version': '8.76.0'
192
191
  }).withConfig({
193
192
  displayName: "StyledTooltip",
194
193
  componentId: "sc-gzzjq4-0"
@@ -342,27 +341,12 @@ Tooltip.defaultProps = {
342
341
  refKey: 'ref'
343
342
  };
344
343
 
345
- function _extends() {
346
- _extends = Object.assign ? Object.assign.bind() : function (target) {
347
- for (var i = 1; i < arguments.length; i++) {
348
- var source = arguments[i];
349
- for (var key in source) {
350
- if (Object.prototype.hasOwnProperty.call(source, key)) {
351
- target[key] = source[key];
352
- }
353
- }
354
- }
355
- return target;
356
- };
357
- return _extends.apply(this, arguments);
358
- }
359
-
360
- const Paragraph = React.forwardRef((props, ref) => React__default.default.createElement(StyledParagraph, _extends({
344
+ const Paragraph = React.forwardRef((props, ref) => React__default.default.createElement(StyledParagraph, Object.assign({
361
345
  ref: ref
362
346
  }, props)));
363
347
  Paragraph.displayName = 'Paragraph';
364
348
 
365
- const Title = React.forwardRef((props, ref) => React__default.default.createElement(StyledTitle, _extends({
349
+ const Title = React.forwardRef((props, ref) => React__default.default.createElement(StyledTitle, Object.assign({
366
350
  ref: ref
367
351
  }, props)));
368
352
  Title.displayName = 'Title';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-tooltips",
3
- "version": "8.75.0",
3
+ "version": "8.76.0",
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>",
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/zendeskgarden/react-components/issues"
11
11
  },
12
12
  "main": "dist/index.cjs.js",
13
- "module": "dist/index.esm.js",
13
+ "module": "dist/esm/index.js",
14
14
  "files": [
15
15
  "dist"
16
16
  ],
@@ -29,13 +29,13 @@
29
29
  "react-popper": "^1.3.4"
30
30
  },
31
31
  "peerDependencies": {
32
- "@zendeskgarden/react-theming": "^8.1.0",
32
+ "@zendeskgarden/react-theming": "^8.75.0",
33
33
  "react": ">=16.8.0",
34
34
  "react-dom": ">=16.8.0",
35
35
  "styled-components": "^4.2.0 || ^5.0.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@zendeskgarden/react-theming": "^8.75.0"
38
+ "@zendeskgarden/react-theming": "^8.76.0"
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": "56a54793a611efc223b8e36262d428365613c853"
50
+ "gitHead": "3e52650c39fd1085a2e97b40a43eed7bc1e21937"
51
51
  }
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, getColorV8 } 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': '8.75.0'
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': '8.75.0'
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`, getColorV8('chromeHue', 600, theme, 0.15));
168
- let backgroundColor = getColorV8('chromeHue', 700, theme);
169
- let color = getColorV8('background', 600 , theme);
170
- let titleColor;
171
- if (type === 'light') {
172
- boxShadow = theme.shadows.lg(`${theme.space.base * 3}px`, `${theme.space.base * 5}px`, getColorV8('chromeHue', 600, theme, 0.15));
173
- border = `${theme.borders.sm} ${getColorV8('neutralHue', 300, theme)}`;
174
- backgroundColor = getColorV8('background', 600 , theme);
175
- color = getColorV8('neutralHue', 700, theme);
176
- titleColor = getColorV8('foreground', 600 , theme);
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': '8.75.0'
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 };