GoScrobble/web/node_modules/reactstrap/es/Label.js

89 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-04-25 02:47:15 +00:00
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType, isObject } from './utils';
var colWidths = ['xs', 'sm', 'md', 'lg', 'xl'];
var stringOrNumberProp = PropTypes.oneOfType([PropTypes.number, PropTypes.string]);
var columnProps = PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.number, PropTypes.shape({
size: stringOrNumberProp,
order: stringOrNumberProp,
offset: stringOrNumberProp
})]);
var propTypes = {
children: PropTypes.node,
hidden: PropTypes.bool,
check: PropTypes.bool,
size: PropTypes.string,
for: PropTypes.string,
tag: tagPropType,
className: PropTypes.string,
cssModule: PropTypes.object,
xs: columnProps,
sm: columnProps,
md: columnProps,
lg: columnProps,
xl: columnProps,
widths: PropTypes.array
};
var defaultProps = {
tag: 'label',
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 Label = function Label(props) {
var className = props.className,
cssModule = props.cssModule,
hidden = props.hidden,
widths = props.widths,
Tag = props.tag,
check = props.check,
size = props.size,
htmlFor = props.for,
attributes = _objectWithoutPropertiesLoose(props, ["className", "cssModule", "hidden", "widths", "tag", "check", "size", "for"]);
var colClasses = [];
widths.forEach(function (colWidth, i) {
var columnProp = props[colWidth];
delete attributes[colWidth];
if (!columnProp && columnProp !== '') {
return;
}
var isXs = !i;
var colClass;
if (isObject(columnProp)) {
var _classNames;
var colSizeInterfix = isXs ? '-' : "-" + colWidth + "-";
colClass = getColumnSizeClass(isXs, colWidth, columnProp.size);
colClasses.push(mapToCssModules(classNames((_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 {
colClass = getColumnSizeClass(isXs, colWidth, columnProp);
colClasses.push(colClass);
}
});
var classes = mapToCssModules(classNames(className, hidden ? 'sr-only' : false, check ? 'form-check-label' : false, size ? "col-form-label-" + size : false, colClasses, colClasses.length ? 'col-form-label' : false), cssModule);
return /*#__PURE__*/React.createElement(Tag, _extends({
htmlFor: htmlFor
}, attributes, {
className: classes
}));
};
Label.propTypes = propTypes;
Label.defaultProps = defaultProps;
export default Label;