安装
yarn add storybook-addon-chakra-theme --dev
添加到 .storybook/addons.js
import 'storybook-addon-chakra-theme/dist/register';
将 addDecorator 添加到 .storybook/config.js
import { addDecorator } from '@storybook/react';
import { withThemesProvider } from 'storybook-addon-chakra-theme';
const themes = [theme1, theme2];
addDecorator(withThemesProvider(themes));
或
将 addDecorator 添加到 stories 中
import {withThemesProvider} from 'storybook-addon-chakra-theme';
const themes = [theme1, theme2];
storiesOf("demo", module)
.addDecorator(withThemesProvider(themes))
.add("demo div", () => <div>DEMO</div>);
提醒
确保每个主题都具有 name
属性。例如
const myTheme = {
name: "Light",
primaryColor: "blue"
}
这用于在 Storybook UI 中显示。
贡献
yarn
yarn build
yarn example
致谢和许可证参考
https://github.com/echoulen/storybook-addon-styled-component-theme https://github.com/JumboInteractiveLimited/storybook-addon-emotion-theme