主题容器 ThemeProvider
ThemeProvider 可以独立使用,不需要依赖 ConfigProvider。它会在当前子树内创建主题作用域容器,仅影响该子树。
<theme-provider> Props
Section titled “<theme-provider> Props”| 参数名 | 描述 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| theme | 运行时主题对象 | SDThemeConfig | - | |
| theme-mode | 当前子树主题模式 | 'light' | 'dark' | - | |
| global | 是否直接作用于全局 body | boolean | false | |
| tag | 局部容器标签名 | string | 'div' |
<theme-provider> Slots
Section titled “<theme-provider> Slots”| 插槽名 | 描述 | 参数 |
|---|---|---|
| default | 子树内容 | - |
和 ConfigProvider 的区别是什么?
Section titled “和 ConfigProvider 的区别是什么?”ThemeProvider只处理主题作用域(theme/theme-mode/ CSS variables)。ConfigProvider除主题能力外,还提供locale、rtl、size等全局配置。
如果你只需要局部主题切换,优先使用 ThemeProvider。