storybook-addon-jotai
v0.0.6
Published
A storybook addon that allows you to use components in your stories that rely on jotai atoms and see internal Jotai state in a panel.
Downloads
7,455
Readme
Storybook Jotai Addon
A Storybook Addon and Decorator for Jotai and track the state in a Panel.
TODO: Add screenshot here
Install
yarn add -D storybook-addon-jotai
Register the addon in .storybook/main.js
module.exports = {
stories: ['../stories/**/*.stories.tsx'],
addons: ['storybook-addon-jotai'],
};
Usage
Given a simple component:
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>
);
};
You can write a story as
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 = {};
Development scripts
yarn start
runs babel in watch mode and starts Storybookyarn build
build and package your addon code
Release Management
Creating a release
Automatically created when pushing to GitHub