1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import classNames from 'classnames';
|
7 | import React from 'react';
|
8 | import PropTypes from 'prop-types';
|
9 | import elementType from 'prop-types-extra/lib/elementType';
|
10 |
|
11 | import { bsClass, prefix, splitBsProps } from './utils/bootstrapUtils';
|
12 | import { DEVICE_SIZES } from './utils/StyleConfig';
|
13 |
|
14 | var propTypes = {
|
15 | componentClass: elementType,
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | xs: PropTypes.number,
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | sm: PropTypes.number,
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | md: PropTypes.number,
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | lg: PropTypes.number,
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | xsHidden: PropTypes.bool,
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | smHidden: PropTypes.bool,
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | mdHidden: PropTypes.bool,
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | lgHidden: PropTypes.bool,
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | xsOffset: PropTypes.number,
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | smOffset: PropTypes.number,
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | mdOffset: PropTypes.number,
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | lgOffset: PropTypes.number,
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | xsPush: PropTypes.number,
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | smPush: PropTypes.number,
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | mdPush: PropTypes.number,
|
137 | |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | lgPush: PropTypes.number,
|
145 | |
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | xsPull: PropTypes.number,
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | smPull: PropTypes.number,
|
161 | |
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | mdPull: PropTypes.number,
|
169 | |
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | lgPull: PropTypes.number
|
177 | };
|
178 |
|
179 | var defaultProps = {
|
180 | componentClass: 'div'
|
181 | };
|
182 |
|
183 | var 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 |
|
234 | Col.propTypes = propTypes;
|
235 | Col.defaultProps = defaultProps;
|
236 |
|
237 | export default bsClass('col', Col); |
\ | No newline at end of file |