forked from sjoerdapp/styleguide2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCol.js
More file actions
executable file
·61 lines (51 loc) · 1.49 KB
/
Copy pathCol.js
File metadata and controls
executable file
·61 lines (51 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, {Component, PropTypes} from 'react';
import style from 'flexboxgrid';
const ModificatorType = PropTypes.oneOfType([PropTypes.number, PropTypes.bool]);
export default class Col extends Component {
constructor(props) {
super(props);
this._classMap = {
xs: 'col-xs',
sm: 'col-sm',
md: 'col-md',
lg: 'col-lg',
xsOffset: 'col-xs-offset',
smOffset: 'col-sm-offset',
mdOffset: 'col-md-offset',
lgOffset: 'col-lg-offset'
};
}
render() {
const classes = [];
if (this.props.className) {
classes.push(this.props.className);
}
if (this.props.reverse) {
classes.push(style.reverse);
}
for (const key in this.props) {
if (this.props.hasOwnProperty(key) && this._classMap[key]) {
let colBaseClass = this._classMap[key];
colBaseClass = Number.isInteger(this.props[key]) ? (colBaseClass + '-' + this.props[key]) : colBaseClass;
classes.push(style[colBaseClass]);
}
}
return React.createElement(this.props.tagName || 'div', Object.assign({}, this.props, {
className: classes.join(' ')
}), this.props.children);
}
}
Col.propTypes = {
xs: ModificatorType,
sm: ModificatorType,
md: ModificatorType,
lg: ModificatorType,
xsOffset: PropTypes.number,
smOffset: PropTypes.number,
mdOffset: PropTypes.number,
lgOffset: PropTypes.number,
reverse: PropTypes.bool,
className: PropTypes.string,
tagName: PropTypes.string,
children: PropTypes.node
};