Storybook Jotai 插件
一个用于 Storybook 的 Jotai 插件和装饰器,可以在面板中跟踪状态。
待办事项:在此处添加屏幕截图
安装
yarn add -D storybook-addon-jotai
在 .storybook/main.js
中注册插件
module.exports = {
stories: ['../stories/**/*.stories.tsx'],
addons: ['storybook-addon-jotai'],
};
用法
给定一个简单的组件
import { useAtom, atom } from 'jotai';
const userAtom = atom(null);
export const User = () => {
const [user] = useAtom(userAtom);
return (
<div>
{user ? (
<div>
<div>{`Logged in as ${user.name}`}</div>
<Button size="small" label="Log out" onClick={() => setUser(null)} />
</div>
) : (
<div>
<div>No one is signed in</div>
<Button size="small" label="Log in" onClick={() => setUser({ name: 'John' })}/>
</div>
)}
</div>
);
};
你可以编写一个故事,如下所示
import { withJotai } from 'storybook-addon-jotai';
import { User, userAtom } from '../components/User';
import { Header } from './Header';
export default {
title: 'Example/User',
component: User,
decorators: [withJotai],
};
const Template = (args) => <User {...args} />;
export const JohnLoggedIn = Template.bind({});
JohnLoggedIn.parameters = {
jotai: {
atoms: {
user: userAtom,
},
values: {
user: {
name: 'John Doe',
},
},
},
};
export const JaneLoggedIn = Template.bind({});
JaneLoggedIn.parameters = {
jotai: {
atoms: {
user: userAtom,
},
values: {
user: {
name: 'Jane Doe',
},
},
},
};
export const LoggedOut = Template.bind({});
LoggedOut.args = {};
开发脚本
yarn start
以监视模式运行 babel 并启动 Storybookyarn build
构建并打包你的插件代码
发布管理
创建发布
在推送到 GitHub 时自动创建