Skip to content

Latest commit

 

History

History
 
 

centered

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Storybook Centered Decorator

Greenkeeper badge Build Status CodeFactor Known Vulnerabilities BCH compliance codecov Storybook Slack

Storybook Centered Decorator can be used to center components inside the preview in Storybook.

This addon works with Storybook for: React.

Usage

npm install @storybook/addon-centered --save-dev

As a decorator

You can set the decorator locally:

import { storiesOf } from '@storybook/react';
import centered from '@storybook/addon-centered';

import MyComponent from '../Component';

storiesOf('MyComponent', module)
  .addDecorator(centered)
  .add('without props', () => (<MyComponent />))
  .add('with some props', () => (<MyComponent text="The Comp"/>));

Or you can also add this decorator globally:

import { configure, addDecorator } from '@storybook/react';
import centered from '@storybook/react-storybook-decorator-centered';

addDecorator(centered);

configure(function () {
  //...
}, module);

As an extension

1 - Configure the extension

import { configure, setAddon } from '@storybook/react';
import centered from '@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 '@storybook/react';

import Component from '../Component';

storiesOf('Component', module)
  .addCentered('without props', () => (<Component />))