Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chodorowicz
Last active July 29, 2021 18:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chodorowicz/5854cf9f21ba0c9ec44d10febeafacdb to your computer and use it in GitHub Desktop.
Save chodorowicz/5854cf9f21ba0c9ec44d10febeafacdb to your computer and use it in GitHub Desktop.
react-storybook samples
/**
* dynamically loading all stories with .stories.js extension
*/
import { configure } from '@kadira/storybook';
require('es6-promise').polyfill();
import 'babel-polyfill';
const stories = require.context('../app/js/components', true, /.stories.js$/);
function loadStories() {
stories.keys().forEach(filename => stories(filename));
}
configure(loadStories, module);
/**
* using redux-mock-store
* using redux provider
* using stories decorators
*/
import React from 'react';
import { storiesOf } from '@kadira/storybook';
import { MenuToggle } from '../header/MenuToggle';
import Header from '../header/Header';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
const mockStore = configureStore();
const store = mockStore({
ui: {
isMenuOpened: true,
},
});
storiesOf('Header', module)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('with text', () => {
const config = {
version: 'standard',
config: {},
isLoggedIn: true,
user: {
access: 'buyer',
},
};
return <Header {...config} />;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment