mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-19 05:02:40 +08:00
Storybook Centered Decorator
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 />))