Skip to content
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a28975c
refactor(theme-generator): streamline token management
RylanBot Jul 20, 2025
dd9a3a6
chore: remove unused components
RylanBot Jul 20, 2025
e37c94f
chore: organize dictionaries and update import
RylanBot Jul 20, 2025
79785e8
chore: organize folders again
RylanBot Jul 21, 2025
8128c0b
refactor: automatically extract the color index for tokens from CSS
RylanBot Jul 28, 2025
7945ae9
refactor: enhance token management 😈
RylanBot Jul 29, 2025
7fbba4a
fix: add missing code
RylanBot Jul 29, 2025
7134b3b
fix: update `ColorPicker` attributes
RylanBot Jul 29, 2025
1cad514
fix: adjust width for radio buttons
RylanBot Jul 29, 2025
c018ddd
fix: ensure `changeNeutralColor` works
RylanBot Jul 30, 2025
104c047
fix(color-picker): make sure the popup is positioned correctly
RylanBot Jul 30, 2025
3a7b22f
docs: add ARCHITECTURE_zh-CN.md
RylanBot Jul 30, 2025
e6aadd7
refactor: clean up unused CSS variables and update font sizes
RylanBot Jul 31, 2025
af199d1
chore(deps): update `tdesign-vue` to v1.13.0-naruto
RylanBot Aug 7, 2025
6779058
fix(color-picker): update format prop
RylanBot Aug 7, 2025
580474b
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot Aug 7, 2025
978e93f
chore(deps): update `pnpm-lock.yaml`
RylanBot Aug 7, 2025
24b589a
fix(panel-drawer): ensure mounting inside web components
RylanBot Aug 7, 2025
ec62c3a
chore: remove deprecated styles
RylanBot Aug 7, 2025
cc3795f
fix: update step and token initialization
RylanBot Aug 12, 2025
1a68a63
docs: rename to `CONTRIBUTING_zh-CN`
RylanBot Aug 12, 2025
c8b5134
chore: remove unused CSS files
RylanBot Aug 22, 2025
a183566
chore(deps): update `tdesign-vue` to `1.13.1-naruto`
RylanBot Aug 22, 2025
7a9e858
chore: remove unused props and styles
RylanBot Aug 22, 2025
8859b14
fix: add tooltipProps to t-slider
RylanBot Aug 22, 2025
4c7070b
refactor: improve color handling logic
RylanBot Aug 22, 2025
f586bb7
chore: try to debug NaN in deployment
RylanBot Aug 22, 2025
7426d7a
fix: adjust padding for token list
RylanBot Aug 22, 2025
f936239
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot Aug 22, 2025
55e0204
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot Sep 29, 2025
45f0b13
Merge remote-tracking branch 'origin' into refactor/theme
RylanBot Sep 29, 2025
54c58b9
fix: ensure default theme mode is 'light' when not set
RylanBot Sep 29, 2025
b50c659
fix(color-panel): update color initialization logic
RylanBot Sep 29, 2025
877a9b9
fix(segment-selection): adjust slider options to exclude the last item
RylanBot Sep 29, 2025
519285b
fix(color-panel): update brand token logic
RylanBot Sep 29, 2025
f23526f
fix(size-panel): remove unused value property and log
RylanBot Sep 30, 2025
49ca526
chore: minify `tdesign.min.css`
RylanBot Sep 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions packages/theme-generator/CONTRIBUTING_zh-CN.md
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 中获取配置
21 changes: 11 additions & 10 deletions packages/theme-generator/README-zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# tdesign-theme-generator
<h1 style="text-align: center"><em><img alt="TDesign Logo" width="40" src="https://tdesign.tencent.com/favicon.ico"> TDesign Theme Generator</em></h1>

- TDesign 主题配置生成器挂件 支持任意框架使用。
[English](./README.md) | 简体中文

## 🏗️ Develop
TDesign 主题生成器挂件,专为组件库的文档站点量身打造,用于实时预览配色和样式的调整。

- `npm run dev`

- `npm run build:watch` 配合 npm link 进入站点热更新预览

- `npm run build` 构建 web component

## 📦 Usage
## 🔨 基础使用

1. `npm i tdesign-theme-generator`

Expand All @@ -27,3 +21,10 @@
generator.setAttribute('device', 'mobile');
document.body.appendChild(generator);
```

## 🏗️ 快速开发

```bash
npm link
npm run build:watch # 进入组件库站点热更新预览
```
23 changes: 11 additions & 12 deletions packages/theme-generator/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
## TDesign Theme Generator Plugin
<h1 style="text-align: center"><em><img alt="TDesign Logo" width="40" src="https://tdesign.tencent.com/favicon.ico"> TDesign Theme Generator</em></h1>

- TDesign theme generator plugin, which is available in any web application.
English | [简体中文](./README_zh-CN.md)

### 🏗️ Develop
TDesign theme generator plugin, which is tailored for the component library documentation site. It is used for real-time preview of color and style adjustments.

- `npm run dev`

- `npm run build:watch` execute `npm link` as well to preview in application project

### ⚙️ Build

- `npm run build` build web-component

### 📦 Usage
## 🔨 Usage

1. `npm i tdesign-theme-generator`

Expand All @@ -29,3 +21,10 @@
generator.setAttribute('device', 'mobile');
document.body.appendChild(generator);
```

