Blame view

build/config/themeConfig.ts 1.77 KB
vben authored
1
import { generate } from '@ant-design/colors';
2
vben authored
3
export const primaryColor = '#0960bd';
vben authored
4
Vben authored
5
export const darkMode = 'light';
vben authored
6
7
8

type Fn = (...arg: any) => any;
Vben authored
9
type GenerateTheme = 'default' | 'dark';
10
vben authored
11
12
13
14
15
16
17
export interface GenerateColorsParams {
  mixLighten: Fn;
  mixDarken: Fn;
  tinycolor: any;
  color?: string;
}
18
export function generateAntColors(color: string, theme: GenerateTheme = 'default') {
vben authored
19
  return generate(color, {
Vben authored
20
    theme,
vben authored
21
22
23
  });
}
Vben authored
24
export function getThemeColors(color?: string) {
vben authored
25
  const tc = color || primaryColor;
26
  const lightColors = generateAntColors(tc);
Vben authored
27
  const primary = lightColors[5];
28
  const modeColors = generateAntColors(primary, 'dark');
vben authored
29
30
  return [...lightColors, ...modeColors];
vben authored
31
32
33
34
35
36
37
38
}

export function generateColors({
  color = primaryColor,
  mixLighten,
  mixDarken,
  tinycolor,
}: GenerateColorsParams) {
vben authored
39
  const arr = new Array(19).fill(0);
40
  const lightens = arr.map((_t, i) => {
vben authored
41
42
43
    return mixLighten(color, i / 5);
  });
44
  const darkens = arr.map((_t, i) => {
vben authored
45
46
47
    return mixDarken(color, i / 5);
  });
48
  const alphaColors = arr.map((_t, i) => {
vben authored
49
50
51
52
53
    return tinycolor(color)
      .setAlpha(i / 20)
      .toRgbString();
  });
54
55
  const shortAlphaColors = alphaColors.map((item) => item.replace(/\s/g, '').replace(/0\./g, '.'));
vben authored
56
  const tinycolorLightens = arr
57
    .map((_t, i) => {
vben authored
58
59
60
61
62
63
      return tinycolor(color)
        .lighten(i * 5)
        .toHexString();
    })
    .filter((item) => item !== '#ffffff');
vben authored
64
  const tinycolorDarkens = arr
65
    .map((_t, i) => {
vben authored
66
67
68
69
70
      return tinycolor(color)
        .darken(i * 5)
        .toHexString();
    })
    .filter((item) => item !== '#000000');
71
72
73
74
75
76
77
78
  return [
    ...lightens,
    ...darkens,
    ...alphaColors,
    ...shortAlphaColors,
    ...tinycolorDarkens,
    ...tinycolorLightens,
  ].filter((item) => !item.includes('-'));
vben authored
79
}