gf-vben-admin/build/config/themeConfig.ts

80 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-02-03 23:52:55 +08:00
import { generate } from '@ant-design/colors';
2021-02-08 23:59:47 +08:00
export const primaryColor = '#0960bd';
2021-02-03 23:52:55 +08:00
2021-04-07 23:14:51 +08:00
export const darkMode = 'light';
2021-02-03 23:52:55 +08:00
type Fn = (...arg: any) => any;
2021-05-17 00:54:45 +08:00
type GenerateTheme = 'default' | 'dark';
2021-02-03 23:52:55 +08:00
export interface GenerateColorsParams {
mixLighten: Fn;
mixDarken: Fn;
tinycolor: any;
color?: string;
}
export function generateAntColors(color: string, theme: GenerateTheme = 'default') {
2021-02-03 23:52:55 +08:00
return generate(color, {
2021-05-17 00:54:45 +08:00
theme,
2021-02-03 23:52:55 +08:00
});
}
2021-04-07 23:14:51 +08:00
export function getThemeColors(color?: string) {
2021-02-03 23:52:55 +08:00
const tc = color || primaryColor;
const lightColors = generateAntColors(tc);
2021-05-17 00:54:45 +08:00
const primary = lightColors[5];
const modeColors = generateAntColors(primary, 'dark');
2021-02-03 23:52:55 +08:00
return [...lightColors, ...modeColors];
2021-02-03 23:52:55 +08:00
}
export function generateColors({
color = primaryColor,
mixLighten,
mixDarken,
tinycolor,
}: GenerateColorsParams) {
2021-02-04 21:46:35 +08:00
const arr = new Array(19).fill(0);
const lightens = arr.map((_t, i) => {
2021-02-03 23:52:55 +08:00
return mixLighten(color, i / 5);
});
const darkens = arr.map((_t, i) => {
2021-02-03 23:52:55 +08:00
return mixDarken(color, i / 5);
});
const alphaColors = arr.map((_t, i) => {
2021-02-03 23:52:55 +08:00
return tinycolor(color)
.setAlpha(i / 20)
.toRgbString();
});
const shortAlphaColors = alphaColors.map((item) => item.replace(/\s/g, '').replace(/0\./g, '.'));
2021-02-04 21:46:35 +08:00
const tinycolorLightens = arr
.map((_t, i) => {
2021-02-03 23:52:55 +08:00
return tinycolor(color)
.lighten(i * 5)
.toHexString();
})
.filter((item) => item !== '#ffffff');
2021-02-04 21:46:35 +08:00
const tinycolorDarkens = arr
.map((_t, i) => {
2021-02-03 23:52:55 +08:00
return tinycolor(color)
.darken(i * 5)
.toHexString();
})
.filter((item) => item !== '#000000');
return [
...lightens,
...darkens,
...alphaColors,
...shortAlphaColors,
...tinycolorDarkens,
...tinycolorLightens,
].filter((item) => !item.includes('-'));
2021-02-03 23:52:55 +08:00
}