## 🏗️ Develop

```bash
npm link
npm run build:watch # open the component library site with hot-reload preview
```
2 changes: 1 addition & 1 deletion packages/theme-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"cssbeautify": "^0.3.1",
"lodash": "^4.17.21",
"tdesign-icons-vue": "^0.0.8",
"tdesign-vue": "1.9.4-naruto",
"tdesign-vue": "1.13.1-naruto",
"tvision-color": "^1.6.0",
"vue": "2.7.14"
},
Expand Down
92 changes: 33 additions & 59 deletions packages/theme-generator/src/Generator.vue
Original file line number Diff line number Diff line change
@@ -1,51 +1,34 @@
<template>
<div class="theme-generator">
<dock
@trigger-visible="handleTriggerVisible"
@refresh-content="handleRefreshContent"
@change-theme="handleChangeTheme"
@click-setting="handleClickSetting"
<float-dock
:drawerVisible="visible"
:showSetting="showSetting"
@click-setting="handleClickSetting"
@trigger-visible="handleTriggerVisible"
/>
<panel-drawer
:drawerVisible="visible"
:theme="theme"
:refresh="refresh"
@panel-drawer-visible="handleDrawerVisible"
:propsTop="propsTop"
/>
<panel-drawer :drawerVisible="visible" @panel-drawer-visible="handleDrawerVisible" />
</div>
</template>

<script>
import {
applyThemeFromLocal,
DEFAULT_THEME,
generateNewTheme,
getOptionFromLocal,
applyTokenFromLocal,
initGeneratorVars,
syncModeToGenerator,
syncThemeToIframe,
} from './common/Themes';

import Dock from './dock/index.vue';
import PanelDrawer from './panel-drawer/index.vue';
themeStore,
} from './common/themes';

const activeTabMap = {
color: 0,
font: 1,
radius: 2,
shadow: 3,
size: 4,
};
import FloatDock from './float-dock';
import PanelDrawer from './panel-drawer';

export default {
name: 'ThemeGenerator',
components: {
FloatDock,
PanelDrawer,
Dock,
},
props: {
propsTop: String,
showSetting: {
type: [Boolean, String],
},
Expand All @@ -54,42 +37,31 @@ export default {
default: 'web',
},
},
provide() {
return {
device: this.device,
};
},
data() {
return {
activeTabMap,
refresh: false,
visible: 0,
activeTabIdx: activeTabMap.color,
theme: DEFAULT_THEME,
};
},
computed: {
$theme() {
return themeStore.theme;
},
},
mounted() {
const localTheme = getOptionFromLocal('color') ?? DEFAULT_THEME.value;
generateNewTheme(localTheme, undefined, this.device);
themeStore.updateDevice(this.device);
syncModeToGenerator();
initGeneratorVars();
applyTokenFromLocal();
syncThemeToIframe(this.device);
applyThemeFromLocal(this.device);
},
methods: {
handleChangeTheme(theme) {
this.theme = theme;
},
handleRefreshContent() {
this.refresh = !this.refresh;
},
handleTriggerVisible() {
this.visible = true;
},
handleDrawerVisible(v) {
this.visible = v;
this.$emit('panel-drawer-visible', v);
},
handleClickSetting() {
this.$emit('click-setting');
this.visible = false;
},
},
Expand All @@ -107,12 +79,15 @@ export default {
}
</style>
<style>
.t-popup .t-select-option {
font-size: 14px;
}
.t-popconfirm {
z-index: 10000;
}
.t-popconfirm .t-icon {
font-size: 20px !important;
}
.t-popup .t-select-option {
font-size: 14px;
}
.t-popup .t-input-number {
font-size: 14px;
}
Expand All @@ -122,23 +97,22 @@ export default {
.t-popup .t-icon {
font-size: 14px !important;
}

.t-popconfirm .t-icon {
font-size: 20px !important;
}
.t-popup .t-select__empty {
font-size: 14px;
}
.t-button.t-size-l {
font-size: 16px;
}
.t-radio-button__label {
font-size: 14px;
}
.t-radio-group__bg-block {
background: var(--bg-color-theme-radio-active) !important;
}
.t-slider__button {
width: 16px;
height: 16px;
}
.t-button.t-size-l {
font-size: 16px;
}
.t-button--variant-base.t-button--theme-primary:hover,
.t-button--variant-base.t-button--theme-primary:focus-visible {
border-color: var(--brand-main-hover);
Expand Down
10 changes: 0 additions & 10 deletions packages/theme-generator/src/README.md

This file was deleted.

48 changes: 48 additions & 0 deletions packages/theme-generator/src/color-panel/built-in/color-map.js
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,
};
Loading
Loading