@zendeskgarden/react-tooltips 9.0.0-next.2 → 9.0.0-next.20

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