GoScrobble/web/node_modules/reactstrap/lib/Col.js

99 lines
3.3 KiB
JavaScript

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _utils = require("./utils");
var colWidths = ['xs', 'sm', 'md', 'lg', 'xl'];
var stringOrNumberProp = _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]);
var columnProps = _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.number, _propTypes.default.string, _propTypes.default.shape({
size: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.number, _propTypes.default.string]),
order: stringOrNumberProp,
offset: stringOrNumberProp
})]);
var propTypes = {
tag: _utils.tagPropType,
xs: columnProps,
sm: columnProps,
md: columnProps,
lg: columnProps,
xl: columnProps,
className: _propTypes.default.string,
cssModule: _propTypes.default.object,
widths: _propTypes.default.array
};
var defaultProps = {
tag: 'div',
widths: colWidths
};
var getColumnSizeClass = function getColumnSizeClass(isXs, colWidth, colSize) {
if (colSize === true || colSize === '') {
return isXs ? 'col' : "col-" + colWidth;
} else if (colSize === 'auto') {
return isXs ? 'col-auto' : "col-" + colWidth + "-auto";
}
return isXs ? "col-" + colSize : "col-" + colWidth + "-" + colSize;
};
var Col = function Col(props) {
var className = props.className,
cssModule = props.cssModule,
widths = props.widths,
Tag = props.tag,
attributes = (0, _objectWithoutPropertiesLoose2.default)(props, ["className", "cssModule", "widths", "tag"]);
var colClasses = [];
widths.forEach(function (colWidth, i) {
var columnProp = props[colWidth];
delete attributes[colWidth];
if (!columnProp && columnProp !== '') {
return;
}
var isXs = !i;
if ((0, _utils.isObject)(columnProp)) {
var _classNames;
var colSizeInterfix = isXs ? '-' : "-" + colWidth + "-";
var colClass = getColumnSizeClass(isXs, colWidth, columnProp.size);
colClasses.push((0, _utils.mapToCssModules)((0, _classnames.default)((_classNames = {}, _classNames[colClass] = columnProp.size || columnProp.size === '', _classNames["order" + colSizeInterfix + columnProp.order] = columnProp.order || columnProp.order === 0, _classNames["offset" + colSizeInterfix + columnProp.offset] = columnProp.offset || columnProp.offset === 0, _classNames)), cssModule));
} else {
var _colClass = getColumnSizeClass(isXs, colWidth, columnProp);
colClasses.push(_colClass);
}
});
if (!colClasses.length) {
colClasses.push('col');
}
var classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, colClasses), cssModule);
return /*#__PURE__*/_react.default.createElement(Tag, (0, _extends2.default)({}, attributes, {
className: classes
}));
};
Col.propTypes = propTypes;
Col.defaultProps = defaultProps;
var _default = Col;
exports.default = _default;