forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcol.jsx
More file actions
78 lines (59 loc) · 1.4 KB
/
col.jsx
File metadata and controls
78 lines (59 loc) · 1.4 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* MUI React Col Component
* @module react/col
*/
'use strict';
import React from 'react';
import * as util from '../js/lib/util';
const breakpoints = ['xs', 'sm', 'md', 'lg', 'xl'];
/**
* Col constructor
* @class
*/
class Col extends React.Component {
defaultProps() {
let props = {className: ''},
i,
v;
// add {breakpoint}, {breakpoint}-offset to props
for (i=breakpoints.length - 1; i > -1; i--) {
v = breakpoints[i];
props[v] = null;
props[v + '-offset'] = null;
}
return props;
}
render() {
let cls = {},
i,
bk,
val,
baseCls;
let { children, className, ...reactProps } = this.props;
// add mui-col classes
for (i=breakpoints.length - 1; i > -1; i--) {
bk = breakpoints[i];
baseCls = 'mui-col-' + bk;
// add mui-col-{bk}-{val}
val = this.props[bk];
if (val) cls[baseCls + '-' + val] = true;
// add mui-col-{bk}-offset-{val}
val = this.props[bk + '-offset'];
if (val) cls[baseCls + '-offset-' + val] = true;
// remove from reactProps
delete reactProps[bk];
delete reactProps[bk + '-offset'];
}
cls = util.classNames(cls);
return (
<div
{ ...reactProps }
className={cls + ' ' + className }
>
{children}
</div>
);
}
}
/** Define module API */
export default Col;