-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kadirahq/add-storybook
Add storybook
- Loading branch information
Showing
4 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters