安裝
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