themeConfig.ts 1.7 KB

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