It's long to navigate to the location of my component in my app after making a change
What if my visual change break other components?
I wasn't aware that this component was even existing
How can I enable people to quickly contribute to my component?
I'd like to have a visual documentation of my component
npm i -g @storybook/cli
cd my-react-app
getstorybook
This will:
npm i -g @storybook/cli
cd my-react-native-app
getstorybook
This will:
I got warnings and had to manually add react-dom to package.json
🤔
import React from 'react';
import { storiesOf } from '@storybook/react';
storiesOf('SearchBar', module)
.add('default', () => (
<SearchBar
value="Blabla"
hint="Enter your search keyword"
/>
));
storiesOf('SearchBar', module)
.add('default', () => ...)
.add('display an error', () => (
<SearchBar error="No internet connection"/>
));
//...
import { action } from '@storybook/addon-actions';
storiesOf('SearchBar', module)
.add('default', () => (
<SearchBar
value="Blabla"
onSearch={action('search launched')}
/>
));
// Decorator to allow material-ui components
// to read the app theme
const muiDecorator = (story) => (
<MuiThemeProvider muiTheme={defaultTheme}>
{story()}
</MuiThemeProvider>
)
// Add you decorator to any story using material-ui
storiesOf('AboutDialog', module)
.addDecorator(muiDecorator)
.add('default', () => <AboutDialog open />);
// You can create a helper component and reuse it:
const Serializer = props => (
<div>{props.children} {JSON.stringify(props.object)}</div>
);
storiesOf('ProfilePage', module).add('default', () => (
<Serializer object={profile}>
<ProfilePage profile={profile} />
</Serializer>
));
storiesOf('CartItemsList', module).add('default', () => (
<Serializer object={items}>
<CartItemsList items={items} />
</Serializer>
));
// Create fixtures, or better, share them with your unit tests :)
import complexFakeData from './fixtures/my-complex-data.json';
storiesOf('Dashboard', module)
.add('default', () => <Dashboard data={complexFakeData} />);
Edit props dynamically
Snapshot testing of your stories for free