Skip to content

Commit ed760d5

Browse files
authored
fix(react): migrate SCSS imports to local variables and fix Popup positioning (#101)
* fix(react): migrate SCSS imports to local variables and fix Popup positioning - Move all component SCSS imports from @tiny-design/tokens/scss/variables to local ../../style/variables, decoupling component styles from the tokens package SCSS source - Slim down @tiny-design/tokens by removing legacy SCSS files in favour of the v2 CSS-variable + runtime approach - Fix Popup component scroll-following by adding a useLayoutEffect that calls Popper forceUpdate after every render, ensuring position stays in sync with layout changes * chore: remove pro app
1 parent f21d252 commit ed760d5

215 files changed

Lines changed: 727 additions & 5740 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
"access": "public",
1515
"baseBranch": "master",
1616
"updateInternalDependencies": "patch",
17-
"ignore": ["@tiny-design/docs", "@tiny-design/extract", "@tiny-design/pro"]
17+
"ignore": ["@tiny-design/docs", "@tiny-design/extract"]
1818
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tiny-design/react": patch
3+
"@tiny-design/tokens": patch
4+
---
5+
6+
Migrate component SCSS imports from @tiny-design/tokens to local style/variables and fix Popup positioning sync

.github/workflows/deploy-site.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ jobs:
4646
- name: Copy 404.html for SPA routing
4747
run: cp apps/docs/build/index.html apps/docs/build/404.html
4848

49-
- name: Build pro site
50-
run: pnpm --filter @tiny-design/pro build
51-
env:
52-
NEXT_PUBLIC_BASE_PATH: /tiny-design/pro
53-
54-
- name: Merge pro into docs output
55-
run: cp -r apps/pro/out/ apps/docs/build/pro/
56-
5749
- name: Upload artifact
5850
uses: actions/upload-pages-artifact@v3
5951
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ es
77
lib
88
coverage
99
apps/docs/build
10+
apps/docs/test-results
11+
apps/docs/playwright-report
1012

1113
# Turbo
1214
.turbo

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Tiny Design is a React component UI library (80+ components) published as `@tiny
88

99
```
1010
packages/react/ → @tiny-design/react (main component library)
11-
packages/tokens/ → @tiny-design/tokens (design tokens, SCSS variables)
11+
packages/tokens/ → @tiny-design/tokens (v2 design tokens and theme runtime)
1212
packages/icons/ → @tiny-design/icons (SVG icon components)
1313
apps/docs/ → documentation site (Vite + MDX)
1414
```

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The package root barrel must also re-export those public component types from `p
8787
- TypeScript strict mode is enabled
8888
- Components use `React.forwardRef` for ref forwarding
8989
- CSS class names follow the `ty-component-name` convention
90-
- SCSS variables are in `packages/react/src/style/_variables.scss`
90+
- Shared Sass helpers for React component styles live in `packages/react/src/style/`
9191

9292
## Running Tests
9393

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,14 @@ Every visual token is a `--ty-*` CSS custom property. Override any of them:
104104
}
105105
```
106106

107-
### SCSS variables
108-
109-
For compile-time control, override `!default` SCSS variables before importing:
110-
111-
```scss
112-
$primary-color: #3b82f6;
113-
$border-radius: 8px;
114-
@use "@tiny-design/react/es/style/index" as *;
115-
```
116-
117-
See the [Theming Guide](https://wangdicoder.github.io/tiny-design/theme/customise-theme) for the full list of tokens and variables.
107+
See the [Theming Guide](https://wangdicoder.github.io/tiny-design/theme/customise-theme) for the full token list and Theme Studio workflow.
118108

119109
## Packages
120110

121111
| Package | Description |
122112
| ------- | ----------- |
123113
| [@tiny-design/react](./packages/react) | Core component library |
124-
| [@tiny-design/tokens](./packages/tokens) | Design tokens and foundational styles |
114+
| [@tiny-design/tokens](./packages/tokens) | V2 design tokens and theme runtime |
125115
| [@tiny-design/icons](./packages/icons) | SVG icon components |
126116
| [@tiny-design/cli](./packages/cli) | CLI for the Tiny Design component library |
127117
| [@tiny-design/mcp](./packages/mcp) | MCP server for AI assistants to access the component library |

_template/style/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@use '@tiny-design/tokens/scss/variables' as *;
1+
@use '../../style/variables' as *;

apps/docs/guides/customise-theme.md

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Customise Theme
22

3-
Tiny UI now uses a v2 token system with one primary runtime model:
3+
Tiny UI uses a token-driven runtime theme model:
44

55
1. **CSS custom properties** for direct runtime overrides.
66
2. **ThemeDocument** for portable theme JSON.
77
3. **ConfigProvider `theme.tokens`** for React-scoped theming.
88

9-
SCSS constants still exist, but they are only for compile-time structural overrides.
10-
119
## Theme Editor
1210

1311
The built-in [Theme Editor](/theme/theme-studio) lets you visually customise design tokens in real time. You can:
@@ -20,7 +18,7 @@ The built-in [Theme Editor](/theme/theme-studio) lets you visually customise des
2018

2119
Changes are applied instantly via CSS custom properties — no rebuild required.
2220

23-
The editor exports the same v2 token model used by the runtime, so the result can be applied as CSS variables, stored as a `ThemeDocument`, or passed into `ConfigProvider`.
21+
The editor exports the same token model used by the runtime, so the result can be applied as CSS variables, stored as a `ThemeDocument`, or passed into `ConfigProvider`.
2422

2523
## Dark mode
2624

@@ -102,13 +100,13 @@ html[data-tiny-theme='dark'] {
102100
| `--ty-color-text` | `rgba(0,0,0,0.85)` | Primary text colour |
103101
| `--ty-color-text-secondary` | `rgba(0,0,0,0.65)` | Secondary text colour |
104102
| `--ty-color-border` | `#d9d9d9` | Default border colour |
105-
| `--ty-border-radius` | `2px` | Global border radius |
106-
| `--ty-font-size-base` | `1rem` | Base font size |
103+
| `--ty-border-radius` | `6px` | Global border radius |
104+
| `--ty-font-size-base` | `14px` | Base font size |
107105
| `--ty-height-sm` | `24px` | Small control height |
108-
| `--ty-height-md` | `32px` | Medium control height |
109-
| `--ty-height-lg` | `42px` | Large control height |
106+
| `--ty-height-md` | `35px` | Medium control height |
107+
| `--ty-height-lg` | `44px` | Large control height |
110108

