/
ChartTooltip.tsx
115 lines (107 loc) · 3.72 KB
/
ChartTooltip.tsx
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
import React from 'react';
import { Color, ValueFormatter } from '../../../lib';
import {
border,
borderRadius,
boxShadow,
classNames,
defaultColors,
fontSize,
fontWeight,
getColorTheme,
getColorVariantsFromColorThemeValue,
sizing,
spacing,
themeColorRange
} from 'lib';
export interface ChartTooltipRowProps {
value: string,
name: string,
color: Color,
}
const ChartTooltipRow = ({ value, name, color }: ChartTooltipRowProps) => (
<div className="tr-flex tr-items-center tr-justify-between tr-space-x-8">
<div className="tr-flex tr-items-center tr-space-x-2">
<span className={ classNames(
'tr-shrink-0',
getColorVariantsFromColorThemeValue(getColorTheme(color).background).bgColor,
getColorVariantsFromColorThemeValue(defaultColors.white).borderColor,
sizing.sm.height,
sizing.sm.width,
borderRadius.full.all,
border.md.all,
boxShadow.md,
) } />
<p className={ classNames(
'text-elem tr-font-medium tr-tabular-nums tr-text-right tr-whitespace-nowrap',
getColorVariantsFromColorThemeValue(defaultColors.darkText).textColor,
) }>
{ value }
</p>
</div>
<p className={ classNames(
'text-elem tr-text-right tr-whitespace-nowrap',
getColorVariantsFromColorThemeValue(defaultColors.text).textColor,
fontWeight.sm,
) }>
{ name }
</p>
</div>
);
export interface ChartTooltipProps {
active: boolean | undefined,
payload: any,
label: string,
colors?: Color[],
valueFormatter: ValueFormatter,
}
const ChartTooltip = ({ active, payload, label, colors = themeColorRange, valueFormatter }: ChartTooltipProps) => {
if (active && payload) {
return (
<div className={ classNames(
getColorVariantsFromColorThemeValue(defaultColors.white).bgColor,
fontSize.sm,
borderRadius.md.all,
border.sm.all,
boxShadow.lg,
) }>
<div className={ classNames(
getColorVariantsFromColorThemeValue(defaultColors.lightBorder).borderColor,
spacing.twoXl.paddingLeft,
spacing.twoXl.paddingRight,
spacing.sm.paddingTop,
spacing.sm.paddingBottom,
border.sm.bottom,
) }>
<p className={ classNames(
'text-elem',
getColorVariantsFromColorThemeValue(defaultColors.darkText).textColor,
fontWeight.md,
) }>
{ label }
</p>
</div>
<div className={ classNames(
spacing.twoXl.paddingLeft,
spacing.twoXl.paddingRight,
spacing.sm.paddingTop,
spacing.sm.paddingBottom,
'tr-space-y-1',
) }>
{
payload.map(({value, name}: { value: number, name: string }, idx: number) => (
<ChartTooltipRow
key={ `id-${idx}` }
value={ valueFormatter(value) }
name={ name }
color={ colors[idx] }
/>
))
}
</div>
</div>
);
}
return null;
};
export default ChartTooltip;