-
Notifications
You must be signed in to change notification settings - Fork 21
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 #7 from buildo/6-add-flexview
- Loading branch information
Showing
11 changed files
with
193 additions
and
31 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,2 @@ | ||
*.css | ||
!example.css |
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,25 @@ | ||
import React from 'react'; | ||
import {FlexView, FlexCell} from '../../src/flex'; | ||
|
||
const Example = React.createClass({ | ||
|
||
propTypes: {}, | ||
|
||
getTemplate() { | ||
return ( | ||
<div> | ||
<FlexView className='hello' style={{backgroundColor: 'blue'}}> | ||
<div className='ui segment' style={{backgroundColor: 'red'}}/> | ||
<div className='ui segment' style={{backgroundColor: 'green'}}/> | ||
</FlexView> | ||
</div> | ||
); | ||
}, | ||
|
||
render() { | ||
return this.getTemplate(); | ||
} | ||
|
||
}); | ||
|
||
export default Example; |
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
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
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
This file was deleted.
Oops, something went wrong.
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
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,17 @@ | ||
import React from 'react'; | ||
import FlexView from './FlexView'; | ||
|
||
export default React.createClass({ | ||
|
||
getDefaultProps() { | ||
return { | ||
className: '', | ||
grow: true | ||
}; | ||
}, | ||
|
||
render() { | ||
return <FlexView {...this.props} className={`react-flex-cell ${this.props.className}`}/>; | ||
} | ||
|
||
}); |
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,101 @@ | ||
import React from 'react'; | ||
|
||
export default React.createClass({ | ||
|
||
propTypes: { | ||
children: React.PropTypes.node, | ||
row: React.PropTypes.bool, | ||
column: React.PropTypes.bool, | ||
auto: React.PropTypes.bool, | ||
centerVertically: React.PropTypes.bool, | ||
grow: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, | ||
React.PropTypes.string | ||
]), | ||
height: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, | ||
React.PropTypes.string | ||
]), | ||
width: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, | ||
React.PropTypes.string | ||
]), | ||
flexBasis: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, | ||
React.PropTypes.string | ||
]), | ||
className: React.PropTypes.string, | ||
style: React.PropTypes.object | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
className: '', | ||
style: {} | ||
}; | ||
}, | ||
|
||
getGrow() { | ||
if (typeof this.props.grow === 'number') { | ||
return this.props.grow; | ||
} else if (this.props.grow) { | ||
return 1; | ||
} else { | ||
return 0; // auto === true or default | ||
} | ||
}, | ||
|
||
getShrink() { | ||
if (this.props.flexBasis || this.props.auto) { | ||
return 0; | ||
} else { | ||
return 1; // grow === true or default | ||
} | ||
}, | ||
|
||
getBasis() { | ||
if (this.props.flexBasis) { | ||
const suffix = typeof this.props.flexBasis === 'number' ? 'px' : ''; | ||
return this.props.flexBasis + suffix; | ||
} else if (this.props.grow) { | ||
return '100%'; | ||
} else { | ||
return 'auto'; // auto === true or default | ||
} | ||
}, | ||
|
||
getFlexStyle() { | ||
const grow = this.getGrow(); | ||
const shrink = this.getShrink(); | ||
const basis = this.getBasis(); | ||
const values = `${grow} ${shrink} ${basis}`; | ||
return { | ||
WebkitBoxFlex: values, | ||
MozBoxFlex: values, | ||
msFlex: values, | ||
WebkitFlex: values, | ||
flex: values | ||
}; | ||
}, | ||
|
||
getStyle() { | ||
const sizeStyle = { | ||
width: this.props.width, | ||
height: this.props.height | ||
}; | ||
return {...this.getFlexStyle(), ...sizeStyle, ...this.props.style}; | ||
}, | ||
|
||
getClasses() { | ||
const direction = this.props.column ? 'flex-column' : 'flex-row'; | ||
const centerVertically = this.props.centerVertically === true ? 'flex-vertically-centered' : ''; | ||
return `react-flex-view ${direction} ${centerVertically} ${this.props.className}`; | ||
}, | ||
|
||
render() { | ||
const className = this.getClasses(); | ||
const style = this.getStyle(); | ||
return <div className={className} style={style}>{this.props.children}</div>; | ||
} | ||
|
||
}); |
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,34 @@ | ||
@import '../../node_modules/sass-flex-mixins/src/sass-flex-mixins.scss'; | ||
|
||
.react-flex-view { | ||
box-sizing: 'border-box'; | ||
@include display_flex(); | ||
@include flex_flex-wrap(nowrap); | ||
@include flex_align-items(stretch); | ||
|
||
&.flex-vertically-centered { | ||
@include flex_align-items(center); | ||
} | ||
|
||
&.flex-column { | ||
@include flex_flex-direction(column); | ||
} | ||
|
||
&.flex-row { | ||
@include flex_flex-direction(row); | ||
} | ||
|
||
&.flex-auto { | ||
@include flex_flex(0 0 auto); | ||
} | ||
|
||
&.flex-grow { | ||
@include flex_flex(1 1 100%); | ||
} | ||
|
||
} | ||
|
||
.react-flex-view.react-flex-cell { | ||
@include flex_justify-content(space-between); | ||
@include flex_align-content(space-between); | ||
} |
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,4 @@ | ||
import FlexView from './FlexView'; | ||
import FlexCell from './FlexCell'; | ||
|
||
export default { FlexView, FlexCell }; |