mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-19 05:02:40 +08:00
Add Centered addon
This commit is contained in:
parent
17bf3be26d
commit
931dadf02c
@ -1,11 +1,11 @@
|
||||
## Addon / Framework Support Table
|
||||
|
||||
| |[React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [Mithril](app/html)|
|
||||
| |[React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [HTML](app/html)|
|
||||
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|
|
||||
|[a11y](addons/a11y) |+| | | | | | |
|
||||
|[actions](addons/actions) |+|+|+|+|+|+|+|
|
||||
|[background](addons/background) |+| | | | |+| |
|
||||
|[centered](addons/centered) |+| |+| | |+| |
|
||||
|[centered](addons/centered) |+| |+| | |+|+|
|
||||
|[events](addons/events) |+| | | | | | |
|
||||
|[graphql](addons/graphql) |+| | | | | | |
|
||||
|[info](addons/info) |+| | | | | | |
|
||||
|
1
addons/centered/html.js
Normal file
1
addons/centered/html.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./dist/html');
|
39
addons/centered/src/html.js
Normal file
39
addons/centered/src/html.js
Normal file
@ -0,0 +1,39 @@
|
||||
import { document, Node } from 'global';
|
||||
|
||||
const style = {
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
overflow: 'auto',
|
||||
};
|
||||
|
||||
const innerStyle = {
|
||||
margin: 'auto',
|
||||
};
|
||||
|
||||
export default function(storyFn) {
|
||||
const inner = document.createElement('div');
|
||||
Object.assign(inner.style, innerStyle);
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
Object.assign(wrapper.style, style);
|
||||
wrapper.appendChild(inner);
|
||||
|
||||
const component = storyFn();
|
||||
|
||||
if (typeof component === 'string') {
|
||||
inner.innerHTML = component;
|
||||
} else if (component instanceof Node) {
|
||||
inner.innerHTML = '';
|
||||
inner.appendChild(component);
|
||||
} else {
|
||||
return component;
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
}
|
@ -14,6 +14,7 @@
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@storybook/addon-actions": "^4.0.0-alpha.3",
|
||||
"@storybook/addon-centered": "^4.0.0-alpha.3",
|
||||
"@storybook/addon-knobs": "^4.0.0-alpha.3",
|
||||
"@storybook/addon-links": "^4.0.0-alpha.3",
|
||||
"@storybook/addon-options": "^4.0.0-alpha.3",
|
||||
|
@ -0,0 +1,6 @@
|
||||
import { storiesOf } from '@storybook/html';
|
||||
import centered from '@storybook/addon-centered/html';
|
||||
|
||||
storiesOf('Addons|Centered', module)
|
||||
.addDecorator(centered)
|
||||
.add('button in center', () => '<button>I am a Button !</button>');
|
Loading…
x
Reference in New Issue
Block a user