Skip to content

Commit af27290

Browse files
committed
docs: update customise-theme guide
- Add Theme Editor section documenting the visual editor - Fix import path: 'tiny-design' -> '@tiny-design/react' - Fix SCSS import path to @tiny-design/react/es/style/index - Fix GitHub links to correct monorepo paths (packages/tokens/scss/) - Add useTheme hook API table and commonly used tokens table
1 parent 75708f8 commit af27290

2 files changed

Lines changed: 88 additions & 20 deletions

File tree

apps/docs/guides/customise-theme.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
# Customise Theme
22

3-
Tiny UI provides two layers of theming:
3+
Tiny UI provides three ways to customise the look and feel:
44

5-
1. **Design tokens** — CSS custom properties that power light and dark mode. These are the runtime values every component reads.
6-
2. **SCSS variables** — compile-time variables (sizes, font stacks, border radii, etc.) that can be overridden when you build your own stylesheet.
5+
1. **Theme Editor** — a visual, no-code tool for real-time theming (great for exploration and quick customisation).
6+
2. **Design tokens** — CSS custom properties that power light and dark mode. These are the runtime values every component reads.
7+
3. **SCSS variables** — compile-time variables (sizes, font stacks, border radii, etc.) that can be overridden when you build your own stylesheet.
8+
9+
## Theme Editor
10+
11+
The built-in [Theme Editor](/theme/theme-editor) lets you visually customise design tokens in real time. You can:
12+
13+
- Pick from **20+ preset themes** (e.g. Catppuccin, Mocha Mousse, Cyberpunk) or start from scratch.
14+
- Adjust primary, success, warning, danger, and info colours, background, text, and border colours.
15+
- Tweak typography (font size, line height, font weight) and details (border radius, spacing, sizing).
16+
- Preview changes live on real components.
17+
- Export your customised tokens as CSS or SCSS to use in your project.
18+
19+
Changes are applied instantly via CSS custom properties — no rebuild required.
720

821
## Dark mode
922

@@ -23,14 +36,23 @@ Tiny UI ships with built-in light and dark themes. Light mode is the default. To
2336
You can also use the `useTheme` hook to switch themes at runtime:
2437

2538
```tsx
26-
import { useTheme } from 'tiny-design';
39+
import { useTheme } from '@tiny-design/react';
2740

2841
const App = () => {
29-
const { mode, setMode, toggle } = useTheme();
30-
return <button onClick={toggle}>Current: {mode}</button>;
42+
const { mode, resolvedTheme, setMode, toggle } = useTheme();
43+
return <button onClick={toggle}>Current: {resolvedTheme}</button>;
3144
};
3245
```
3346

47+
The hook returns:
48+
49+
| Property | Type | Description |
50+
|---|---|---|
51+
| `mode` | `'light' \| 'dark' \| 'system'` | The stored preference |
52+
| `resolvedTheme` | `'light' \| 'dark'` | The actual resolved theme (resolves `'system'` to the OS preference) |
53+
| `setMode(mode)` | `(mode: ThemeMode) => void` | Set a specific mode |
54+
| `toggle()` | `() => void` | Toggle between light and dark |
55+
3456
## Design tokens (CSS custom properties)
3557

