Skip to content

Commit a2977c2

Browse files
committed
doc: add css var
1 parent 91eb74b commit a2977c2

7 files changed

+311
-74
lines changed

site/src/router/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ const routes = [
7878
meta: { enTitle: 'Customize Theme', title: '定制主题', category: 'docs' },
7979
component: () => import('../vueDocs/customize-theme.en-US.md'),
8080
},
81+
82+
{
83+
path: 'vue/customize-theme-variable-cn',
84+
meta: { enTitle: 'Dynamic Theme (Experimental)', title: '动态主题', category: 'docs' },
85+
component: () => import('../vueDocs/customize-theme-variable.zh-CN.md'),
86+
},
87+
{
88+
path: 'vue/customize-theme-variable',
89+
meta: { enTitle: 'Dynamic Theme (Experimental)', title: '动态主题', category: 'docs' },
90+
component: () => import('../vueDocs/customize-theme-variable.en-US.md'),
91+
},
8192
{
8293
path: 'vue/migration-v2-cn',
8394
meta: { enTitle: 'V1 to V2', title: '从 v1 到 v2', category: 'docs' },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
order: 7.1
3+
title: Dynamic Theme (Experimental)
4+
---
5+
6+
Except [less customize theme](/docs/react/customize-theme), We also provide CSS Variable version to enable dynamic theme. You can check on [ConfigProvider](/components/config-provider/#components-config-provider-demo-theme) demo.
7+
8+
## Caveats
9+
10+
- This function requires at least `[email protected]`.
11+
12+
## How to use
13+
14+
### Import antd.variable.min.css
15+
16+
Replace your import style file with CSS Variable version:
17+
18+
```diff
19+
-- import 'ant-design-vue/dist/antd.min.css';
20+
++ import 'ant-design-vue/dist/antd.variable.min.css';
21+
```
22+
23+
Note: You need remove `babel-plugin-import` for the dynamic theme.
24+
25+
### Static config
26+
27+
Call ConfigProvider static function to modify theme color:
28+
29+
```ts
30+
import { ConfigProvider } from 'ant-design-vue';
31+
32+
ConfigProvider.config({
33+
theme: {
34+
primaryColor: '#25b864',
35+
},
36+
});
37+
```
38+
39+
## Conflict resolve
40+
41+
CSS Variable use `--ant` prefix by default. When exist multiple antd style file in your project, you can modify prefix to fix it.
42+
43+
### Adjust
44+
45+
Modify `prefixCls` on the root of ConfigProvider:
46+
47+
```tsx
48+
import { ConfigProvider } from 'ant-design-vue';
49+
50+
export default () => (
51+
<ConfigProvider prefixCls="custom">
52+
<MyApp />
53+
</ConfigProvider>
54+
);
55+
```
56+
57+
Also need call the static function to modify `prefixCls`:
58+
59+
```ts
60+
ConfigProvider.config({
61+
prefixCls: 'custom',
62+
theme: {
63+
primaryColor: '#25b864',
64+
},
65+
});
66+
```
67+
68+
### Compile less
69+
70+
Since prefix modified. Origin `antd.variable.css` should also be replaced:
71+
72+
```bash
73+
lessc --js --modify-var="ant-prefix=custom" ant-design-vue/dist/antd.variable.less modified.css
74+
```
75+
76+
### Related changes
77+
78+
In order to implement CSS Variable and maintain original usage compatibility, we added `@root-entry-name: xxx;` entry injection to the `dist/antd.xxx.less` file to support less dynamic loading of the corresponding less file. Under normal circumstances, you do not need to pay attention to this change. However, if your project directly references the less file in the `lib|es` directory. You need to configure `@root-entry-name: default;` (or `@root-entry-name: variable;`) at the entry of less so that less can find the correct entry.
79+
80+
In addition, we migrated `@import'motion'` and `@import'reset'` in `lib|es/style/minxins/index.less` to `lib|es/style/themes/xxx.less` In, because these two files rely on theme-related variables. If you use the relevant internal method, please adjust it yourself. Of course, we still recommend using the `antd.less` files in the `dist` directory directly instead of calling internal files, because they are often affected by refactoring.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
order: 7.1
3+
title: 动态主题(实验性)
4+
---
5+
6+
除了 [less 定制主题](/docs/vue/customize-theme) 外,我们还提供了 CSS Variable 版本以支持动态切换主题能力。你可以在 [ConfigProvider](/components/config-provider/#components-config-provider-demo-theme) 进行体验。
7+
8+
## 注意事项
9+
10+
- 该功能在 `[email protected]` 版本起支持。
11+
12+
## 如何使用
13+
14+
### 引入 antd.variable.min.css
15+
16+
替换当前项目引入样式文件为 CSS Variable 版本:
17+
18+
```diff
19+
-- import 'ant-design-vue/dist/antd.min.css';
20+
++ import 'ant-design-vue/dist/antd.variable.min.css';
21+
```
22+
23+
注:如果你使用了 `babel-plugin-import`,需要将其去除。
24+
25+
### 静态方法配置
26+
27+
调用 ConfigProvider 配置方法设置主题色:
28+
29+
```ts
30+
import { ConfigProvider } from 'ant-design-vue';
31+
32+
ConfigProvider.config({
33+
theme: {
34+
primaryColor: '#25b864',
35+
},
36+
});
37+
```
38+
39+
## 冲突解决
40+
41+
默认情况下,CSS Variable 会以 `--ant` 作为前缀。当你的项目中引用多份 css 文件时,可以通过修改前缀的方式避免冲突。
42+
43+
### 代码调整
44+
45+
通过 ConfigProvider 在顶层修改 `prefixCls`
46+
47+
```tsx
48+
import { ConfigProvider } from 'ant-design-vue';
49+
50+
export default () => (
51+
<ConfigProvider prefixCls="custom">
52+
<MyApp />
53+
</ConfigProvider>
54+
);
55+
```
56+
57+
通过静态方法设置主题色以及对应 `prefixCls`
58+
59+
```ts
60+
ConfigProvider.config({
61+
prefixCls: 'custom',
62+
theme: {
63+
primaryColor: '#25b864',
64+
},
65+
});
66+
```
67+
68+
### 编译 less
69+
70+
由于前缀变更,你需要重新生成一份对应的 css 文件。
71+
72+
```bash
73+
lessc --js --modify-var="ant-prefix=custom" ant-design-vue/dist/antd.variable.less modified.css
74+
```
75+
76+
### 相关变更
77+
78+
为了实现 CSS Variable 并保持原始用法兼容性,我们于 `dist/antd.xxx.less` 文件中添加了 `@root-entry-name: xxx;` 入口注入以支持 less 动态加载对应的 less 文件。一般情况下,你不需要关注该变化。但是,如果你的项目中直接引用了 `lib|es` 目录下的 less 文件。你需要在 less 入口处配置 `@root-entry-name: default;` (或者 `@root-entry-name: variable;`)以使 less 可以找到正确的入口。
79+
80+
此外,我们将 `lib|es/style/minxins/index.less` 中的 `@import 'motion'``@import 'reset'` 迁移至了 `lib|es/style/themes/xxx.less` 中,因为这两个文件依赖了主题相关变量。如果你使用了相关内部方法,请自行调整。当然,我们还是建议直接使用 `dist` 目录下的 `antd.less` 文件而非调用内部文件,因为它们经常会受重构影响。

site/src/vueDocs/customize-theme.en-US.md

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ Another approach to customize theme is creating a `less` file within variables t
121121

122122
Note: This way will load the styles of all components, regardless of your demand, which cause `style` option of `babel-plugin-import` not working.
123123

124+
### Dynamic theme
125+
126+
Runtime update theme color please [ref this doc](/docs/react/customize-theme-variable).
127+
124128
## How to avoid modifying global styles?
125129

126130
Currently ant-design-vue is designed as a whole experience and modify global styles (eg `body` etc). If you need to integrate ant-design-vue as a part of an existing website, it's likely you want to prevent ant-design-vue to override global styles.

site/src/vueDocs/customize-theme.zh-CN.md

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ module.exports = {
121121

122122
注意,这种方式已经载入了所有组件的样式,不需要也无法和按需加载插件 `babel-plugin-import` 的 `style` 属性一起使用。
123123

124+
### 动态主题色
125+
126+
在运行时调整主题色请[参考此处](/docs/vue/customize-theme-variable)。
127+
124128
## 没有生效?
125129

126130
注意样式必须加载 less 格式,一个常见的问题就是引入了多份样式,less 的样式被 css 的样式覆盖了。

site/src/vueDocs/i18n.en-US.md

+66-37
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,71 @@ Note: `fr_FR` is the filename, follow below.
3535

3636
Supported languages:
3737

38-
| Language | Filename |
39-
| --------------------- | -------- |
40-
| Arabic | ar_EG |
41-
| Bulgarian | bg_BG |
42-
| Catalan | ca_ES |
43-
| Czech | cs_CZ |
44-
| German | de_DE |
45-
| Greek | el_GR |
46-
| English (Global) | en_GB |
47-
| English | en_US |
48-
| Spanish | es_ES |
49-
| Estonian | et_EE |
50-
| Persian | fa_IR |
51-
| Finnish | fi_FI |
52-
| French (Belgium) | fr_BE |
53-
| French (France) | fr_FR |
54-
| Italian | it_IT |
55-
| Icelandic | is_IS |
56-
| Japanese | ja_JP |
57-
| Korean | ko_KR |
58-
| Norwegian | nb_NO |
59-
| Dutch (Belgium) | nl_BE |
60-
| Dutch | nl_NL |
61-
| Polish | pl_PL |
62-
| Portuguese (Brazil) | pt_BR |
63-
| Portuguese | pt_PT |
64-
| Slovak | sk_SK |
65-
| Serbian | sr_RS |
66-
| Slovenian | sl_SI |
67-
| Swedish | sv_SE |
68-
| Thai | th_TH |
69-
| Turkish | tr_TR |
70-
| Russian | ru_RU |
71-
| Ukrainian | uk_UA |
72-
| Vietnamese | vi_VN |
73-
| Chinese (Simplified) | zh_CN |
74-
| Chinese (Traditional) | zh_TW |
38+
| Language | Filename |
39+
| ------------------------ | -------- |
40+
| Arabic | ar_EG |
41+
| Azerbaijani | az_AZ |
42+
| Bulgarian | bg_BG |
43+
| Bangla (Bangladesh) | bn_BD |
44+
| Belarusian | by_BY |
45+
| Catalan | ca_ES |
46+
| Czech | cs_CZ |
47+
| Danish | da_DK |
48+
| German | de_DE |
49+
| Greek | el_GR |
50+
| English (United Kingdom) | en_GB |
51+
| English | en_US |
52+
| Spanish | es_ES |
53+
| Estonian | et_EE |
54+
| Persian | fa_IR |
55+
| Finnish | fi_FI |
56+
| French (Belgium) | fr_BE |
57+
| French (Canada) | fr_CA |
58+
| French (France) | fr_FR |
59+
| Irish (Ireland) | ga_IE |
60+
| Galician (Spain) | gl_ES |
61+
| Hebrew | he_IL |
62+
| Hindi | hi_IN |
63+
| Croatian | hr_HR |
64+
| Hungarian | hu_HU |
65+
| Armenian | hy_AM |
66+
| Indonesian | id_ID |
67+
| Italian | it_IT |
68+
| Icelandic | is_IS |
69+
| Japanese | ja_JP |
70+
| Georgian | ka_GE |
71+
| Kurdish (Kurmanji) | kmr_IQ |
72+
| Kannada | kn_IN |
73+
| Kazakh | kk_KZ |
74+
| Khmer | km_KH |
75+
| Korean | ko_KR |
76+
| Lithuanian | lt_LT |
77+
| Latvian | lv_LV |
78+
| Macedonian | mk_MK |
79+
| Malayalam (India) | ml_IN |
80+
| Mongolian | mn_MN |
81+
| Malay (Malaysia) | ms_MY |
82+
| Norwegian | nb_NO |
83+
| Nepal | ne_NP |
84+
| Dutch (Belgium) | nl_BE |
85+
| Dutch | nl_NL |
86+
| Polish | pl_PL |
87+
| Portuguese (Brazil) | pt_BR |
88+
| Portuguese | pt_PT |
89+
| Romanian | ro_RO |
90+
| Russian | ru_RU |
91+
| Slovak | sk_SK |
92+
| Serbian | sr_RS |
93+
| Slovenian | sl_SI |
94+
| Swedish | sv_SE |
95+
| Tamil | ta_IN |
96+
| Thai | th_TH |
97+
| Turkish | tr_TR |
98+
| Urdu (Pakistan) | ur_PK |
99+
| Ukrainian | uk_UA |
100+
| Vietnamese | vi_VN |
101+
| Chinese (Simplified) | zh_CN |
102+
| Chinese (Traditional) | zh_HK |
103+
| Chinese (Traditional) | zh_TW |
75104

76105
See usage at [ConfigProvider](/components/config-provider).

0 commit comments

Comments
 (0)