@nlabs/storybook-addon-centered
v3.4.3
Published
Storybook decorator to center components
Downloads
4
Readme
Storybook Centered Decorator
Storybook Centered Decorator can be used to center components inside the preview in Storybook.
This addon works with Storybook for:
Usage
npm install @nlabs/storybook-addon-centered --save-dev
As a decorator
You can set the decorator locally.
example for React:
import { storiesOf } from '@nlabs/storybook-react';
import centered from '@nlabs/storybook-addon-centered';
import MyComponent from '../Component';
storiesOf('MyComponent', module)
.addDecorator(centered)
.add('without props', () => (<MyComponent />))
.add('with some props', () => (<MyComponent text="The Comp"/>));
Also, you can also add this decorator globally
example for React:
import { configure, addDecorator } from '@nlabs/storybook-react';
import centered from '@nlabs/storybook-addon-centered';
addDecorator(centered);
configure(function () {
//...
}, module);
As an extension
1 - Configure the extension
import { configure, setAddon } from '@nlabs/storybook-react';
import centered from '@nlabs/storybook-addon-centered';
setAddon({
addCentered(storyName, storyFn) {
this.add(storyName, (context) => (
centered.call(context, storyFn)
));
},
});
configure(function () {
//...
}, module);
2 - Use it in your story
import { storiesOf } from '@nlabs/storybook-react';
import Component from '../Component';
storiesOf('Component', module)
.addCentered('without props', () => (<Component />))