111-
Every component also has its own tokens for fine-grained control. For example, Button uses `--ty-button-bg-default`, `--ty-button-text-default`, and `--ty-button-radius`. The full list of supported tokens is generated from the v2 registry and component sources:
109+
Every component also has its own tokens for fine-grained control. For example, Button uses `--ty-button-bg-default`, `--ty-button-text-default`, and `--ty-button-radius`. The full list of supported tokens is generated from the token registry and component sources:
112110
- [Token registry](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/dist/registry.json)
113111
- [Component token sources](https://github.com/wangdicoder/tiny-design/tree/master/packages/tokens/source/components)
114112

@@ -178,65 +176,21 @@ Use this when you want:
178176
- nested theme overrides
179177
- popup / portal content to inherit the same token scope
180178

181-
`ConfigProvider` no longer uses the old `theme.token` or `theme.components` API. Use `theme.tokens.semantic` and `theme.tokens.components` only.
182-
183-
## SCSS constants
184-
185-
If you import Tiny UI's SCSS source instead of the pre-built CSS, you can override compile-time structural constants such as padding, transitions, and arrow sizes. These are values that don't need to change at runtime.
186-
187-
Every constant uses the `!default` flag, so your overrides take precedence.
188-
189-
### 1. Install Sass
190-
191-
```bash
192-
$ npm install sass --save-dev
193-
```
194-
195-
### 2. Create your overrides file
196-
197-
Create a file, e.g. `theme-overrides.scss`. Your overrides **must come before** the Tiny UI import:
179+
Use `theme.tokens.semantic` and `theme.tokens.components` as the supported React theme shape.
198180

199-
```scss
200-
// Override structural constants
201-
$btn-padding-md: 0 20px;
202-
$card-body-padding: 20px;
203-
$tooltip-arrow-size: 6px;
181+
## Sass source styles
204182

205-
// Import Tiny UI styles (applies your overrides via !default)
206-
@use "@tiny-design/react/es/style/index" as *;
207-
```
208-
209-
### 3. Import in your entry file
210-
211-
```js
212-
import './theme-overrides.scss';
213-
```
214-
215-
The full list of SCSS constants can be found in [_constants.scss](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/_constants.scss).
183+
Tiny UI still ships Sass source files for bundlers that compile library styles directly, but Sass variables are not a theme API. Treat `@tiny-design/react/es/style/*.scss` and component `style/*.scss` files as implementation source, not as supported customisation contracts.
216184

217-
Some commonly overridden constants:
218-
219-
```scss
220-
// Button
221-
$btn-padding-sm: 0 10px !default;
222-
$btn-padding-md: 0 15px !default;
223-
$btn-padding-lg: 0 28px !default;
224-
225-
// Card
226-
$card-header-padding: 13px 16px !default;
227-
$card-body-padding: 16px !default;
228-
229-
// Notification
230-
$notification-width: 380px !default;
231-
```
185+
Use tokens for visual changes such as colour, typography, radii, shadows, spacing, sizing, and component states. If a value is not exposed as a token yet, prefer adding it to the token registry instead of adding a new public Sass variable.
232186

233-
> **Note:** Colours, typography, radii, shadows, and all other visual tokens should be customised through v2 tokens, not SCSS variables. SCSS constants are only for compile-time structural values like padding and sizing.
187+
The full token list is generated from `packages/tokens/dist/registry.json`.
234188

235189
## Recommended approach
236190

237191
- Use CSS variables when you want the simplest runtime override.
238192
- Use `ThemeDocument` when you need a portable JSON theme format.
239193
- Use `ConfigProvider` when you need scoped theming in React.
240-
- Use SCSS constants only when a value must be decided at build time.
194+
- Avoid treating Sass variables as public theme configuration; add missing customisation points as tokens.
241195

242-
Please report an issue if the existing list of tokens or constants is not enough for you.
196+
Please report an issue if the existing list of tokens is not enough for you.

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

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

3-
Tiny UI 现在使用 v2 token 系统,推荐的主题自定义方式收敛为一套主模型
3+
Tiny UI 使用由 token 驱动的运行时主题模型
44

55
1. **CSS 自定义属性**,用于直接做运行时覆盖。
66
2. **ThemeDocument**,用于可移植的主题 JSON。
77
3. **ConfigProvider `theme.tokens`**,用于 React 作用域主题。
88

9-
SCSS 常量仍然保留,但它只用于编译期的结构性覆盖。
10-
119
## 主题编辑器
1210

1311
内置的[主题编辑器](/theme/theme-studio)让你可以实时可视化定制设计令牌。你可以:
@@ -20,7 +18,7 @@ SCSS 常量仍然保留,但它只用于编译期的结构性覆盖。
2018

2119
更改通过 CSS 自定义属性即时生效 — 无需重新构建。
2220

23-
主题编辑器导出的也是同一套 v2 token 模型,因此结果既可以作为 CSS 变量使用,也可以保存为 `ThemeDocument`,或者传给 `ConfigProvider`
21+
主题编辑器导出的也是同一套运行时 token 模型,因此结果既可以作为 CSS 变量使用,也可以保存为 `ThemeDocument`,或者传给 `ConfigProvider`
2422

2523
## 暗色模式
2624

@@ -102,13 +100,13 @@ html[data-tiny-theme='dark'] {
102100
| `--ty-color-text` | `rgba(0,0,0,0.85)` | 主文本色 |
103101
| `--ty-color-text-secondary` | `rgba(0,0,0,0.65)` | 次要文本色 |
104102
| `--ty-color-border` | `#d9d9d9` | 默认边框色 |
105-
| `--ty-border-radius` | `2px` | 全局圆角 |
106-
| `--ty-font-size-base` | `1rem` | 基础字号 |
103+
| `--ty-border-radius` | `6px` | 全局圆角 |
104+
| `--ty-font-size-base` | `14px` | 基础字号 |
107105
| `--ty-height-sm` | `24px` | 小尺寸控件高度 |
108-
| `--ty-height-md` | `32px` | 中尺寸控件高度 |
109-
| `--ty-height-lg` | `42px` | 大尺寸控件高度 |
106+
| `--ty-height-md` | `35px` | 中尺寸控件高度 |
107+
| `--ty-height-lg` | `44px` | 大尺寸控件高度 |
110108

111-
每个组件也有自己的令牌,用于细粒度控制。例如,Button 使用 `--ty-button-bg-default``--ty-button-text-default``--ty-button-radius`。完整的受支持令牌列表来自 v2 registry 和组件 source:
109+
每个组件也有自己的令牌,用于细粒度控制。例如,Button 使用 `--ty-button-bg-default``--ty-button-text-default``--ty-button-radius`。完整的受支持令牌列表来自 token registry 和组件 source:
112110
- [Token registry](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/dist/registry.json)
113111
- [组件 token 源文件](https://github.com/wangdicoder/tiny-design/tree/master/packages/tokens/source/components)
114112

@@ -178,65 +176,21 @@ import { ConfigProvider } from '@tiny-design/react';
178176
- 需要嵌套主题覆盖
179177
- 需要让弹层 / portal 内容继承同一个 token 作用域
180178

181-
`ConfigProvider` 已经不再使用旧的 `theme.token``theme.components` API。现在只使用 `theme.tokens.semantic``theme.tokens.components`
182-
183-
## SCSS 常量
184-
185-
如果你引入的是 Tiny UI 的 SCSS 源文件而非预编译的 CSS,可以覆盖编译时结构常量,如内边距、过渡动画和箭头尺寸。这些是不需要在运行时变化的值。
186-
187-
每个常量都使用了 `!default` 标志,因此你的覆盖值会优先生效。
188-
189-
### 1. 安装 Sass
190-
191-
```bash
192-
$ npm install sass --save-dev
193-
```
194-
195-
### 2. 创建覆盖文件
196-
197-
创建一个文件,例如 `theme-overrides.scss`。你的覆盖值**必须写在** Tiny UI 引入语句之前:
179+
`theme.tokens.semantic``theme.tokens.components` 是受支持的 React 主题结构。
198180

199-
```scss
200-
// 覆盖结构常量
201-
$btn-padding-md: 0 20px;
202-
$card-body-padding: 20px;
203-
$tooltip-arrow-size: 6px;
181+
## Sass 源码样式
204182

205-
// 引入 Tiny UI 样式(通过 !default 应用你的覆盖值)
206-
@use "@tiny-design/react/es/style/index" as *;
207-
```
208-
209-
### 3. 在入口文件中引入
210-
211-
```js
212-
import './theme-overrides.scss';
213-
```
214-
215-
完整的 SCSS 常量列表请参考 [_constants.scss](https://github.com/wangdicoder/tiny-design/blob/master/packages/tokens/scss/_constants.scss)
183+
Tiny UI 仍然发布 Sass 源文件,方便需要直接编译库样式的构建工具使用;但 Sass 变量不再是主题 API。请把 `@tiny-design/react/es/style/*.scss` 和组件 `style/*.scss` 当作实现源码,而不是受支持的主题定制契约。
216184

217-
以下是一些常用的可覆盖常量:
218-
219-
```scss
220-
// 按钮
221-
$btn-padding-sm: 0 10px !default;
222-
$btn-padding-md: 0 15px !default;
223-
$btn-padding-lg: 0 28px !default;
224-
225-
// 卡片
226-
$card-header-padding: 13px 16px !default;
227-
$card-body-padding: 16px !default;
228-
229-
// 通知
230-
$notification-width: 380px !default;
231-
```
185+
颜色、排版、圆角、阴影、间距、尺寸和组件状态等视觉定制都应该通过 token 完成。如果某个值还没有对应 token,优先把它补进 token registry,而不是新增公开 Sass 变量。
232186

233-
> **注意:** 颜色、排版、圆角、阴影等所有视觉令牌,都应该通过 v2 token 定制,而不是通过 SCSS 变量。SCSS 常量只适用于内边距、尺寸等编译期结构值
187+
完整 token 列表由 `packages/tokens/dist/registry.json` 生成
234188

235189
## 推荐用法
236190

237191
- 想最快做运行时覆盖,用 CSS 变量
238192
- 需要可移植的 JSON 主题格式,用 `ThemeDocument`
239193
- 需要 React 局部主题,用 `ConfigProvider`
240-
- 只有在值必须在构建期决定时,才使用 SCSS 常量
194+
- 不要把 Sass 变量当作公开主题配置;缺失的定制点应该补成 token
241195

242-
如果现有的令牌或常量列表无法满足你的需求,请提交 issue 反馈。
196+
如果现有的令牌列表无法满足你的需求,请提交 issue 反馈。

0 commit comments

Comments
 (0)