-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtooltip.tsx
More file actions
131 lines (121 loc) · 3.24 KB
/
Copy pathtooltip.tsx
File metadata and controls
131 lines (121 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from 'react';
import {
Tooltip as ReakitTooltip,
TooltipReference,
useTooltipState,
} from 'reakit/Tooltip';
import styled from 'styled-components';
import { BaseProps } from '../../types';
import BodyText from '../body-text/body-text';
import CaptionText from '../caption-text/caption-text';
import FlexColumn from '../flex-column/flex-column';
import { matchSize } from '../../utils/match-size';
type Ref = HTMLDivElement;
type StyledReactTooltipProps = {
lineHeight?: 'xs' | 'sm';
scale?: 'xs' | 'sm';
paddingScale?: 1 | 2;
padding?: string;
};
export interface TooltipProps extends BaseProps {
tooltipContent?: JSX.Element | string | null;
caption?: string | null;
additionalBlock?: React.ReactElement<any> & any;
children?: React.ReactElement<any> & any;
monotype?: boolean;
limitWidth?: boolean | string;
}
const StyledReactTooltip = styled(
ReakitTooltip,
).withConfig<StyledReactTooltipProps>({
shouldForwardProp: (prop) => prop !== 'paddingScale',
})(({ theme, lineHeight = 'sm', scale = 'sm', paddingScale = 2, padding }) => ({
zIndex: theme.zIndex.tooltip,
color: theme.styleguideColors.contentPrimary,
backgroundColor: theme.styleguideColors.backgroundPrimary,
borderRadius: theme.borderRadius.base,
padding: padding || theme.padding[paddingScale],
boxShadow: theme.boxShadow.tooltip,
transition: 'opacity 250ms ease-in-out',
opacity: 0,
fontSize: matchSize(
{
sm: '1.3rem',
xs: '0.8125rem',
},
scale,
),
lineHeight: matchSize(
{
sm: '1.5rem',
xs: '1.25rem',
},
lineHeight,
),
'&[data-enter]': {
opacity: 1,
},
}),
);
export const Tooltip = React.forwardRef<
Ref,
TooltipProps & StyledReactTooltipProps
>(
(
{
children,
limitWidth,
tooltipContent,
caption,
additionalBlock,
monotype,
lineHeight = 'sm',
scale = 'sm',
paddingScale = 2,
padding,
...props
},
ref,
) => {
const tooltip = useTooltipState({ animated: 250 });
const maxWidth = limitWidth
? typeof limitWidth === 'string'
? limitWidth
: '500px'
: undefined;
if (children == null) {
return null;
}
if (tooltipContent == null) {
return <>{children}</>;
}
return (
<>
<TooltipReference {...tooltip} ref={children.ref} {...children.props}>
{(referenceProps) => React.cloneElement(children, referenceProps)}
</TooltipReference>
<StyledReactTooltip paddingScale={paddingScale} padding={padding} {...tooltip} {...props}>
<div style={{ maxWidth }}>
<FlexColumn itemsSpacing={8}>
<FlexColumn>
<CaptionText size={2} variation="gray">
{caption}
</CaptionText>
<BodyText
size={3}
monotype={monotype}
lineHeight={lineHeight}
scale={scale}
>
{tooltipContent}
</BodyText>
</FlexColumn>
{additionalBlock}
</FlexColumn>
</div>
</StyledReactTooltip>
</>
);
},
);
export default Tooltip;