|
1 | 1 | import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
2 | 2 | import { ETheme } from 'types/index.d'; |
3 | 3 | import { Color } from 'tvision-color'; |
4 | | -import { CHART_COLORS, defaultColor, colorMap } from 'configs/color'; |
| 4 | +import { CHART_COLORS, defaultColor } from 'configs/color'; |
5 | 5 | import { generateColorMap, insertThemeStylesheet } from 'utils/color'; |
6 | 6 | import { RootState } from '../store'; |
7 | 7 | import { version } from '../../../package.json'; |
@@ -108,18 +108,17 @@ const globalSlice = createSlice({ |
108 | 108 | state.color = action?.payload; |
109 | 109 | const mode = state.theme; |
110 | 110 |
|
111 | | - let colorType = colorMap?.[action?.payload]; |
112 | | - if (!colorType) { |
113 | | - colorType = action?.payload; |
114 | | - const newPalette = Color.getPaletteByGradation({ |
115 | | - colors: [colorType], |
116 | | - step: 10, |
117 | | - })[0]; |
118 | | - const newColorMap = generateColorMap(colorType, newPalette, mode); |
119 | | - insertThemeStylesheet(colorType, newColorMap, mode); |
120 | | - } |
| 111 | + const hex = action?.payload; |
121 | 112 |
|
122 | | - document.documentElement.setAttribute('theme-color', colorType || ''); |
| 113 | + const { colors: newPalette, primary: brandColorIndex } = Color.getColorGradations({ |
| 114 | + colors: [hex], |
| 115 | + step: 10, |
| 116 | + remainInput: false, // 是否保留输入 不保留会矫正不合适的主题色 |
| 117 | + })[0]; |
| 118 | + const newColorMap = generateColorMap(hex, newPalette, mode, brandColorIndex); |
| 119 | + insertThemeStylesheet(hex, newColorMap, mode); |
| 120 | + |
| 121 | + document.documentElement.setAttribute('theme-color', hex || ''); |
123 | 122 | } |
124 | 123 | }, |
125 | 124 | switchLayout: (state, action) => { |
|
0 commit comments