blob: 34ddb5a01b067d3000590a26cfe1828ac2a3b726 (
plain) (
blame)
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
|
import { Row, StatusLight, Text } from '@umami/react-zen';
import type { LegendItem } from 'chart.js/auto';
import { colord } from 'colord';
export function Legend({
items = [],
onClick,
}: {
items: any[];
onClick: (index: LegendItem) => void;
}) {
if (!items.find(({ text }) => text)) {
return null;
}
return (
<Row gap wrap="wrap" justifyContent="center">
{items.map(item => {
const { text, fillStyle, hidden } = item;
const color = colord(fillStyle);
return (
<Row key={text} onClick={() => onClick(item)}>
<StatusLight color={color.alpha(color.alpha() + 0.2).toHex()}>
<Text
size="2"
color={hidden ? 'disabled' : undefined}
truncate={true}
style={{ maxWidth: '300px' }}
>
{text}
</Text>
</StatusLight>
</Row>
);
})}
</Row>
);
}
|