UNPKG

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