加入直播会话:周四,美国东部时间上午 11 点,Storybook 9 发布 & 答疑

带 Chakra 主题的 Storybook 插件

在 Github 上查看

安装

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