Skip to content

Instantly share code, notes, and snippets.

@SvitlanaShepitsena
Created December 22, 2016 23:48
Show Gist options
  • Save SvitlanaShepitsena/cc1dcbd9179c547a7cabad1af0d25414 to your computer and use it in GitHub Desktop.
Save SvitlanaShepitsena/cc1dcbd9179c547a7cabad1af0d25414 to your computer and use it in GitHub Desktop.
React Grid with Radium styles for 4 columns
import React, {PropTypes} from 'react';
import Radium from 'radium';
import withWidth2, {
X_SMALL,
SMALL,
H_SMALL,
MEDIUM,
X_MEDIUM,
LARGE
} from '../../../../../../../../../webapp/scripts/withWidth2.js';
class Grid_4col extends React.Component {
static propTypes = {
gridCol_1: PropTypes.object.isRequired,
gridCol_2: PropTypes.object.isRequired,
gridCol_3: PropTypes.object.isRequired,
gridCol_4: PropTypes.object.isRequired,
rowPadding: PropTypes.string,
colPadding: PropTypes.string
};
getStyles() {
let {width, rowPadding, colPadding}= this.props;
const styles = {
gridRow: {
position: 'relative',
boxSizing: 'border-box',
width: '100%',
maxWidth: '100%'
},
gridCol: {
display: 'inline-block',
verticalAlign: 'top',
width: '25%'
},
rowContainer: {
padding: rowPadding ? rowPadding : '0 5px'
},
colPadding: {
padding: colPadding ? colPadding : '5px'
}
};
if (width === X_SMALL || width === SMALL) {
styles.gridCol.width = '100%'
}
if (width === H_SMALL) {
styles.gridCol.width = '50%'
}
return styles;
}
render() {
const styles = this.getStyles();
return (
<div style={styles.rowContainer}>
<div style={styles.gridRow}>
<div style={styles.gridCol}>
<div style={styles.colPadding}>
{this.props.gridCol_1}
</div>
</div>
<div style={styles.gridCol}>
<div style={styles.colPadding}>
{this.props.gridCol_2}
</div>
</div>
<div style={styles.gridCol}>
<div style={styles.colPadding}>
{this.props.gridCol_3}
</div>
</div>
<div style={styles.gridCol}>
<div style={styles.colPadding}>
{this.props.gridCol_4}
</div>
</div>
</div>
</div>
);
}
}
export default withWidth2()(Radium(Grid_4col));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment