@zendeskgarden/react-tooltips 9.0.0-next.2 → 9.0.0-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/elements/Paragraph.js +18 -0
- package/dist/esm/elements/Title.js +18 -0
- package/dist/esm/elements/Tooltip.js +137 -0
- package/dist/esm/elements/utils.js +15 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/styled/StyledParagraph.js +22 -0
- package/dist/esm/styled/StyledTitle.js +22 -0
- package/dist/esm/styled/StyledTooltip.js +137 -0
- package/dist/esm/styled/StyledTooltipWrapper.js +18 -0
- package/dist/esm/types/index.js +13 -0
- package/dist/index.cjs.js +85 -66
- package/dist/typings/elements/Paragraph.d.ts +2 -0
- package/dist/typings/elements/Title.d.ts +2 -0
- package/dist/typings/elements/Tooltip.d.ts +29 -0
- package/dist/typings/index.d.ts +1 -1
- package/package.json +8 -8
- package/dist/index.esm.js +0 -289
|
@@ -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 = 'Tooltip.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 = 'Tooltip.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.21'
|
|
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.21'
|
|
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,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 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
|
+
placement,
|
|
18
|
+
hasArrow
|
|
19
|
+
} = _ref;
|
|
20
|
+
let margin = `${theme.space.base * 1.5}px`;
|
|
21
|
+
let borderRadius = theme.borderRadii.sm;
|
|
22
|
+
let padding = '0 1em';
|
|
23
|
+
let maxWidth;
|
|
24
|
+
let overflowWrap;
|
|
25
|
+
let whiteSpace = 'nowrap';
|
|
26
|
+
let lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.sm);
|
|
27
|
+
let fontSize = theme.fontSizes.sm;
|
|
28
|
+
let titleDisplay;
|
|
29
|
+
let paragraphMarginTop;
|
|
30
|
+
let wordWrap;
|
|
31
|
+
if (size !== 'small') {
|
|
32
|
+
borderRadius = theme.borderRadii.md;
|
|
33
|
+
overflowWrap = 'break-word';
|
|
34
|
+
whiteSpace = 'normal';
|
|
35
|
+
wordWrap = 'break-word';
|
|
36
|
+
}
|
|
37
|
+
if (size === 'extra-large') {
|
|
38
|
+
padding = `${theme.space.base * 10}px`;
|
|
39
|
+
maxWidth = `460px`;
|
|
40
|
+
lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
|
|
41
|
+
paragraphMarginTop = `${theme.space.base * 2.5}px`;
|
|
42
|
+
} else if (size === 'large') {
|
|
43
|
+
padding = `${theme.space.base * 5}px`;
|
|
44
|
+
maxWidth = `270px`;
|
|
45
|
+
lineHeight = getLineHeight(theme.space.base * 5, theme.fontSizes.md);
|
|
46
|
+
paragraphMarginTop = `${theme.space.base * 2}px`;
|
|
47
|
+
} else if (size === 'medium') {
|
|
48
|
+
padding = '1em';
|
|
49
|
+
maxWidth = `140px`;
|
|
50
|
+
lineHeight = getLineHeight(theme.space.base * 4, theme.fontSizes.sm);
|
|
51
|
+
}
|
|
52
|
+
if (size === 'extra-large' || size === 'large') {
|
|
53
|
+
fontSize = theme.fontSizes.md;
|
|
54
|
+
titleDisplay = 'block';
|
|
55
|
+
}
|
|
56
|
+
let arrowSize;
|
|
57
|
+
if (hasArrow) {
|
|
58
|
+
if (size === 'small' || size === 'medium') {
|
|
59
|
+
arrowSize = margin;
|
|
60
|
+
} else if (size === 'large') {
|
|
61
|
+
margin = `${theme.space.base * 2}px`;
|
|
62
|
+
arrowSize = margin;
|
|
63
|
+
} else if (size === 'extra-large') {
|
|
64
|
+
margin = `${theme.space.base * 3}px`;
|
|
65
|
+
arrowSize = `${theme.space.base * 2.5}px`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
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), {
|
|
69
|
+
size: arrowSize
|
|
70
|
+
}), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
|
|
71
|
+
};
|
|
72
|
+
const colorStyles = _ref2 => {
|
|
73
|
+
let {
|
|
74
|
+
theme,
|
|
75
|
+
type
|
|
76
|
+
} = _ref2;
|
|
77
|
+
let borderColor;
|
|
78
|
+
let boxShadow;
|
|
79
|
+
let backgroundColor;
|
|
80
|
+
let color;
|
|
81
|
+
let titleColor;
|
|
82
|
+
if (type === 'light') {
|
|
83
|
+
backgroundColor = getColor({
|
|
84
|
+
theme,
|
|
85
|
+
variable: 'background.raised'
|
|
86
|
+
});
|
|
87
|
+
borderColor = getColor({
|
|
88
|
+
theme,
|
|
89
|
+
variable: 'border.default'
|
|
90
|
+
});
|
|
91
|
+
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({
|
|
92
|
+
variable: 'shadow.medium',
|
|
93
|
+
theme
|
|
94
|
+
}));
|
|
95
|
+
color = getColor({
|
|
96
|
+
theme,
|
|
97
|
+
variable: 'foreground.subtle'
|
|
98
|
+
});
|
|
99
|
+
titleColor = getColor({
|
|
100
|
+
theme,
|
|
101
|
+
variable: 'foreground.default'
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
backgroundColor = getColor({
|
|
105
|
+
theme,
|
|
106
|
+
hue: 'neutralHue',
|
|
107
|
+
light: {
|
|
108
|
+
shade: 900
|
|
109
|
+
},
|
|
110
|
+
dark: {
|
|
111
|
+
shade: 700
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
borderColor = backgroundColor;
|
|
115
|
+
boxShadow = theme.shadows.lg(`${theme.space.base}px`, `${theme.space.base * 2}px`, getColor({
|
|
116
|
+
variable: 'shadow.small',
|
|
117
|
+
theme
|
|
118
|
+
}));
|
|
119
|
+
color = getColor({
|
|
120
|
+
theme,
|
|
121
|
+
hue: 'white'
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return css(["border-color:", ";box-shadow:", ";background-color:", ";color:", ";", "{color:", ";}"], borderColor, boxShadow, backgroundColor, color, StyledTitle, titleColor);
|
|
125
|
+
};
|
|
126
|
+
const StyledTooltip = styled.div.attrs({
|
|
127
|
+
'data-garden-id': COMPONENT_ID,
|
|
128
|
+
'data-garden-version': '9.0.0-next.21'
|
|
129
|
+
}).withConfig({
|
|
130
|
+
displayName: "StyledTooltip",
|
|
131
|
+
componentId: "sc-gzzjq4-0"
|
|
132
|
+
})(["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, sizeStyles, colorStyles, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
133
|
+
StyledTooltip.defaultProps = {
|
|
134
|
+
theme: DEFAULT_THEME
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.
|
|
28
|
+
'data-garden-version': '9.0.0-next.21'
|
|
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.
|
|
40
|
+
'data-garden-version': '9.0.0-next.21'
|
|
42
41
|
}).withConfig({
|
|
43
42
|
displayName: "StyledTitle",
|
|
44
43
|
componentId: "sc-vnjcvz-0"
|
|
@@ -52,7 +51,6 @@ const sizeStyles = _ref => {
|
|
|
52
51
|
let {
|
|
53
52
|
theme,
|
|
54
53
|
size,
|
|
55
|
-
type,
|
|
56
54
|
placement,
|
|
57
55
|
hasArrow
|
|
58
56
|
} = _ref;
|
|
@@ -93,25 +91,19 @@ const sizeStyles = _ref => {
|
|
|
93
91
|
titleDisplay = 'block';
|
|
94
92
|
}
|
|
95
93
|
let arrowSize;
|
|
96
|
-
let arrowInset;
|
|
97
94
|
if (hasArrow) {
|
|
98
95
|
if (size === 'small' || size === 'medium') {
|
|
99
96
|
arrowSize = margin;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
} else if (size === 'extra-large') {
|
|
107
|
-
margin = `${theme.space.base * 3}px`;
|
|
108
|
-
arrowSize = `${theme.space.base * 2.5}px`;
|
|
109
|
-
}
|
|
97
|
+
} else if (size === 'large') {
|
|
98
|
+
margin = `${theme.space.base * 2}px`;
|
|
99
|
+
arrowSize = margin;
|
|
100
|
+
} else if (size === 'extra-large') {
|
|
101
|
+
margin = `${theme.space.base * 3}px`;
|
|
102
|
+
arrowSize = `${theme.space.base * 2.5}px`;
|
|
110
103
|
}
|
|
111
104
|
}
|
|
112
105
|
return styled.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 && reactTheming.arrowStyles(reactTheming.getArrowPosition(theme, placement), {
|
|
113
|
-
size: arrowSize
|
|
114
|
-
inset: arrowInset
|
|
106
|
+
size: arrowSize
|
|
115
107
|
}), StyledParagraph, paragraphMarginTop, StyledTitle, titleDisplay);
|
|
116
108
|
};
|
|
117
109
|
const colorStyles = _ref2 => {
|
|
@@ -119,27 +111,62 @@ const colorStyles = _ref2 => {
|
|
|
119
111
|
theme,
|
|
120
112
|
type
|
|
121
113
|
} = _ref2;
|
|
122
|
-
let
|
|
123
|
-
let boxShadow
|
|
124
|
-
let backgroundColor
|
|
125
|
-
let color
|
|
114
|
+
let borderColor;
|
|
115
|
+
let boxShadow;
|
|
116
|
+
let backgroundColor;
|
|
117
|
+
let color;
|
|
126
118
|
let titleColor;
|
|
127
119
|
if (type === 'light') {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
backgroundColor = reactTheming.getColor({
|
|
121
|
+
theme,
|
|
122
|
+
variable: 'background.raised'
|
|
123
|
+
});
|
|
124
|
+
borderColor = reactTheming.getColor({
|
|
125
|
+
theme,
|
|
126
|
+
variable: 'border.default'
|
|
127
|
+
});
|
|
128
|
+
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({
|
|
129
|
+
variable: 'shadow.medium',
|
|
130
|
+
theme
|
|
131
|
+
}));
|
|
132
|
+
color = reactTheming.getColor({
|
|
133
|
+
theme,
|
|
134
|
+
variable: 'foreground.subtle'
|
|
135
|
+
});
|
|
136
|
+
titleColor = reactTheming.getColor({
|
|
137
|
+
theme,
|
|
138
|
+
variable: 'foreground.default'
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
backgroundColor = reactTheming.getColor({
|
|
142
|
+
theme,
|
|
143
|
+
hue: 'neutralHue',
|
|
144
|
+
light: {
|
|
145
|
+
shade: 900
|
|
146
|
+
},
|
|
147
|
+
dark: {
|
|
148
|
+
shade: 700
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
borderColor = backgroundColor;
|
|
152
|
+
boxShadow = theme.shadows.lg(`${theme.space.base}px`, `${theme.space.base * 2}px`, reactTheming.getColor({
|
|
153
|
+
variable: 'shadow.small',
|
|
154
|
+
theme
|
|
155
|
+
}));
|
|
156
|
+
color = reactTheming.getColor({
|
|
157
|
+
theme,
|
|
158
|
+
hue: 'white'
|
|
159
|
+
});
|
|
133
160
|
}
|
|
134
|
-
return styled.css(["border:", ";box-shadow:", ";background-color:", ";color:", ";", "{color:", ";}"],
|
|
161
|
+
return styled.css(["border-color:", ";box-shadow:", ";background-color:", ";color:", ";", "{color:", ";}"], borderColor, boxShadow, backgroundColor, color, StyledTitle, titleColor);
|
|
135
162
|
};
|
|
136
163
|
const StyledTooltip = styled__default.default.div.attrs({
|
|
137
164
|
'data-garden-id': COMPONENT_ID,
|
|
138
|
-
'data-garden-version': '9.0.0-next.
|
|
165
|
+
'data-garden-version': '9.0.0-next.21'
|
|
139
166
|
}).withConfig({
|
|
140
167
|
displayName: "StyledTooltip",
|
|
141
168
|
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,
|
|
169
|
+
})(["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, sizeStyles, colorStyles, props => reactTheming.retrieveComponentStyles(COMPONENT_ID, props));
|
|
143
170
|
StyledTooltip.defaultProps = {
|
|
144
171
|
theme: reactTheming.DEFAULT_THEME
|
|
145
172
|
};
|
|
@@ -152,6 +179,16 @@ StyledTooltipWrapper.defaultProps = {
|
|
|
152
179
|
theme: reactTheming.DEFAULT_THEME
|
|
153
180
|
};
|
|
154
181
|
|
|
182
|
+
const Paragraph = React.forwardRef((props, ref) => React__default.default.createElement(StyledParagraph, Object.assign({
|
|
183
|
+
ref: ref
|
|
184
|
+
}, props)));
|
|
185
|
+
Paragraph.displayName = 'Tooltip.Paragraph';
|
|
186
|
+
|
|
187
|
+
const Title = React.forwardRef((props, ref) => React__default.default.createElement(StyledTitle, Object.assign({
|
|
188
|
+
ref: ref
|
|
189
|
+
}, props)));
|
|
190
|
+
Title.displayName = 'Tooltip.Title';
|
|
191
|
+
|
|
155
192
|
const PLACEMENT = ['auto', ...reactTheming.PLACEMENT];
|
|
156
193
|
const SIZE = ['small', 'medium', 'large', 'extra-large'];
|
|
157
194
|
const TYPE = ['light', 'dark'];
|
|
@@ -165,7 +202,7 @@ const toSize = (size, type) => {
|
|
|
165
202
|
};
|
|
166
203
|
|
|
167
204
|
const PLACEMENT_DEFAULT = 'top';
|
|
168
|
-
const
|
|
205
|
+
const TooltipComponent = _ref => {
|
|
169
206
|
let {
|
|
170
207
|
id,
|
|
171
208
|
delayMS,
|
|
@@ -208,6 +245,10 @@ const Tooltip = _ref => {
|
|
|
208
245
|
transform
|
|
209
246
|
}
|
|
210
247
|
} = reactDom.useFloating({
|
|
248
|
+
platform: {
|
|
249
|
+
...reactDom.platform,
|
|
250
|
+
isRTL: () => theme.rtl
|
|
251
|
+
},
|
|
211
252
|
elements: {
|
|
212
253
|
reference: triggerRef?.current,
|
|
213
254
|
floating: floatingRef?.current
|
|
@@ -247,8 +288,8 @@ const Tooltip = _ref => {
|
|
|
247
288
|
[refKey]: reactMergeRefs.mergeRefs([triggerRef, Child.ref ? Child.ref : null])
|
|
248
289
|
})), appendToNode ? reactDom$1.createPortal(Node, appendToNode) : Node);
|
|
249
290
|
};
|
|
250
|
-
|
|
251
|
-
|
|
291
|
+
TooltipComponent.displayName = 'Tooltip';
|
|
292
|
+
TooltipComponent.propTypes = {
|
|
252
293
|
appendToNode: PropTypes__default.default.any,
|
|
253
294
|
hasArrow: PropTypes__default.default.bool,
|
|
254
295
|
delayMS: PropTypes__default.default.number,
|
|
@@ -261,38 +302,16 @@ Tooltip.propTypes = {
|
|
|
261
302
|
isInitialVisible: PropTypes__default.default.bool,
|
|
262
303
|
refKey: PropTypes__default.default.string
|
|
263
304
|
};
|
|
264
|
-
|
|
305
|
+
TooltipComponent.defaultProps = {
|
|
265
306
|
hasArrow: true,
|
|
266
307
|
type: 'dark',
|
|
267
308
|
placement: PLACEMENT_DEFAULT,
|
|
268
309
|
delayMS: 500,
|
|
269
310
|
refKey: 'ref'
|
|
270
311
|
};
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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';
|
|
312
|
+
const Tooltip = TooltipComponent;
|
|
313
|
+
Tooltip.Paragraph = Paragraph;
|
|
314
|
+
Tooltip.Title = Title;
|
|
296
315
|
|
|
297
316
|
exports.Paragraph = Paragraph;
|
|
298
317
|
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
|
};
|
package/dist/typings/index.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "9.0.0-next.21",
|
|
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.
|
|
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.
|
|
25
|
+
"@zendeskgarden/container-tooltip": "^1.0.16",
|
|
26
26
|
"@zendeskgarden/container-utilities": "^2.0.0",
|
|
27
|
-
"polished": "^4.
|
|
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": "
|
|
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
|
|
35
|
+
"styled-components": "^5.3.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@zendeskgarden/react-theming": "^9.0.0-next.
|
|
38
|
+
"@zendeskgarden/react-theming": "^9.0.0-next.21"
|
|
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": "
|
|
50
|
+
"gitHead": "a245ce2b794ea65142174a6a1f855a111b2677a2"
|
|
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 };
|