@zendeskgarden/react-tooltips 9.0.0-next.7 → 9.0.0-next.8

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,137 @@
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 '../styled/StyledParagraph.js';
15
+ import '../styled/StyledTitle.js';
16
+ import { StyledTooltip } from '../styled/StyledTooltip.js';
17
+ import { StyledTooltipWrapper } from '../styled/StyledTooltipWrapper.js';
18
+ import { PLACEMENT, SIZE, TYPE } from '../types/index.js';
19
+ import { useFloating, platform, autoPlacement, autoUpdate } from '@floating-ui/react-dom';
20
+ import { DEFAULT_THEME, getFloatingPlacements } from '@zendeskgarden/react-theming';
21
+ import { toSize } from './utils.js';
22
+ import { Paragraph } from './Paragraph.js';
23
+ import { Title } from './Title.js';
24
+
25
+ const PLACEMENT_DEFAULT = 'top';
26
+ const TooltipComponent = _ref => {
27
+ let {
28
+ id,
29
+ delayMS,
30
+ isInitialVisible,
31
+ content,
32
+ refKey,
33
+ placement: _placement,
34
+ children,
35
+ hasArrow,
36
+ size,
37
+ type,
38
+ appendToNode,
39
+ zIndex,
40
+ isVisible: externalIsVisible,
41
+ onFocus,
42
+ onBlur,
43
+ ...props
44
+ } = _ref;
45
+ const theme = useContext(ThemeContext) || DEFAULT_THEME;
46
+ const triggerRef = useRef(null);
47
+ const floatingRef = useRef(null);
48
+ const {
49
+ isVisible,
50
+ getTooltipProps,
51
+ getTriggerProps,
52
+ openTooltip,
53
+ closeTooltip
54
+ } = useTooltip({
55
+ id,
56
+ delayMilliseconds: delayMS,
57
+ isVisible: isInitialVisible
58
+ });
59
+ const controlledIsVisible = getControlledValue(externalIsVisible, isVisible);
60
+ const [floatingPlacement] = getFloatingPlacements(theme, _placement === 'auto' ? PLACEMENT_DEFAULT : _placement);
61
+ const {
62
+ refs,
63
+ placement,
64
+ update,
65
+ floatingStyles: {
66
+ transform
67
+ }
68
+ } = useFloating({
69
+ platform: {
70
+ ...platform,
71
+ isRTL: () => theme.rtl
72
+ },
73
+ elements: {
74
+ reference: triggerRef?.current,
75
+ floating: floatingRef?.current
76
+ },
77
+ placement: floatingPlacement,
78
+ middleware: _placement === 'auto' ? [autoPlacement()] : undefined
79
+ });
80
+ useEffect(() => {
81
+ let cleanup;
82
+ if (controlledIsVisible && refs.reference.current && refs.floating.current) {
83
+ cleanup = autoUpdate(refs.reference.current, refs.floating.current, update, {
84
+ elementResize: typeof ResizeObserver === 'function'
85
+ });
86
+ }
87
+ return () => cleanup && cleanup();
88
+ }, [controlledIsVisible, refs.reference, refs.floating, update]);
89
+ const Child = React.Children.only(children);
90
+ const Node = React.createElement(StyledTooltipWrapper, {
91
+ ref: floatingRef,
92
+ style: {
93
+ transform
94
+ },
95
+ zIndex: zIndex,
96
+ "aria-hidden": !controlledIsVisible
97
+ }, React.createElement(StyledTooltip, getTooltipProps({
98
+ hasArrow,
99
+ placement,
100
+ size: toSize(size, type),
101
+ onFocus: composeEventHandlers(onFocus, openTooltip),
102
+ onBlur: composeEventHandlers(onBlur, () => closeTooltip(0)),
103
+ 'aria-hidden': !controlledIsVisible,
104
+ type,
105
+ ...props
106
+ }), content));
107
+ return React.createElement(React.Fragment, null, cloneElement(Child, getTriggerProps({
108
+ ...Child.props,
109
+ [refKey]: mergeRefs([triggerRef, Child.ref ? Child.ref : null])
110
+ })), appendToNode ? createPortal(Node, appendToNode) : Node);
111
+ };
112
+ TooltipComponent.displayName = 'Tooltip';
113
+ TooltipComponent.propTypes = {
114
+ appendToNode: PropTypes.any,
115
+ hasArrow: PropTypes.bool,
116
+ delayMS: PropTypes.number,
117
+ id: PropTypes.string,
118
+ content: PropTypes.node.isRequired,
119
+ placement: PropTypes.oneOf(PLACEMENT),
120
+ size: PropTypes.oneOf(SIZE),
121
+ type: PropTypes.oneOf(TYPE),
122
+ zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
123
+ isInitialVisible: PropTypes.bool,
124
+ refKey: PropTypes.string
125
+ };
126
+ TooltipComponent.defaultProps = {
127
+ hasArrow: true,
128
+ type: 'dark',
129
+ placement: PLACEMENT_DEFAULT,
130
+ delayMS: 500,
131
+ refKey: 'ref'
132
+ };
133
+ const Tooltip = TooltipComponent;
134
+ Tooltip.Paragraph = Paragraph;
135
+ Tooltip.Title = Title;
136
+
137
+ export { PLACEMENT_DEFAULT, Tooltip, TooltipComponent };
@@ -0,0 +1,15 @@
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 toSize = (size, type) => {
8
+ let retVal = size;
9
+ if (retVal === undefined) {
10
+ retVal = type === 'dark' ? 'small' : 'large';
11
+ }
12
+ return retVal;
13
+ };
14
+
15
+ export { toSize };
@@ -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 { Paragraph } from './elements/Paragraph.js';
8
+ export { Title } from './elements/Title.js';
9
+ export { Tooltip } from './elements/Tooltip.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': '9.0.0-next.8'
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': '9.0.0-next.8'
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,109 @@
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, getArrowPosition, getColorV8 } from '@zendeskgarden/react-theming';
9
+ import { StyledParagraph } from './StyledParagraph.js';
10
+ import { StyledTitle } from './StyledTitle.js';
11
+
12
+ const COMPONENT_ID = 'tooltip.tooltip';
13
+ const sizeStyles = _ref => {
14
+ let {
15
+ theme,
16
+ size,
17
+ type,
18
+ placement,
19
+ hasArrow
20
+ } = _ref;
21
+ let margin = `${theme.space.base * 1.5}px`;
22
+ let borderRadius = theme.borderRadii.sm;
23
+ let padding = '0 1em';
24
+ let maxWidth;
25
+ let overflowWrap;
26
+ let whiteSpace = 'nowrap';
27
+ let lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.sm);
28
+ let fontSize = theme.fontSizes.sm;
29
+ let titleDisplay;
30
+ let paragraphMarginTop;
31
+ let wordWrap;
32
+ if (size !== 'small') {
33
+ borderRadius = theme.borderRadii.md;
34
+ overflowWrap = 'break-word';
35
+ whiteSpace = 'normal';
36
+ wordWrap = 'break-word';
37
+ }
38
+ if (size === 'extra-large') {
39
+ padding = `${theme.space.base * 10}px`;
40
+ maxWidth = `460px`;
41
+ lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
42
+ paragraphMarginTop = `${theme.space.base * 2.5}px`;
43
+ } else if (size === 'large') {
44
+ padding = `${theme.space.base * 5}px`;
45
+ maxWidth = `270px`;
46
+ lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
47
+ paragraphMarginTop = `${theme.space.base * 2}px`;
48
+ } else if (size === 'medium') {
49
+ padding = '1em';
50
+ maxWidth = `140px`;
51
+ lineHeight = getLineHeight(theme.space.base * 4, theme.fontSizes.sm);
52
+ }
53
+ if (size === 'extra-large' || size === 'large') {
54
+ fontSize = theme.fontSizes.md;
55
+ titleDisplay = 'block';
56
+ }
57
+ let arrowSize;
58
+ let arrowInset;
59
+ if (hasArrow) {
60
+ if (size === 'small' || size === 'medium') {
61
+ arrowSize = margin;
62
+ arrowInset = type === 'dark' ? '1px' : '0';
63
+ } else {
64
+ arrowInset = type === 'dark' ? '2px' : '1px';
65
+ if (size === 'large') {
66
+ margin = `${theme.space.base * 2}px`;
67
+ arrowSize = margin;
68
+ } else if (size === 'extra-large') {
69
+ margin = `${theme.space.base * 3}px`;
70
+ arrowSize = `${theme.space.base * 2.5}px`;
71
+ }
72
+ }
73
+ }
74
+ 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), {
75
+ size: arrowSize,
76
+ inset: arrowInset
77
+ }), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
78
+ };
79
+ const colorStyles = _ref2 => {
80
+ let {
81
+ theme,
82
+ type
83
+ } = _ref2;
84
+ let border;
85
+ let boxShadow = theme.shadows.lg(`${theme.space.base}px`, `${theme.space.base * 2}px`, getColorV8('chromeHue', 600, theme, 0.15));
86
+ let backgroundColor = getColorV8('chromeHue', 700, theme);
87
+ let color = getColorV8('background', 600 , theme);
88
+ let titleColor;
89
+ if (type === 'light') {
90
+ boxShadow = theme.shadows.lg(`${theme.space.base * 3}px`, `${theme.space.base * 5}px`, getColorV8('chromeHue', 600, theme, 0.15));
91
+ border = `${theme.borders.sm} ${getColorV8('neutralHue', 300, theme)}`;
92
+ backgroundColor = getColorV8('background', 600 , theme);
93
+ color = getColorV8('neutralHue', 700, theme);
94
+ titleColor = getColorV8('foreground', 600 , theme);
95
+ }
96
+ return css(["border:", ";box-shadow:", ";background-color:", ";color:", ";", "{color:", ";}"], border, boxShadow, backgroundColor, color, StyledTitle, titleColor);
97
+ };
98
+ const StyledTooltip = styled.div.attrs({
99
+ 'data-garden-id': COMPONENT_ID,
100
+ 'data-garden-version': '9.0.0-next.8'
101
+ }).withConfig({
102
+ displayName: "StyledTooltip",
103
+ componentId: "sc-gzzjq4-0"
104
+ })(["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));
105
+ StyledTooltip.defaultProps = {
106
+ theme: DEFAULT_THEME
107
+ };
108
+
109
+ 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
+ })(["position:absolute;top:0;left:0;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,13 @@
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 { PLACEMENT as PLACEMENT$1 } from '@zendeskgarden/react-theming';
8
+
9
+ const PLACEMENT = ['auto', ...PLACEMENT$1];
10
+ const SIZE = ['small', 'medium', 'large', 'extra-large'];
11
+ const TYPE = ['light', 'dark'];
12
+
13
+ export { PLACEMENT, SIZE, TYPE };
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');
@@ -23,25 +22,10 @@ var React__default = /*#__PURE__*/_interopDefault(React);
23
22
  var styled__default = /*#__PURE__*/_interopDefault(styled);
24
23
  var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
25
24
 
26
- function _extends() {
27
- _extends = Object.assign ? Object.assign.bind() : function (target) {
28
- for (var i = 1; i < arguments.length; i++) {
29
- var source = arguments[i];
30
- for (var key in source) {
31
- if (Object.prototype.hasOwnProperty.call(source, key)) {
32
- target[key] = source[key];
33
- }
34
- }
35
- }
36
- return target;
37
- };
38
- return _extends.apply(this, arguments);
39
- }
40
-
41
25
  const COMPONENT_ID$2 = 'tooltip.paragraph';
42
26
  const StyledParagraph = styled__default.default.p.attrs({
43
27
  'data-garden-id': COMPONENT_ID$2,
44
- 'data-garden-version': '9.0.0-next.7'
28
+ 'data-garden-version': '9.0.0-next.8'
45
29
  }).withConfig({
46
30
  displayName: "StyledParagraph",
47
31
  componentId: "sc-wuqkfc-0"
@@ -53,7 +37,7 @@ StyledParagraph.defaultProps = {
53
37
  const COMPONENT_ID$1 = 'tooltip.title';
54
38
  const StyledTitle = styled__default.default.strong.attrs({
55
39
  'data-garden-id': COMPONENT_ID$1,
56
- 'data-garden-version': '9.0.0-next.7'
40
+ 'data-garden-version': '9.0.0-next.8'
57
41
  }).withConfig({
58
42
  displayName: "StyledTitle",
59
43
  componentId: "sc-vnjcvz-0"
@@ -150,7 +134,7 @@ const colorStyles = _ref2 => {
150
134
  };
151
135
  const StyledTooltip = styled__default.default.div.attrs({
152
136
  'data-garden-id': COMPONENT_ID,
153
- 'data-garden-version': '9.0.0-next.7'
137
+ 'data-garden-version': '9.0.0-next.8'
154
138
  }).withConfig({
155
139
  displayName: "StyledTooltip",
156
140
  componentId: "sc-gzzjq4-0"
@@ -167,12 +151,12 @@ StyledTooltipWrapper.defaultProps = {
167
151
  theme: reactTheming.DEFAULT_THEME
168
152
  };
169
153
 
170
- const Paragraph = React.forwardRef((props, ref) => React__default.default.createElement(StyledParagraph, _extends({
154
+ const Paragraph = React.forwardRef((props, ref) => React__default.default.createElement(StyledParagraph, Object.assign({
171
155
  ref: ref
172
156
  }, props)));
173
157
  Paragraph.displayName = 'Paragraph';
174
158
 
175
- const Title = React.forwardRef((props, ref) => React__default.default.createElement(StyledTitle, _extends({
159
+ const Title = React.forwardRef((props, ref) => React__default.default.createElement(StyledTitle, Object.assign({
176
160
  ref: ref
177
161
  }, props)));
178
162
  Title.displayName = 'Title';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-tooltips",
3
- "version": "9.0.0-next.7",
3
+ "version": "9.0.0-next.8",
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-merge-refs": "^2.0.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@zendeskgarden/react-theming": "^8.1.0",
32
+ "@zendeskgarden/react-theming": ">=9.0.0-next",
33
33
  "react": ">=16.8.0",
34
34
  "react-dom": ">=16.8.0",
35
35
  "styled-components": "^5.3.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@zendeskgarden/react-theming": "^9.0.0-next.7"
38
+ "@zendeskgarden/react-theming": "^9.0.0-next.8"
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": "50a2b45b2e237a490a6d460818d33498b92479ec"
50
+ "gitHead": "a3d6534843d5a4f5cb60b52bc67264f3230f2da0"
51
51
  }
package/dist/index.esm.js DELETED
@@ -1,296 +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, { forwardRef, useContext, useRef, useEffect, cloneElement } from 'react';
9
- import styled, { css, ThemeContext } from 'styled-components';
10
- import { retrieveComponentStyles, DEFAULT_THEME, getLineHeight, arrowStyles, getArrowPosition, getColorV8, PLACEMENT as PLACEMENT$1, getFloatingPlacements } from '@zendeskgarden/react-theming';
11
- import { createPortal } from 'react-dom';
12
- import PropTypes from 'prop-types';
13
- import { mergeRefs } from 'react-merge-refs';
14
- import { useTooltip } from '@zendeskgarden/container-tooltip';
15
- import { getControlledValue, composeEventHandlers } from '@zendeskgarden/container-utilities';
16
- import { useFloating, platform, autoPlacement, autoUpdate } from '@floating-ui/react-dom';
17
-
18
- function _extends() {
19
- _extends = Object.assign ? Object.assign.bind() : function (target) {
20
- for (var i = 1; i < arguments.length; i++) {
21
- var source = arguments[i];
22
- for (var key in source) {
23
- if (Object.prototype.hasOwnProperty.call(source, key)) {
24
- target[key] = source[key];
25
- }
26
- }
27
- }
28
- return target;
29
- };
30
- return _extends.apply(this, arguments);
31
- }
32
-
33
- const COMPONENT_ID$2 = 'tooltip.paragraph';
34
- const StyledParagraph = styled.p.attrs({
35
- 'data-garden-id': COMPONENT_ID$2,
36
- 'data-garden-version': '9.0.0-next.7'
37
- }).withConfig({
38
- displayName: "StyledParagraph",
39
- componentId: "sc-wuqkfc-0"
40
- })(["margin:0;", ";"], props => retrieveComponentStyles(COMPONENT_ID$2, props));
41
- StyledParagraph.defaultProps = {
42
- theme: DEFAULT_THEME
43
- };
44
-
45
- const COMPONENT_ID$1 = 'tooltip.title';
46
- const StyledTitle = styled.strong.attrs({
47
- 'data-garden-id': COMPONENT_ID$1,
48
- 'data-garden-version': '9.0.0-next.7'
49
- }).withConfig({
50
- displayName: "StyledTitle",
51
- componentId: "sc-vnjcvz-0"
52
- })(["display:none;margin:0;font-weight:", ";", ";"], props => props.theme.fontWeights.semibold, props => retrieveComponentStyles(COMPONENT_ID$1, props));
53
- StyledTitle.defaultProps = {
54
- theme: DEFAULT_THEME
55
- };
56
-
57
- const COMPONENT_ID = 'tooltip.tooltip';
58
- const sizeStyles = _ref => {
59
- let {
60
- theme,
61
- size,
62
- type,
63
- placement,
64
- hasArrow
65
- } = _ref;
66
- let margin = `${theme.space.base * 1.5}px`;
67
- let borderRadius = theme.borderRadii.sm;
68
- let padding = '0 1em';
69
- let maxWidth;
70
- let overflowWrap;
71
- let whiteSpace = 'nowrap';
72
- let lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.sm);
73
- let fontSize = theme.fontSizes.sm;
74
- let titleDisplay;
75
- let paragraphMarginTop;
76
- let wordWrap;
77
- if (size !== 'small') {
78
- borderRadius = theme.borderRadii.md;
79
- overflowWrap = 'break-word';
80
- whiteSpace = 'normal';
81
- wordWrap = 'break-word';
82
- }
83
- if (size === 'extra-large') {
84
- padding = `${theme.space.base * 10}px`;
85
- maxWidth = `460px`;
86
- lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
87
- paragraphMarginTop = `${theme.space.base * 2.5}px`;
88
- } else if (size === 'large') {
89
- padding = `${theme.space.base * 5}px`;
90
- maxWidth = `270px`;
91
- lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
92
- paragraphMarginTop = `${theme.space.base * 2}px`;
93
- } else if (size === 'medium') {
94
- padding = '1em';
95
- maxWidth = `140px`;
96
- lineHeight = getLineHeight(theme.space.base * 4, theme.fontSizes.sm);
97
- }
98
- if (size === 'extra-large' || size === 'large') {
99
- fontSize = theme.fontSizes.md;
100
- titleDisplay = 'block';
101
- }
102
- let arrowSize;
103
- let arrowInset;
104
- if (hasArrow) {
105
- if (size === 'small' || size === 'medium') {
106
- arrowSize = margin;
107
- arrowInset = type === 'dark' ? '1px' : '0';
108
- } else {
109
- arrowInset = type === 'dark' ? '2px' : '1px';
110
- if (size === 'large') {
111
- margin = `${theme.space.base * 2}px`;
112
- arrowSize = margin;
113
- } else if (size === 'extra-large') {
114
- margin = `${theme.space.base * 3}px`;
115
- arrowSize = `${theme.space.base * 2.5}px`;
116
- }
117
- }
118
- }
119
- 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), {
120
- size: arrowSize,
121
- inset: arrowInset
122
- }), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
123
- };
124
- const colorStyles = _ref2 => {
125
- let {
126
- theme,
127
- type
128
- } = _ref2;
129
- let border;
130
- let boxShadow = theme.shadows.lg(`${theme.space.base}px`, `${theme.space.base * 2}px`, getColorV8('chromeHue', 600, theme, 0.15));
131
- let backgroundColor = getColorV8('chromeHue', 700, theme);
132
- let color = getColorV8('background', 600 , theme);
133
- let titleColor;
134
- if (type === 'light') {
135
- boxShadow = theme.shadows.lg(`${theme.space.base * 3}px`, `${theme.space.base * 5}px`, getColorV8('chromeHue', 600, theme, 0.15));
136
- border = `${theme.borders.sm} ${getColorV8('neutralHue', 300, theme)}`;
137
- backgroundColor = getColorV8('background', 600 , theme);
138
- color = getColorV8('neutralHue', 700, theme);
139
- titleColor = getColorV8('foreground', 600 , theme);
140
- }
141
- return css(["border:", ";box-shadow:", ";background-color:", ";color:", ";", "{color:", ";}"], border, boxShadow, backgroundColor, color, StyledTitle, titleColor);
142
- };
143
- const StyledTooltip = styled.div.attrs({
144
- 'data-garden-id': COMPONENT_ID,
145
- 'data-garden-version': '9.0.0-next.7'
146
- }).withConfig({
147
- displayName: "StyledTooltip",
148
- componentId: "sc-gzzjq4-0"
149
- })(["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));
150
- StyledTooltip.defaultProps = {
151
- theme: DEFAULT_THEME
152
- };
153
-
154
- const StyledTooltipWrapper = styled.div.withConfig({
155
- displayName: "StyledTooltipWrapper",
156
- componentId: "sc-1b7q9q6-0"
157
- })(["position:absolute;top:0;left:0;transition:opacity 10ms;opacity:1;z-index:", ";&[aria-hidden='true']{visibility:hidden;opacity:0;}"], props => props.zIndex);
158
- StyledTooltipWrapper.defaultProps = {
159
- theme: DEFAULT_THEME
160
- };
161
-
162
- const Paragraph = forwardRef((props, ref) => React.createElement(StyledParagraph, _extends({
163
- ref: ref
164
- }, props)));
165
- Paragraph.displayName = 'Paragraph';
166
-
167
- const Title = forwardRef((props, ref) => React.createElement(StyledTitle, _extends({
168
- ref: ref
169
- }, props)));
170
- Title.displayName = 'Title';
171
-
172
- const PLACEMENT = ['auto', ...PLACEMENT$1];
173
- const SIZE = ['small', 'medium', 'large', 'extra-large'];
174
- const TYPE = ['light', 'dark'];
175
-
176
- const toSize = (size, type) => {
177
- let retVal = size;
178
- if (retVal === undefined) {
179
- retVal = type === 'dark' ? 'small' : 'large';
180
- }
181
- return retVal;
182
- };
183
-
184
- const PLACEMENT_DEFAULT = 'top';
185
- const TooltipComponent = _ref => {
186
- let {
187
- id,
188
- delayMS,
189
- isInitialVisible,
190
- content,
191
- refKey,
192
- placement: _placement,
193
- children,
194
- hasArrow,
195
- size,
196
- type,
197
- appendToNode,
198
- zIndex,
199
- isVisible: externalIsVisible,
200
- onFocus,
201
- onBlur,
202
- ...props
203
- } = _ref;
204
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
205
- const triggerRef = useRef(null);
206
- const floatingRef = useRef(null);
207
- const {
208
- isVisible,
209
- getTooltipProps,
210
- getTriggerProps,
211
- openTooltip,
212
- closeTooltip
213
- } = useTooltip({
214
- id,
215
- delayMilliseconds: delayMS,
216
- isVisible: isInitialVisible
217
- });
218
- const controlledIsVisible = getControlledValue(externalIsVisible, isVisible);
219
- const [floatingPlacement] = getFloatingPlacements(theme, _placement === 'auto' ? PLACEMENT_DEFAULT : _placement);
220
- const {
221
- refs,
222
- placement,
223
- update,
224
- floatingStyles: {
225
- transform
226
- }
227
- } = useFloating({
228
- platform: {
229
- ...platform,
230
- isRTL: () => theme.rtl
231
- },
232
- elements: {
233
- reference: triggerRef?.current,
234
- floating: floatingRef?.current
235
- },
236
- placement: floatingPlacement,
237
- middleware: _placement === 'auto' ? [autoPlacement()] : undefined
238
- });
239
- useEffect(() => {
240
- let cleanup;
241
- if (controlledIsVisible && refs.reference.current && refs.floating.current) {
242
- cleanup = autoUpdate(refs.reference.current, refs.floating.current, update, {
243
- elementResize: typeof ResizeObserver === 'function'
244
- });
245
- }
246
- return () => cleanup && cleanup();
247
- }, [controlledIsVisible, refs.reference, refs.floating, update]);
248
- const Child = React.Children.only(children);
249
- const Node = React.createElement(StyledTooltipWrapper, {
250
- ref: floatingRef,
251
- style: {
252
- transform
253
- },
254
- zIndex: zIndex,
255
- "aria-hidden": !controlledIsVisible
256
- }, React.createElement(StyledTooltip, getTooltipProps({
257
- hasArrow,
258
- placement,
259
- size: toSize(size, type),
260
- onFocus: composeEventHandlers(onFocus, openTooltip),
261
- onBlur: composeEventHandlers(onBlur, () => closeTooltip(0)),
262
- 'aria-hidden': !controlledIsVisible,
263
- type,
264
- ...props
265
- }), content));
266
- return React.createElement(React.Fragment, null, cloneElement(Child, getTriggerProps({
267
- ...Child.props,
268
- [refKey]: mergeRefs([triggerRef, Child.ref ? Child.ref : null])
269
- })), appendToNode ? createPortal(Node, appendToNode) : Node);
270
- };
271
- TooltipComponent.displayName = 'Tooltip';
272
- TooltipComponent.propTypes = {
273
- appendToNode: PropTypes.any,
274
- hasArrow: PropTypes.bool,
275
- delayMS: PropTypes.number,
276
- id: PropTypes.string,
277
- content: PropTypes.node.isRequired,
278
- placement: PropTypes.oneOf(PLACEMENT),
279
- size: PropTypes.oneOf(SIZE),
280
- type: PropTypes.oneOf(TYPE),
281
- zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
282
- isInitialVisible: PropTypes.bool,
283
- refKey: PropTypes.string
284
- };
285
- TooltipComponent.defaultProps = {
286
- hasArrow: true,
287
- type: 'dark',
288
- placement: PLACEMENT_DEFAULT,
289
- delayMS: 500,
290
- refKey: 'ref'
291
- };
292
- const Tooltip = TooltipComponent;
293
- Tooltip.Paragraph = Paragraph;
294
- Tooltip.Title = Title;
295
-
296
- export { Paragraph, Title, Tooltip };