themeUtil.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const client = require("webpack-theme-color-replacer/client");
  2. const { theme } = require("../../config");
  3. const {
  4. getMenuColors,
  5. getAntdColors,
  6. getThemeToggleColors,
  7. getFunctionalColors
  8. } = require("./colors");
  9. const { ANTD } = require("../../config/default");
  10. module.exports = {
  11. getThemeColors(color, $theme) {
  12. const _color = color || theme.color;
  13. const mode = $theme || theme.mode;
  14. const replaceColors = getThemeToggleColors(_color, mode);
  15. const themeColors = [
  16. ...replaceColors.mainColors,
  17. ...replaceColors.subColors,
  18. ...replaceColors.menuColors,
  19. ...replaceColors.contentColors,
  20. ...replaceColors.rgbColors,
  21. ...replaceColors.functionalColors.success,
  22. ...replaceColors.functionalColors.warning,
  23. ...replaceColors.functionalColors.error
  24. ];
  25. return themeColors;
  26. },
  27. changeThemeColor(newColor, $theme) {
  28. let promise = client.changer.changeColor({
  29. newColors: this.getThemeColors(newColor, $theme)
  30. });
  31. return promise;
  32. },
  33. modifyVars(color) {
  34. let _color = color || theme.color;
  35. const palettes = getAntdColors(_color, theme.mode);
  36. const menuColors = getMenuColors(_color, theme.mode);
  37. const { success, warning, error } = getFunctionalColors(theme.mode);
  38. const primary = palettes[5];
  39. return {
  40. "primary-color": primary,
  41. "primary-1": palettes[0],
  42. "primary-2": palettes[1],
  43. "primary-3": palettes[2],
  44. "primary-4": palettes[3],
  45. "primary-5": palettes[4],
  46. "primary-6": palettes[5],
  47. "primary-7": palettes[6],
  48. "primary-8": palettes[7],
  49. "primary-9": palettes[8],
  50. "primary-10": palettes[9],
  51. "info-color": primary,
  52. "success-color": success[3],
  53. "warning-color": warning[3],
  54. "error-color": error[3],
  55. "alert-info-bg-color": palettes[0],
  56. "alert-info-border-color": palettes[2],
  57. "alert-success-bg-color": success[0],
  58. "alert-success-border-color": success[2],
  59. "alert-warning-bg-color": warning[0],
  60. "alert-warning-border-color": warning[2],
  61. "alert-error-bg-color": error[0],
  62. "alert-error-border-color": error[2],
  63. "processing-color": primary,
  64. "menu-dark-submenu-bg": menuColors[0],
  65. "layout-header-background": menuColors[1],
  66. "layout-trigger-background": menuColors[2],
  67. ...ANTD.theme[theme.mode],
  68. ...ANTD.theme["common"]
  69. };
  70. }
  71. };