vben
authored
|
1
|
import { generate } from '@ant-design/colors';
|
vben
authored
|
2
|
|
vben
authored
|
3
|
export const primaryColor = '#0960bd';
|
vben
authored
|
4
|
|
Vben
authored
|
5
|
export const darkMode = 'light';
|
vben
authored
|
6
7
8
9
10
11
12
13
14
15
|
type Fn = (...arg: any) => any;
export interface GenerateColorsParams {
mixLighten: Fn;
mixDarken: Fn;
tinycolor: any;
color?: string;
}
|
Vben
authored
|
16
|
export function generateAntColors(color: string) {
|
vben
authored
|
17
|
return generate(color, {
|
Vben
authored
|
18
|
theme: 'default',
|
vben
authored
|
19
20
21
|
});
}
|
Vben
authored
|
22
|
export function getThemeColors(color?: string) {
|
vben
authored
|
23
|
const tc = color || primaryColor;
|
Vben
authored
|
24
|
const colors = generateAntColors(tc);
|
vben
authored
|
25
|
const primary = colors[5];
|
Vben
authored
|
26
|
const modeColors = generateAntColors(primary);
|
vben
authored
|
27
28
29
30
31
32
33
34
35
36
|
return [...colors, ...modeColors];
}
export function generateColors({
color = primaryColor,
mixLighten,
mixDarken,
tinycolor,
}: GenerateColorsParams) {
|
vben
authored
|
37
|
const arr = new Array(19).fill(0);
|
Vben
authored
|
38
|
const lightens = arr.map((_t, i) => {
|
vben
authored
|
39
40
41
|
return mixLighten(color, i / 5);
});
|
Vben
authored
|
42
|
const darkens = arr.map((_t, i) => {
|
vben
authored
|
43
44
45
|
return mixDarken(color, i / 5);
});
|
Vben
authored
|
46
|
const alphaColors = arr.map((_t, i) => {
|
vben
authored
|
47
48
49
50
51
|
return tinycolor(color)
.setAlpha(i / 20)
.toRgbString();
});
|
Vben
authored
|
52
53
|
const shortAlphaColors = alphaColors.map((item) => item.replace(/\s/g, '').replace(/0\./g, '.'));
|
vben
authored
|
54
|
const tinycolorLightens = arr
|
Vben
authored
|
55
|
.map((_t, i) => {
|
vben
authored
|
56
57
58
59
60
61
|
return tinycolor(color)
.lighten(i * 5)
.toHexString();
})
.filter((item) => item !== '#ffffff');
|
vben
authored
|
62
|
const tinycolorDarkens = arr
|
Vben
authored
|
63
|
.map((_t, i) => {
|
vben
authored
|
64
65
66
67
68
|
return tinycolor(color)
.darken(i * 5)
.toHexString();
})
.filter((item) => item !== '#000000');
|
Vben
authored
|
69
70
71
72
73
74
75
76
|
return [
...lightens,
...darkens,
...alphaColors,
...shortAlphaColors,
...tinycolorDarkens,
...tinycolorLightens,
].filter((item) => !item.includes('-'));
|
vben
authored
|
77
|
}
|