Norbert de Langen 991edf3f45 UPDATE readmes
2017-05-17 00:21:36 +02:00
..
2017-05-17 00:21:36 +02:00

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 i @storybook/addon-centered

As a decorator

You can set the decorator locally:

import React from 'react';
import { storiesOf } from '@storybook/react';
import MyComponent from '../Component';
import centered from '@storybook/addon-centered';

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 React from 'react';
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 React from 'react';
import { storiesOf } from '@storybook/react';
import Component from '../Component';

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