ant-design / antd-style

css-in-js library with antd v5 token system
https://ant-design.github.io/antd-style/
MIT License
189 stars 29 forks source link

🧐[问题] appearance 和 themeMode 有什么不同吗? #52

Closed xiaohuoni closed 1 year ago

xiaohuoni commented 1 year ago

🧐 问题描述

appearance 和 themeMode 有什么不同吗?为什么不要一个设置就好,什么时候该用 appearance 什么时候该用 themeMode ,感觉全用 themeMode 也可以满足所有场景?

💻 示例代码

🚑 其他信息

arvinxx commented 1 year ago

appearance 描述了应用当前的外观状态。

themeMode 则用于描述控制逻辑。

结合这个demo看下:http://localhost:8000/~demos/docs-guide-switch-theme-demo-controlledswitch

image

譬如我设置 themeMode = 'auto' 的时候, appearance 会自动跟随当前的浏览器外观进行变更,此时这个值为 light,当浏览器变成暗色模式,此时 themeMode 仍然为 'auto' , appearance 会变成 ’dark‘ 。

如果这两个值不拆开,想知道当前是处于“亮色”还是“暗色”,这个逻辑的处理就会很复杂,我在业务里已经试过。

拆开之后控制逻辑和最终展示逻辑能够剥离地比较干净。而且未来做高级的主题切换也会很容易(现在还没实现这块)。

譬如类似 Github 这样的就比较典型:

image

Dark 和 Light Mode 下其实会有很多类型的主题,同时github 也支持自动跟随、使用亮色或者使用暗色。

在上述场景下,themeMode 就等于 github 的大模式选择; appearance 等于各个主题下的小外观形态。

xiaohuoni commented 1 year ago

明白了,感谢

chj-damon commented 1 year ago

也就是说appearance不仅仅只是light | dark 这两个值,还可以有更多的值?

arvinxx commented 1 year ago

也就是说appearance不仅仅只是light | dark 这两个值,还可以有更多的值?

对。你具体看下文档里最后一个例子。以及看下它的类型定义。另外可以看下这个

https://dumi-theme-antd-style.arvinx.app/guide/demo

要实现这个能力必须将appearance和themeMode区分出来

chj-damon commented 1 year ago

明白了。谢谢

xiaohuoni commented 1 year ago

@chj-damon 天天走我的老路!