Skip to content

Commit 6efed2b

Browse files
lixl39505july
andauthored
fix(core): typography color should not be shared between light and dark (#3)
* fix: typography color configuration should distinguish between light and dark themes * chore: add pr template --------- Co-authored-by: july <[email protected]>
1 parent 412dcc4 commit 6efed2b

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### 关联 Issue
2+
3+
<!-- 请用 fixes、closes、resolves、relates 这些关键词来关联 issue,原则上,所有 PR 都应该有关联 Issue -->
4+
5+
### 主要改动
6+
7+
<!--
8+
@example:
9+
1. 修复了 xxx
10+
2. 改进了 xxx
11+
3. 调整了 xxx
12+
-->
13+
14+
### 界面截图
15+
16+
<!-- 如果改动的是跟 UI 相关的,不论是 CLI 还是 WEB 都应该截图 -->
17+
18+
### 测试计划 (暂无)
19+
20+
### 检查清单
21+
22+
- [ ] 本次变更新增了文件需要被包含在 npm 包的文件,且对应 package.json 的 files 字段包括了这些新增的文件
23+
- [ ] 本次变更需要更新文档,并且我更新了相关文档,如果还没更新文档,请新建文档更新的 Issue 并关联上来
24+
- [ ] 本次变更的兼容性测试覆盖了 Chrome
25+
- [ ] 本次变更的兼容性测试覆盖了 Safari
26+
- [ ] 本次变更的兼容性测试覆盖了 PC 端
27+
- [ ] 本次变更的兼容性测试覆盖了移动端【手机浏览器、钱包内置浏览器】

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.15 (2025-5-10)
2+
3+
- fix: typography color configuration should distinguish between light and dark themes
4+
15
## 0.1.14 (2025-5-7)
26

37
- feat: shared font configuration for light and dark modes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@blocklet/theme-builder",
33
"private": true,
44
"description": "A comprehensive tool to customize themes for Material-UI",
5-
"version": "0.1.14",
5+
"version": "0.1.15",
66
"keywords": [
77
"MUI",
88
"MUI v5",

src/state/reducers.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,40 @@ export default (state = initialState, action: any) => {
136136
const currentModeTheme = action.themeOptions;
137137
const otherMode = currentState.mode === 'light' ? 'dark' : 'light';
138138
const otherModeTheme = currentState.themeOptions[otherMode];
139-
const excludeFields = ['palette', 'components'];
140-
const { palette, components } = otherModeTheme;
139+
const excludeFields = ['palette', 'components', 'shadows'];
140+
const { palette, components, typography, shadows } = otherModeTheme;
141+
142+
// 只保留当前主题中存在的共享字段
143+
const newOtherModeTheme: ThemeOptions = {
144+
...Object.keys(currentModeTheme).reduce(
145+
(acc, key) => {
146+
if (!excludeFields.includes(key)) {
147+
acc[key] = currentModeTheme[key];
148+
}
149+
return acc;
150+
},
151+
{} as Record<string, unknown>,
152+
),
153+
palette,
154+
components,
155+
shadows,
156+
};
157+
158+
// 保留历史遗留字段 typography.color
159+
if (typeof typography === 'object' && typography.color) {
160+
if (typeof newOtherModeTheme.typography === 'object' && newOtherModeTheme.typography) {
161+
newOtherModeTheme.typography = {
162+
...newOtherModeTheme.typography,
163+
color: typography.color,
164+
};
165+
}
166+
}
141167

142168
// 创建新的主题配置,保持共享字段同步
143169
const newThemeOptions = {
144170
...currentState.themeOptions,
145171
[currentState.mode]: currentModeTheme,
146-
[otherMode]: {
147-
// 只保留当前主题中存在的共享字段
148-
...Object.keys(currentModeTheme).reduce(
149-
(acc, key) => {
150-
if (!excludeFields.includes(key)) {
151-
acc[key] = currentModeTheme[key];
152-
}
153-
return acc;
154-
},
155-
{} as Record<string, unknown>,
156-
),
157-
palette,
158-
components,
159-
},
172+
[otherMode]: newOtherModeTheme,
160173
};
161174

162175
return {

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.14
1+
0.1.15

0 commit comments

Comments
 (0)