Skip to content

Commit

Permalink
Merge pull request #3 from kadirahq/add-storybook
Browse files Browse the repository at this point in the history
Add storybook
  • Loading branch information
Muhammed Thanish committed Jun 3, 2016
2 parents fa6d3e4 + 6bd56ee commit c89172c
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { configure } from '@kadira/storybook';

configure(function () {
require('./stories/SplitPane');
}, module);
84 changes: 84 additions & 0 deletions .storybook/stories/SplitPane.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import { storiesOf, action } from '@kadira/storybook';
import { nomargin, content, HSplit } from './_utils';
import SplitPane from '../../';

const stories = storiesOf('SplitPane', module)
.addDecorator(nomargin);

// ---

stories.add('defaults', function () {
const props = {};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});

[ 'horizontal', 'vertical' ].forEach(split => {
stories.add('split:'+split, function () {
const props = {split};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});
});

[ 'first', 'second' ].forEach(primary => {
stories.add('primary:'+primary, function () {
const props = {primary};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});
});

[
{ parent: 'horizontal', child: 'horizontal' },
{ parent: 'horizontal', child: 'vertical' },
{ parent: 'vertical', child: 'horizontal' },
{ parent: 'vertical', child: 'vertical' },
].forEach(splits => {
stories.add(`${splits.parent}-${splits.child}`, function () {
const props1 = { key: 'child', split: splits.child};
const children1 = [ content('p1'), content('p2') ];
const splitpane1 = <SplitPane {...props1}>{children1}</SplitPane>;
const props2 = { key: 'parent', split: splits.parent};
const children2 = [ content('p3'), splitpane1 ];
return <SplitPane {...props2}>{children2}</SplitPane>;
});
});

stories.add('default size', function () {
const props = {defaultSize: 200};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});

stories.add('min/max size', function () {
const props = {minSize: 200, maxSize: 400};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});

stories.add('disable resize', function () {
const props = {allowResize: false};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});

stories.add('change event', function () {
const props = {onChange: action('change')};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});

stories.add('start/end events', function () {
const props = {onDragStarted: action('start'), onDragFinished: action('end')};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});

stories.add('custom splitter', function () {
const hsplit = <HSplit header="Split Pane Header" onClose={action('close')} />;
const props = {split: 'horizontal', resizerChildren: hsplit};
const children = [ content('p1'), content('p2') ];
return <SplitPane {...props}>{children}</SplitPane>;
});
71 changes: 71 additions & 0 deletions .storybook/stories/_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';

export function nomargin(storyFn) {
const style = {
position: 'absolute',
overflow: 'auto',
top: 0, right: 0, bottom: 0, left: 0,
};
return <div style={style}>{storyFn()}</div>;
}

export function content(key) {
return (
<div key={key} style={{overflow: 'hidden', width: '100%', height: '100%'}}>
<p style={{margin: 10}}>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
);
}

export const HSplit = React.createClass({
render() {
const style = {
cursor: 'row-resize',
background: '#EEEEEE',
borderBottom: 'solid #E0E0E0 1px',
borderTop: 'solid #E0E0E0 1px',
width: '100%',
};

const headerStyle = {
color: '#888',
float: 'left',
fontFamily: 'sans-serif',
fontSize: '11px',
letterSpacing: '1px',
lineHeight: 1,
margin: 0,
padding: '8px 10px 8px 10px',
textTransform: 'uppercase',
};

const buttonStyle = {
background: 'transparent',
border: 'none',
color: '#888',
float: 'right',
fontFamily: 'sans-serif',
fontSize: '11px',
lineHeight: 1,
outline: 'none',
padding: '8px 15px 8px 10px',
};

const clearFix = {
clear: 'both',
};

return (
<div style={style}>
<h3 style={headerStyle}>{this.props.header}</h3>
<button style={buttonStyle} onClick={this.props.onClose}></button>
<div style={clearFix}></div>
</div>
);
}
});

HSplit.propTypes = {
header: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
"surge": "^0.17.7",
"watchify": "^3.7.0"
"watchify": "^3.7.0",
"@kadira/storybook": "^1.28.1"
},
"scripts": {
"compile": "babel -d lib/ src/",
Expand All @@ -59,7 +60,8 @@
"demo": "npm run compile && browserify demo/Example.js -d -t -o demo/bundle.js",
"demo:watch": "npm run compile:watch & watchify demo/Example.js -d -t -o demo/bundle.js",
"demo:publish": "npm run compile && browserify demo/Example.js -d -t -o demo/bundle.js && surge demo react-split-pane.surge.sh",
"release:patch": "npm test && npm run compile && npm version patch && git push && npm publish"
"release:patch": "npm test && npm run compile && npm version patch && git push && npm publish",
"storybook": "start-storybook -p 9001"
},
"browserify": {
"transform": [
Expand Down

0 comments on commit c89172c

Please sign in to comment.