Skip to content

Commit 519285b

Browse files
committed
fix(color-panel): update brand token logic
1 parent 877a9b9 commit 519285b

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

packages/theme-generator/src/color-panel/built-in/color-map.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/* `idx` 对应实际的颜色索引,例如 `--td-brand-color-light: var(--td-brand-1)` */
2-
3-
export const BRAND_TOKEN_MAP = [
4-
{ name: '--td-brand-color-light', idx: 1 },
5-
{ name: '--td-brand-color-focus', idx: 2 },
6-
{ name: '--td-brand-color-disabled', idx: 3 },
7-
];
8-
91
export const GRAY_TOKENS = [
102
'--td-bg-color-container-hover',
113
'--td-bg-color-secondarycontainer',

packages/theme-generator/src/color-panel/index.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ import {
346346
} from '../common/themes';
347347
import { colorAnimation, getThemeMode, getTokenValue, handleAttach, setUpModeObserver } from '../common/utils';
348348
349-
import { BRAND_TOKEN_MAP, FUNCTION_TOKENS } from './built-in/color-map';
349+
import { FUNCTION_TOKENS } from './built-in/color-map';
350350
import { ALL_PRESET_COLORS, DEFAULT_COLORS, RECOMMEND_COLORS, SCENE_COLORS } from './built-in/color-preset';
351351
352352
import ColorCollapse from './components/ColorCollapse';
@@ -461,6 +461,9 @@ export default {
461461
const hoverIdx = brandIdx - 1;
462462
const activeIdx = brandIdx > 8 ? brandIdx : brandIdx + 1;
463463
return [
464+
{ name: '--td-brand-color-light', idx: 1 },
465+
{ name: '--td-brand-color-focus', idx: isMobile(this.$device) ? 1 : 2 },
466+
{ name: '--td-brand-color-disabled', idx: 3 },
464467
...(!isMobile(this.$device) ? [{ name: '--td-brand-color-hover', idx: hoverIdx }] : []),
465468
{ name: '--td-brand-color', idx: brandIdx },
466469
{ name: '--td-brand-color-active', idx: activeIdx },
@@ -469,7 +472,7 @@ export default {
469472
updateBrandTokenMap() {
470473
const brandIdx = this.currentBrandIdx;
471474
const extraBrandTokens = this.generateBrandTokenMap(brandIdx);
472-
this.brandTokenMap = BRAND_TOKEN_MAP.concat(extraBrandTokens);
475+
this.brandTokenMap = extraBrandTokens;
473476
},
474477
updateFunctionTokenMap() {
475478
Object.keys(FUNCTION_TOKENS).forEach((type) => {
@@ -500,8 +503,8 @@ export default {
500503
const darkExtraTokens = this.generateBrandTokenMap(darkBrandIdx);
501504
502505
this.currentBrandIdx = this.brandIndexes[getThemeMode()];
503-
504-
if (this.$brandColor != this.$theme.value) {
506+
const shouldUpdateStyleSheet = this.$brandColor != this.$theme.value || trigger === 'update';
507+
if (shouldUpdateStyleSheet) {
505508
// 只在用户手动修改主题色时同步 stylesheet,避免覆盖内置主题自身的逻辑
506509
updateStyleSheetColor('brand', lightPalette, darkPalette, trigger);
507510
syncColorTokensToStyle(lightExtraTokens, darkExtraTokens);

0 commit comments

Comments
 (0)