-
Notifications
You must be signed in to change notification settings - Fork 304
refactor(theme-generator): streamline token management #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RylanBot
wants to merge
41
commits into
main
Choose a base branch
from
refactor/theme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
a28975c
refactor(theme-generator): streamline token management
RylanBot dd9a3a6
chore: remove unused components
RylanBot e37c94f
chore: organize dictionaries and update import
RylanBot 79785e8
chore: organize folders again
RylanBot 8128c0b
refactor: automatically extract the color index for tokens from CSS
RylanBot 7945ae9
refactor: enhance token management 😈
RylanBot 7fbba4a
fix: add missing code
RylanBot 7134b3b
fix: update `ColorPicker` attributes
RylanBot 1cad514
fix: adjust width for radio buttons
RylanBot c018ddd
fix: ensure `changeNeutralColor` works
RylanBot 104c047
fix(color-picker): make sure the popup is positioned correctly
RylanBot 3a7b22f
docs: add ARCHITECTURE_zh-CN.md
RylanBot e6aadd7
refactor: clean up unused CSS variables and update font sizes
RylanBot af199d1
chore(deps): update `tdesign-vue` to v1.13.0-naruto
RylanBot 6779058
fix(color-picker): update format prop
RylanBot 580474b
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot 978e93f
chore(deps): update `pnpm-lock.yaml`
RylanBot 24b589a
fix(panel-drawer): ensure mounting inside web components
RylanBot ec62c3a
chore: remove deprecated styles
RylanBot cc3795f
fix: update step and token initialization
RylanBot 1a68a63
docs: rename to `CONTRIBUTING_zh-CN`
RylanBot c8b5134
chore: remove unused CSS files
RylanBot a183566
chore(deps): update `tdesign-vue` to `1.13.1-naruto`
RylanBot 7a9e858
chore: remove unused props and styles
RylanBot 8859b14
fix: add tooltipProps to t-slider
RylanBot 4c7070b
refactor: improve color handling logic
RylanBot f586bb7
chore: try to debug NaN in deployment
RylanBot 7426d7a
fix: adjust padding for token list
RylanBot f936239
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot 55e0204
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot 45f0b13
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot 54c58b9
fix: ensure default theme mode is 'light' when not set
RylanBot b50c659
fix(color-panel): update color initialization logic
RylanBot 877a9b9
fix(segment-selection): adjust slider options to exclude the last item
RylanBot 519285b
fix(color-panel): update brand token logic
RylanBot f23526f
fix(size-panel): remove unused value property and log
RylanBot 7648169
chore: minify `tdesign.min.css`
RylanBot 9797bd9
Merge branch 'main' into refactor/theme
RylanBot 31dea0e
chore: typo
RylanBot 7fa1ab9
Merge branch 'main' into refactor/theme
uyarn 2df946a
chore: remove unused variables
RylanBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # CONTRIBUTING | ||
|
|
||
| **如果你想要新增特性或修复 Bug,建议阅读本文档,以便更好地理解代码的实现** | ||
|
|
||
| ## 📁 目录结构 | ||
|
|
||
| 项目 UI 层由一个浮动入口 `dock` 和一个包含多个功能面板的侧边 `panel` 组成: | ||
|
|
||
| ```mermaid | ||
| graph TB | ||
| A[Generator] --> B[float-dock] | ||
| A[Generator] --> C[panel-drawer] | ||
|
|
||
| C[panel-drawer] --> D[color-panel] | ||
| C[panel-drawer] --> E[font-panel] | ||
| C[panel-drawer] --> F[shadow-panel] | ||
| C[panel-drawer] --> G[radius-panel] | ||
| C[panel-drawer] --> H[size-panel] | ||
|
|
||
| classDef panelFill fill:#e6fffb,stroke:#13c2c2,stroke-width:2px; | ||
| class D,E,F,G,H panelFill; | ||
| ``` | ||
|
|
||
| 项目还包含两个文件夹: | ||
|
|
||
| ```mermaid | ||
| graph TB | ||
| A[styles] --> B["*.min.css 样式文件"] | ||
|
|
||
| C[common] --> D[components 通用组件] | ||
| C[common] --> E[i18n 国际化] | ||
| C[common] --> F[theme 核心逻辑<br>(包括内置主题模板和颜色算法等实现)] | ||
| C[common] --> G[utils 工具函数] | ||
|
|
||
| classDef themeFill fill:#e6f7ff,stroke:#1890ff,stroke-width:2px; | ||
| class F themeFill | ||
| ``` | ||
|
|
||
| `*.min.css` 文件来自 `tdesign-vue` 且经过二次压缩 | ||
|
|
||
| - 额外添加了 `:host` 选择器,确保 Web Components 打包后样式正常 | ||
| - 移除 `td-brand-color-x` 系列颜色 Token,使主题生成器能与外部主题色直接同步 | ||
|
|
||
| ## 🧚 交互逻辑 | ||
|
|
||
| ### 数据持久化 | ||
|
|
||
| 1. `custom-theme-options`: | ||
|
|
||
| | Key | 类型 | 示例 | | ||
| | ----------------------------- | -------------------------- | --------------------- | | ||
| | `theme` | 主题 | `TCloud` | | ||
| | `color` | 主题色 | `#45C58B` | | ||
| | `gray/success/warning/danger` | 功能色的品牌色 | `#2ba471` | | ||
| | `font/radius/shadow` | 预设步骤中的位置 | `1` | | ||
| | `line-height` | 固定或递增模式及其参数 | `plus_9` / `time_1.5` | | ||
| | `recommend` | 智能推荐 | `true` | | ||
| | `neutral` | 关联主题色 | `true` | | ||
|
|
||
| 2. `custom-theme-tokens`:各种 `--td-*` token,主要来自用户手动修改单个变量的操作 | ||
|
|
||
| ### 执行流程 | ||
|
|
||
| 1. **初始化**:根据本地存储的 `theme`(或默认主题),进行 CSS 模板挂载 | ||
|
|
||
| 2. **配置恢复**:读取本地存储的 `tokens`,并还原用户的自定义修改 | ||
|
|
||
| 3. **面板渲染**:各个 Panel 根据 `options` 确定初始化数值 | ||
|
|
||
| ## 😈 开发规范 | ||
|
|
||
| 1. **常量管理**:使用 `UPPER_CASE` 命名方式,独立存放在 JS 文件中,与 Vue 逻辑分离 | ||
|
|
||
| 2. **全局状态管理**:避免通过 props 层层传递共享变量,优先使用 `inject`、`mixin` 或 `store` 等 | ||
|
|
||
| 3. **动态编码管理**:避免硬编码数值,特别是 Token 相关的映射,优先从 CSS 中获取配置 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
packages/theme-generator/src/color-panel/built-in/color-map.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| export const GRAY_TOKENS = [ | ||
| '--td-bg-color-container-hover', | ||
| '--td-bg-color-secondarycontainer', | ||
| '--td-bg-color-secondarycontainer-hover', | ||
| '--td-bg-color-component-disabled', | ||
| '--td-bg-color-page', | ||
| '--td-bg-color-container-active', | ||
| '--td-bg-color-component', | ||
| '--td-component-stroke', | ||
| '--td-bg-color-secondarycontainer-active', | ||
| '--td-bg-color-component-hover', | ||
| '--td-component-border', | ||
| '--td-bg-color-component-active', | ||
| ]; | ||
|
|
||
| export const SUCCESS_TOKENS = [ | ||
| '--td-success-color-light', | ||
| '--td-success-color-focus', | ||
| '--td-success-color-disabled', | ||
| '--td-success-color-hover', | ||
| '--td-success-color', | ||
| '--td-success-color-active', | ||
| ]; | ||
|
|
||
| export const ERROR_TOKENS = [ | ||
| '--td-error-color-light', | ||
| '--td-error-color-focus', | ||
| '--td-error-color-disabled', | ||
| '--td-error-color-hover', | ||
| '--td-error-color', | ||
| '--td-error-color-active', | ||
| ]; | ||
|
|
||
| export const WARNING_TOKENS = [ | ||
| '--td-warning-color-light', | ||
| '--td-warning-color-focus', | ||
| '--td-warning-color-disabled', | ||
| '--td-warning-color-hover', | ||
| '--td-warning-color', | ||
| '--td-warning-color-active', | ||
| ]; | ||
|
|
||
| export const FUNCTION_TOKENS = { | ||
| gray: GRAY_TOKENS, | ||
| success: SUCCESS_TOKENS, | ||
| error: ERROR_TOKENS, | ||
| warning: WARNING_TOKENS, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.