【发布时间】:2021-11-01 00:40:56
【问题描述】:
我有以下 css 已加载到我的项目中:
// Default theme (light mode)
:root {
/* Typography */
--col-body-text: #0b0c0c;
--col-body-text-light: #505a5f;
}
// Dark mode theme
:root.dark {
/* Typography */
--col-body-text: #c5c5c5;
--col-body-text-light: #f8f8f8;
}
在我的实际应用中,这按预期工作,但是,在故事书中,它忽略了暗模式变量。
我已经更新了我的 preview.js 文件,以便在选择暗模式时将“.dark”添加到 `HTML 元素中 - 这可以按预期工作 - 实际上组件中的所有其他暗模式特定代码都可以正常工作。只有那些变量被忽略了。
在我不知道的故事书中使用:root 是否存在问题?
如果有帮助,这里是将类添加到 HTML 元素的代码:
// get an instance to the communication channel for the manager and preview
const channel = addons.getChannel()
// switch body class for story along with interface theme
channel.on('DARK_MODE', isDark => {
if (isDark) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}
})
【问题讨论】:
标签: javascript css storybook darkmode