UNPKG

1.92 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3var _excluded = ["bsPrefix", "className", "as"];
4import classNames from 'classnames';
5import React from 'react';
6import { useBootstrapPrefix } from './ThemeProvider';
7var DEVICE_SIZES = ['xl', 'lg', 'md', 'sm', 'xs'];
8var Col = /*#__PURE__*/React.forwardRef( // Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
9function (_ref, ref) {
10 var bsPrefix = _ref.bsPrefix,
11 className = _ref.className,
12 _ref$as = _ref.as,
13 Component = _ref$as === void 0 ? 'div' : _ref$as,
14 props = _objectWithoutPropertiesLoose(_ref, _excluded);
15
16 var prefix = useBootstrapPrefix(bsPrefix, 'col');
17 var spans = [];
18 var classes = [];
19 DEVICE_SIZES.forEach(function (brkPoint) {
20 var propValue = props[brkPoint];
21 delete props[brkPoint];
22 var span;
23 var offset;
24 var order;
25
26 if (typeof propValue === 'object' && propValue != null) {
27 var _propValue$span = propValue.span;
28 span = _propValue$span === void 0 ? true : _propValue$span;
29 offset = propValue.offset;
30 order = propValue.order;
31 } else {
32 span = propValue;
33 }
34
35 var infix = brkPoint !== 'xs' ? "-" + brkPoint : '';
36 if (span) spans.push(span === true ? "" + prefix + infix : "" + prefix + infix + "-" + span);
37 if (order != null) classes.push("order" + infix + "-" + order);
38 if (offset != null) classes.push("offset" + infix + "-" + offset);
39 });
40
41 if (!spans.length) {
42 spans.push(prefix); // plain 'col'
43 }
44
45 return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
46 ref: ref,
47 className: classNames.apply(void 0, [className].concat(spans, classes))
48 }));
49});
50Col.displayName = 'Col';
51export default Col;
\No newline at end of file