-
-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Add variable.less
to support css variable
#31496
Conversation
Codecov Report
@@ Coverage Diff @@
## feature #31496 +/- ##
========================================
Coverage 99.95% 99.96%
========================================
Files 409 410 +1
Lines 7461 7509 +48
Branches 2032 2039 +7
========================================
+ Hits 7458 7506 +48
Misses 3 3
Continue to review full report at Codecov.
|
|
Size Change: +70.1 kB (+8%) 🔍 Total Size: 912 kB
|
|
|
@@ -300,12 +329,15 @@ | |||
` | |||
); | |||
} | |||
& when not (@theme = dark) { | |||
& when (not (@theme = dark) and not (@theme = variable)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
有没有办法 我只改变 |
@zombieJ 散装的 |
import { generate } from '@ant-design/colors'; | ||
import { Theme } from './context'; | ||
|
||
export function registerTheme(theme: Theme) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个方法能暴露出来,或者挂到 windows 上面吗?
Congratulations! 🏆 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
666
```ts | ||
ConfigProvider.config({ | ||
theme: { | ||
prefixCls: 'custom', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://ant.design/components/config-provider-cn/#ConfigProvider.config()-4.13.0+
应该是这样?
ConfigProvider.config({
prefixCls: 'custom',
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个还没回复呀。@zombieJ
由于前缀变更,你需要重新生成一份对应的 css 文件。 | ||
|
||
```bash | ||
lessc --modify-var="ant-prefix=custom" antd/dist/antd.variable.less modified.css |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lessc --modify-var="ant-prefix=custom" antd/dist/antd.variable.less modified.css | |
lessc --modify-var="ant-prefix=custom" antd/dist/antd.variable.less modified.css |
```diff | ||
-- import 'antd/dist/antd.min.css'; | ||
++ import 'antd/dist/antd.variable.min.css'; | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
提示一下去掉 babel-plugin-import 里的 css 或 style 属性,避免样式重复(如果用到)。
@@ -291,7 +291,7 @@ | |||
"bundlesize": [ | |||
{ | |||
"path": "./dist/antd.min.js", | |||
"maxSize": "270 kB" | |||
"maxSize": "275 kB" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加了 2kB 多,主要是在哪里?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CSS 计算切换到 js,多了 3+ KB。
title: 动态主题(实验性) | ||
--- | ||
|
||
除了 [less 定制主题外](/docs/react/customize-theme) 外,我们还提供了 CSS Variable 版本以支持动态切换主题能力。你可以在 [ConfigProvider](/components/config-provider/#components-config-provider-demo-theme) 进行体验。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/react/customize-theme 里也补一下动态主题内容,链接到这里来。
纯文档更新, 我在 #31987 顺道一起了 |
@zombieJ, Thank you for you job! Could you explain, how I can use Dynamic Theme (experience) in That config worked fine.. // index.ts
import 'antd/dist/antd.variable.less'; // webpack.config.js
module.exports = {
rules: [{
test: /\.less$/,
use: [{
loader: 'style-loader',
}, {
loader: 'css-loader',
}, {
loader: 'less-loader',
options: {
lessOptions: {
modifyVars: {
'btn-height-sm': '32px',
'btn-height-lg': '48px',
'border-radius-base': '2px',
// ...other sizes variables
},
javascriptEnabled: true,
},
},
}],
}],
} .. but, now for change // index.ts
-- import 'antd/dist/antd.variable.less';
++ import 'antd/dist/antd.variable.min.css';
ConfigProvider.config({
theme: {
primaryColor: 'blue',
},
}); This changes lose modifyVars working. Buttons with size="large" has |
这个 feature 什么时候可以正式发布?我看现在还是 alpha |
@olivewind alpha 也可以用起来了。 |
升级 4.17.0-alpha.2 报这个错:
4.16.13 是好的 |
@wangjianio 提个 issue。 |
+1. Finally dynamic theming on runtime. It would be nice to see dynamic dark mode implementation in near future too. |
still no dynamic dark mode? |
Congrats to the work! I believe the dark theme can be much easier to implement when using css variables. |
@zombieJ umijs框架中,通过 |
Great Work! Save us much time on to be compatible with css variables. |
no dynamic dark mode! |
[中文版模板 / Chinese template]
📋 RFC
Summary
Support CSS Variable to dynamic change antd theme color with static function.
Basic example
Motivation
In antd, theme is generate on build time which means user can not dynamic change theme on runtime. There is some hack way like build replacement css file back of css variable (which may cause wrong design token of same valued variables) or create a less builder on client or server side to build style add inject back.
For the modern browsers, css variable is a cheaper way to dynamic change theme. To avoid breaking current user like IE 11, it should keep all the output as previous version but provide additional build file with css variables version like
antd.variable.css
&antd.variable.min.css
. So developer can chose to use these new variable style file to enable config provider static function.Detailed
To realize this feature, we need create another entry for build. Current components is strong deps on the root style file which use the less function to generate style variables and these function variables can not work in browser. We need:
default.less
and replace all the variables by css variableDrawbacks
Since design token use lots of less function, its hard to replace all the variable with native one. We may lock the static function in alpha for a long time util all the design token is validate to replace
Adoption strategy
alpha version will release sync with current version of antd. When all the design token replaced, we will release final version.
Not provide less version file since it can not split on less side.
🤔 This is a ...
💡 Background and solution
Before next major version. We consider to provide css variable support in v4 for the user who do not need support IE.
NOTE: This is far from finish since we do too much on less color calculation. To avoid break current behavior, we need some workaround to make it work.
https://preview-31496-ant-design.surge.sh/components/config-provider-cn/#components-config-provider-demo-theme
📝 Changelog
☑️ Self Check before Merge