主题容器 ThemeProvider
ThemeProvider 可以独立使用,不需要依赖 ConfigProvider。它会在当前子树内创建主题作用域容器,仅影响该子树。
<theme-provider> 属性
Section titled “<theme-provider> 属性”| 参数名 | 描述 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| theme | 运行时主题对象 | SdThemeConfig |
- |
|
| theme-mode | 当前子树主题模式 | 'light' | 'dark' |
- |
|
| global | 是否直接作用于全局 body |
boolean |
false |
|
| tag | 局部容器标签名 | string |
'div' |
<theme-provider> 插槽
Section titled “<theme-provider> 插槽”| 插槽名 | 描述 | 参数 |
|---|---|---|
| default | 子树内容 | - |
暗色模式如何影响基础色?
Section titled “暗色模式如何影响基础色?”theme-mode 优先于 theme.algorithm,未指定时继承祖先模式;compact 不改变明暗。seed 色阶会按生效模式重新派生,主题浮层同步更新。显式 tokens 和组件覆盖仍拥有最高优先级,切换模式不会删除用户配置。
和 ConfigProvider 的区别是什么?
Section titled “和 ConfigProvider 的区别是什么?”ThemeProvider只处理主题作用域(theme/theme-mode/ CSS variables)。ConfigProvider除主题能力外,还提供locale、rtl、size等全局配置。
如果你只需要局部主题切换,优先使用 ThemeProvider。