3658
Every colour, shadow, and visual state is exposed as a `--ty-*` CSS custom property on `:root`. You can override any token in your own stylesheet:
@@ -43,9 +65,21 @@ Every colour, shadow, and visual state is exposed as a `--ty-*` CSS custom prope
4365
}
4466
```
4567

68+
### Commonly used tokens
69+
70+
| Token | Light default | Description |
71+
|---|---|---|
72+
| `--ty-color-primary` | `#6e41bf` | Primary brand colour |
73+
| `--ty-color-primary-hover` | `#8b62d0` | Primary hover state |
74+
| `--ty-color-primary-active` | `#5a30a8` | Primary active state |
75+
| `--ty-color-bg` | `#fff` | Page background |
76+
| `--ty-color-text` | `rgba(0,0,0,0.85)` | Primary text colour |
77+
| `--ty-color-text-secondary` | `rgba(0,0,0,0.65)` | Secondary text colour |
78+
| `--ty-color-border` | `#d9d9d9` | Default border colour |
79+
4680
The full list of tokens can be found in the source:
47-
- [Light theme tokens](https://github.com/wangdicoder/tiny-design/blob/master/components/style/themes/_light.scss)
48-
- [Dark theme tokens](https://github.com/wangdicoder/tiny-design/blob/master/components/style/themes/_dark.scss)
81+
- [Light theme tokens](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/themes/_light.scss)
82+
- [Dark theme tokens](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/themes/_dark.scss)
4983

5084
## SCSS variables
5185

@@ -70,7 +104,7 @@ $border-radius: 4px;
70104
$font-size-base: 14px;
71105

72106
// Import Tiny UI styles (applies your overrides via !default)
73-
@use "tiny-design/es/style/index" as *;
107+
@use "@tiny-design/react/es/style/index" as *;
74108
```
75109

76110
### 3. Import in your entry file
@@ -79,7 +113,7 @@ $font-size-base: 14px;
79113
import './theme-variables.scss';
80114
```
81115

82-
The full list of SCSS variables can be found in [_variables.scss](https://github.com/wangdicoder/tiny-design/blob/master/components/style/_variables.scss).
116+
The full list of SCSS variables can be found in [_variables.scss](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/_variables.scss).
83117

84118
Some commonly overridden variables:
85119

apps/docs/guides/customise-theme.zh_CN.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
# 自定义主题
22

3-
Tiny UI 提供两层主题定制方案
3+
Tiny UI 提供三种方式来定制外观
44

5-
1. **设计令牌(Design tokens)** — 驱动亮色/暗色模式的 CSS 自定义属性,所有组件在运行时读取这些值。
6-
2. **SCSS 变量** — 编译时变量(尺寸、字体、圆角等),可在构建自定义样式表时覆盖。
5+
1. **主题编辑器** — 一个可视化的实时主题工具,无需编写代码(非常适合探索和快速定制)。
6+
2. **设计令牌(Design tokens)** — 驱动亮色/暗色模式的 CSS 自定义属性,所有组件在运行时读取这些值。
7+
3. **SCSS 变量** — 编译时变量(尺寸、字体、圆角等),可在构建自定义样式表时覆盖。
8+
9+
## 主题编辑器
10+
11+
内置的[主题编辑器](/theme/theme-editor)让你可以实时可视化定制设计令牌。你可以:
12+
13+
-**20+ 个预设主题**中选择(如 Catppuccin、摩卡慕斯、赛博朋克等),或从零开始。
14+
- 调整主色、成功色、警告色、危险色和信息色,以及背景色、文本色和边框色。
15+
- 调整排版(字号、行高、字重)和细节(圆角、间距、尺寸)。
16+
- 在真实组件上实时预览更改效果。
17+
- 导出自定义的令牌为 CSS 或 SCSS,在你的项目中使用。
18+
19+
更改通过 CSS 自定义属性即时生效 — 无需重新构建。
720

821
## 暗色模式
922

@@ -23,14 +36,23 @@ Tiny UI 内置亮色和暗色主题。默认为亮色模式。要启用暗色模
2336
也可以使用 `useTheme` hook 在运行时切换主题:
2437

2538
```tsx
26-
import { useTheme } from 'tiny-design';
39+
import { useTheme } from '@tiny-design/react';
2740

2841
const App = () => {
29-
const { mode, setMode, toggle } = useTheme();
30-
return <button onClick={toggle}>当前:{mode}</button>;
42+
const { mode, resolvedTheme, setMode, toggle } = useTheme();
43+
return <button onClick={toggle}>当前:{resolvedTheme}</button>;
3144
};
3245
```
3346

47+
该 hook 返回:
48+
49+
| 属性 | 类型 | 说明 |
50+
|---|---|---|
51+
| `mode` | `'light' \| 'dark' \| 'system'` | 存储的用户偏好 |
52+
| `resolvedTheme` | `'light' \| 'dark'` | 实际解析的主题(将 `'system'` 解析为操作系统偏好) |
53+
| `setMode(mode)` | `(mode: ThemeMode) => void` | 设置指定模式 |
54+
| `toggle()` | `() => void` | 在亮色和暗色之间切换 |
55+
3456
## 设计令牌(CSS 自定义属性)
3557

3658
所有颜色、阴影和视觉状态都以 `--ty-*` CSS 自定义属性的形式暴露在 `:root` 上。你可以在自己的样式表中覆盖任意令牌:
@@ -43,9 +65,21 @@ const App = () => {
4365
}
4466
```
4567

68+
### 常用令牌
69+
70+
| 令牌 | 亮色默认值 | 说明 |
71+
|---|---|---|
72+
| `--ty-color-primary` | `#6e41bf` | 主品牌色 |
73+
| `--ty-color-primary-hover` | `#8b62d0` | 主色悬停状态 |
74+
| `--ty-color-primary-active` | `#5a30a8` | 主色激活状态 |
75+
| `--ty-color-bg` | `#fff` | 页面背景色 |
76+
| `--ty-color-text` | `rgba(0,0,0,0.85)` | 主文本色 |
77+
| `--ty-color-text-secondary` | `rgba(0,0,0,0.65)` | 次要文本色 |
78+
| `--ty-color-border` | `#d9d9d9` | 默认边框色 |
79+
4680
完整的令牌列表请参考源码:
47-
- [亮色主题令牌](https://github.com/wangdicoder/tiny-design/blob/master/components/style/themes/_light.scss)
48-
- [暗色主题令牌](https://github.com/wangdicoder/tiny-design/blob/master/components/style/themes/_dark.scss)
81+
- [亮色主题令牌](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/themes/_light.scss)
82+
- [暗色主题令牌](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/themes/_dark.scss)
4983

5084
## SCSS 变量
5185

@@ -70,7 +104,7 @@ $border-radius: 4px;
70104
$font-size-base: 14px;
71105

72106
// 引入 Tiny UI 样式(通过 !default 应用你的覆盖值)
73-
@use "tiny-design/es/style/index" as *;
107+
@use "@tiny-design/react/es/style/index" as *;
74108
```
75109

76110
### 3. 在入口文件中引入
@@ -79,7 +113,7 @@ $font-size-base: 14px;
79113
import './theme-variables.scss';
80114
```
81115

82-
完整的 SCSS 变量列表请参考 [_variables.scss](https://github.com/wangdicoder/tiny-design/blob/master/components/style/_variables.scss)
116+
完整的 SCSS 变量列表请参考 [_variables.scss](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/_variables.scss)
83117

84118
以下是一些常用的可覆盖变量:
85119

0 commit comments

Comments
 (0)