forked from Cambly/syntax
/
Colors.tsx
82 lines (78 loc) · 2.4 KB
/
Colors.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
import React from "react";
import variables from "../../../packages/syntax-design-tokens/dist/json/variables.json";
export default function Colors() {
const groupColors = Object.entries(variables).reduce(
(acc, [key, value]) => {
if (key.includes("cambio")) {
// @ts-expect-error
acc["Cambio"].push({ key, value });
} else if (
key.includes("black") ||
key.includes("white") ||
key.includes("gray")
) {
// @ts-expect-error
acc["Grayscale"].push({ key, value });
} else if (key.includes("primary")) {
// @ts-expect-error
acc["Primary"].push({ key, value });
} else if (key.includes("destructive")) {
// @ts-expect-error
acc["Destructive"].push({ key, value });
} else {
// @ts-expect-error
acc["Extended Palette"].push({ key, value });
}
return acc;
},
{
Cambio: [],
Grayscale: [],
Primary: [],
Destructive: [],
"Extended Palette": [],
},
);
return (
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
{Object.entries(groupColors).map(([group, colors]) => {
return (
<>
<h2>{group}</h2>
{colors.map(({ key, value }) => {
const [number] = (key as string).match(/\d\d\d/g) ?? [];
return (
<div
key={key}
style={{
color:
[
"color-cambio-white",
"color-cambio-cream",
"color-cambio-pink",
"color-cambio-sky",
"color-cambio-yellow-700",
"color-cambio-transparent-full",
"color-base-gray-10",
"color-base-gray-30",
"color-base-yellow-700",
"color-base-white",
].includes(key) ||
(number && parseInt(number) < 400)
? "black"
: "white",
backgroundColor: value,
padding: 8,
borderRadius: 8,
}}
>
--{key}: {value}
</div>
);
})}
</>
);
})}
</div>
);
}