UNPKG

5.36 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import classNames from 'classnames';
7import React from 'react';
8import PropTypes from 'prop-types';
9import elementType from 'prop-types-extra/lib/elementType';
10
11import { bsClass, prefix, splitBsProps } from './utils/bootstrapUtils';
12import { DEVICE_SIZES } from './utils/StyleConfig';
13
14var propTypes = {
15 componentClass: elementType,
16
17 /**
18 * The number of columns you wish to span
19 *
20 * for Extra small devices Phones (<768px)
21 *
22 * class-prefix `col-xs-`
23 */
24 xs: PropTypes.number,
25 /**
26 * The number of columns you wish to span
27 *
28 * for Small devices Tablets (≥768px)
29 *
30 * class-prefix `col-sm-`
31 */
32 sm: PropTypes.number,
33 /**
34 * The number of columns you wish to span
35 *
36 * for Medium devices Desktops (≥992px)
37 *
38 * class-prefix `col-md-`
39 */
40 md: PropTypes.number,
41 /**
42 * The number of columns you wish to span
43 *
44 * for Large devices Desktops (≥1200px)
45 *
46 * class-prefix `col-lg-`
47 */
48 lg: PropTypes.number,
49 /**
50 * Hide column
51 *
52 * on Extra small devices Phones
53 *
54 * adds class `hidden-xs`
55 */
56 xsHidden: PropTypes.bool,
57 /**
58 * Hide column
59 *
60 * on Small devices Tablets
61 *
62 * adds class `hidden-sm`
63 */
64 smHidden: PropTypes.bool,
65 /**
66 * Hide column
67 *
68 * on Medium devices Desktops
69 *
70 * adds class `hidden-md`
71 */
72 mdHidden: PropTypes.bool,
73 /**
74 * Hide column
75 *
76 * on Large devices Desktops
77 *
78 * adds class `hidden-lg`
79 */
80 lgHidden: PropTypes.bool,
81 /**
82 * Move columns to the right
83 *
84 * for Extra small devices Phones
85 *
86 * class-prefix `col-xs-offset-`
87 */
88 xsOffset: PropTypes.number,
89 /**
90 * Move columns to the right
91 *
92 * for Small devices Tablets
93 *
94 * class-prefix `col-sm-offset-`
95 */
96 smOffset: PropTypes.number,
97 /**
98 * Move columns to the right
99 *
100 * for Medium devices Desktops
101 *
102 * class-prefix `col-md-offset-`
103 */
104 mdOffset: PropTypes.number,
105 /**
106 * Move columns to the right
107 *
108 * for Large devices Desktops
109 *
110 * class-prefix `col-lg-offset-`
111 */
112 lgOffset: PropTypes.number,
113 /**
114 * Change the order of grid columns to the right
115 *
116 * for Extra small devices Phones
117 *
118 * class-prefix `col-xs-push-`
119 */
120 xsPush: PropTypes.number,
121 /**
122 * Change the order of grid columns to the right
123 *
124 * for Small devices Tablets
125 *
126 * class-prefix `col-sm-push-`
127 */
128 smPush: PropTypes.number,
129 /**
130 * Change the order of grid columns to the right
131 *
132 * for Medium devices Desktops
133 *
134 * class-prefix `col-md-push-`
135 */
136 mdPush: PropTypes.number,
137 /**
138 * Change the order of grid columns to the right
139 *
140 * for Large devices Desktops
141 *
142 * class-prefix `col-lg-push-`
143 */
144 lgPush: PropTypes.number,
145 /**
146 * Change the order of grid columns to the left
147 *
148 * for Extra small devices Phones
149 *
150 * class-prefix `col-xs-pull-`
151 */
152 xsPull: PropTypes.number,
153 /**
154 * Change the order of grid columns to the left
155 *
156 * for Small devices Tablets
157 *
158 * class-prefix `col-sm-pull-`
159 */
160 smPull: PropTypes.number,
161 /**
162 * Change the order of grid columns to the left
163 *
164 * for Medium devices Desktops
165 *
166 * class-prefix `col-md-pull-`
167 */
168 mdPull: PropTypes.number,
169 /**
170 * Change the order of grid columns to the left
171 *
172 * for Large devices Desktops
173 *
174 * class-prefix `col-lg-pull-`
175 */
176 lgPull: PropTypes.number
177};
178
179var defaultProps = {
180 componentClass: 'div'
181};
182
183var Col = function (_React$Component) {
184 _inherits(Col, _React$Component);
185
186 function Col() {
187 _classCallCheck(this, Col);
188
189 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
190 }
191
192 Col.prototype.render = function render() {
193 var _props = this.props,
194 Component = _props.componentClass,
195 className = _props.className,
196 props = _objectWithoutProperties(_props, ['componentClass', 'className']);
197
198 var _splitBsProps = splitBsProps(props),
199 bsProps = _splitBsProps[0],
200 elementProps = _splitBsProps[1];
201
202 var classes = [];
203
204 DEVICE_SIZES.forEach(function (size) {
205 function popProp(propSuffix, modifier) {
206 var propName = '' + size + propSuffix;
207 var propValue = elementProps[propName];
208
209 if (propValue != null) {
210 classes.push(prefix(bsProps, '' + size + modifier + '-' + propValue));
211 }
212
213 delete elementProps[propName];
214 }
215
216 popProp('', '');
217 popProp('Offset', '-offset');
218 popProp('Push', '-push');
219 popProp('Pull', '-pull');
220
221 var hiddenPropName = size + 'Hidden';
222 if (elementProps[hiddenPropName]) {
223 classes.push('hidden-' + size);
224 }
225 delete elementProps[hiddenPropName];
226 });
227
228 return React.createElement(Component, _extends({}, elementProps, { className: classNames(className, classes) }));
229 };
230
231 return Col;
232}(React.Component);
233
234Col.propTypes = propTypes;
235Col.defaultProps = defaultProps;
236
237export default bsClass('col', Col);
\No newline at end of file