1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | var _react = _interopRequireDefault(require("react"));
|
8 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
9 | var _classnames = _interopRequireDefault(require("classnames"));
|
10 | var _utils = require("./utils");
|
11 | const _excluded = ["className", "cssModule", "hidden", "widths", "tag", "check", "size", "for"];
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 | 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); }
|
14 | 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; }
|
15 | 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; }
|
16 | const colWidths = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
|
17 | const stringOrNumberProp = _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]);
|
18 | const columnProps = _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string, _propTypes.default.number, _propTypes.default.shape({
|
19 | size: stringOrNumberProp,
|
20 | order: stringOrNumberProp,
|
21 | offset: stringOrNumberProp
|
22 | })]);
|
23 | const propTypes = {
|
24 | children: _propTypes.default.node,
|
25 | hidden: _propTypes.default.bool,
|
26 | check: _propTypes.default.bool,
|
27 | size: _propTypes.default.string,
|
28 | for: _propTypes.default.string,
|
29 | tag: _utils.tagPropType,
|
30 | className: _propTypes.default.string,
|
31 | cssModule: _propTypes.default.object,
|
32 | xs: columnProps,
|
33 | sm: columnProps,
|
34 | md: columnProps,
|
35 | lg: columnProps,
|
36 | xl: columnProps,
|
37 | xxl: columnProps,
|
38 | widths: _propTypes.default.array
|
39 | };
|
40 | const getColumnSizeClass = (isXs, colWidth, colSize) => {
|
41 | if (colSize === true || colSize === '') {
|
42 | return isXs ? 'col' : `col-${colWidth}`;
|
43 | }
|
44 | if (colSize === 'auto') {
|
45 | return isXs ? 'col-auto' : `col-${colWidth}-auto`;
|
46 | }
|
47 | return isXs ? `col-${colSize}` : `col-${colWidth}-${colSize}`;
|
48 | };
|
49 | function Label(props) {
|
50 | const {
|
51 | className,
|
52 | cssModule,
|
53 | hidden,
|
54 | widths = colWidths,
|
55 | tag: Tag = 'label',
|
56 | check,
|
57 | size,
|
58 | for: htmlFor
|
59 | } = props,
|
60 | attributes = _objectWithoutProperties(props, _excluded);
|
61 | const colClasses = [];
|
62 | widths.forEach((colWidth, i) => {
|
63 | let columnProp = props[colWidth];
|
64 | delete attributes[colWidth];
|
65 | if (!columnProp && columnProp !== '') {
|
66 | return;
|
67 | }
|
68 | const isXs = !i;
|
69 | let colClass;
|
70 | if ((0, _utils.isObject)(columnProp)) {
|
71 | const colSizeInterfix = isXs ? '-' : `-${colWidth}-`;
|
72 | colClass = getColumnSizeClass(isXs, colWidth, columnProp.size);
|
73 | colClasses.push((0, _utils.mapToCssModules)((0, _classnames.default)({
|
74 | [colClass]: columnProp.size || columnProp.size === '',
|
75 | [`order${colSizeInterfix}${columnProp.order}`]: columnProp.order || columnProp.order === 0,
|
76 | [`offset${colSizeInterfix}${columnProp.offset}`]: columnProp.offset || columnProp.offset === 0
|
77 | })), cssModule);
|
78 | } else {
|
79 | colClass = getColumnSizeClass(isXs, colWidth, columnProp);
|
80 | colClasses.push(colClass);
|
81 | }
|
82 | });
|
83 | const colFormLabel = size || colClasses.length;
|
84 | const formLabel = !(check || colFormLabel);
|
85 | const classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, hidden ? 'visually-hidden' : false, check ? 'form-check-label' : false, size ? `col-form-label-${size}` : false, colClasses, colFormLabel ? 'col-form-label' : false, formLabel ? 'form-label' : false), cssModule);
|
86 | return _react.default.createElement(Tag, _extends({
|
87 | htmlFor: htmlFor
|
88 | }, attributes, {
|
89 | className: classes
|
90 | }));
|
91 | }
|
92 | Label.propTypes = propTypes;
|
93 | var _default = Label;
|
94 | exports.default = _default; |
\ | No newline at end of file |