UNPKG

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