1 | var _excluded = ["className", "cssModule", "hidden", "widths", "tag", "check", "size", "for"];
|
2 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
3 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
4 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
5 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
6 | import React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import classNames from 'classnames';
|
9 | import { mapToCssModules, tagPropType, isObject } from './utils';
|
10 | var colWidths = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
|
11 | var stringOrNumberProp = PropTypes.oneOfType([PropTypes.number, PropTypes.string]);
|
12 | var columnProps = PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.number, PropTypes.shape({
|
13 | size: stringOrNumberProp,
|
14 | order: stringOrNumberProp,
|
15 | offset: stringOrNumberProp
|
16 | })]);
|
17 | var propTypes = {
|
18 | children: PropTypes.node,
|
19 | hidden: PropTypes.bool,
|
20 | check: PropTypes.bool,
|
21 | size: PropTypes.string,
|
22 | "for": PropTypes.string,
|
23 | tag: tagPropType,
|
24 | className: PropTypes.string,
|
25 | cssModule: PropTypes.object,
|
26 | xs: columnProps,
|
27 | sm: columnProps,
|
28 | md: columnProps,
|
29 | lg: columnProps,
|
30 | xl: columnProps,
|
31 | xxl: columnProps,
|
32 | widths: PropTypes.array
|
33 | };
|
34 | var getColumnSizeClass = function getColumnSizeClass(isXs, colWidth, colSize) {
|
35 | if (colSize === true || colSize === '') {
|
36 | return isXs ? 'col' : "col-".concat(colWidth);
|
37 | }
|
38 | if (colSize === 'auto') {
|
39 | return isXs ? 'col-auto' : "col-".concat(colWidth, "-auto");
|
40 | }
|
41 | return isXs ? "col-".concat(colSize) : "col-".concat(colWidth, "-").concat(colSize);
|
42 | };
|
43 | function Label(props) {
|
44 | var className = props.className,
|
45 | cssModule = props.cssModule,
|
46 | hidden = props.hidden,
|
47 | _props$widths = props.widths,
|
48 | widths = _props$widths === void 0 ? colWidths : _props$widths,
|
49 | _props$tag = props.tag,
|
50 | Tag = _props$tag === void 0 ? 'label' : _props$tag,
|
51 | check = props.check,
|
52 | size = props.size,
|
53 | htmlFor = props["for"],
|
54 | attributes = _objectWithoutProperties(props, _excluded);
|
55 | var colClasses = [];
|
56 | widths.forEach(function (colWidth, i) {
|
57 | var columnProp = props[colWidth];
|
58 | delete attributes[colWidth];
|
59 | if (!columnProp && columnProp !== '') {
|
60 | return;
|
61 | }
|
62 | var isXs = !i;
|
63 | var colClass;
|
64 | if (isObject(columnProp)) {
|
65 | var _classNames;
|
66 | var colSizeInterfix = isXs ? '-' : "-".concat(colWidth, "-");
|
67 | colClass = getColumnSizeClass(isXs, colWidth, columnProp.size);
|
68 | colClasses.push(mapToCssModules(classNames((_classNames = {}, _defineProperty(_classNames, colClass, columnProp.size || columnProp.size === ''), _defineProperty(_classNames, "order".concat(colSizeInterfix).concat(columnProp.order), columnProp.order || columnProp.order === 0), _defineProperty(_classNames, "offset".concat(colSizeInterfix).concat(columnProp.offset), columnProp.offset || columnProp.offset === 0), _classNames))), cssModule);
|
69 | } else {
|
70 | colClass = getColumnSizeClass(isXs, colWidth, columnProp);
|
71 | colClasses.push(colClass);
|
72 | }
|
73 | });
|
74 | var colFormLabel = size || colClasses.length;
|
75 | var formLabel = !(check || colFormLabel);
|
76 | var classes = mapToCssModules(classNames(className, hidden ? 'visually-hidden' : false, check ? 'form-check-label' : false, size ? "col-form-label-".concat(size) : false, colClasses, colFormLabel ? 'col-form-label' : false, formLabel ? 'form-label' : false), cssModule);
|
77 | return React.createElement(Tag, _extends({
|
78 | htmlFor: htmlFor
|
79 | }, attributes, {
|
80 | className: classes
|
81 | }));
|
82 | }
|
83 | Label.propTypes = propTypes;
|
84 | export default Label; |
\ | No newline at end of file |