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

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.11'
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.11'
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.11'
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 };