Storybook Material-UI 模式插件
一个提供 UI 用于在明/暗模式之间切换状态的插件。
适用于 material-ui v4、v5
用法
在 .storybook/preview.js
或故事内部创建装饰器。
// .storybook/preview.js
import { useMemo } from "react";
import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";
import CssBaseline from "@material-ui/core/CssBaseline";
const withMuiTheme = (Story, context) => {
const mode = context.globals?.muiMode;
const theme = useMemo(() => createMuiTheme({
palette: {
mode, // for v5
// type: mode // for v4
}
}), [mode])
return (
<MuiThemeProvider theme={theme}>
<CssBaseline />
</MuiThemeProvider>
)
}