@coreui/react
Version:
UI Components Library for React.js
63 lines (60 loc) • 4.28 kB
JavaScript
import { __rest, __assign } from '../../node_modules/tslib/tslib.es6.js';
import React, { forwardRef, useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import classNames from '../../_virtual/index.js';
import { CFormControlValidation } from './CFormControlValidation.js';
import { CFormLabel } from './CFormLabel.js';
import { useForkedRef } from '../../hooks/useForkedRef.js';
import '@popperjs/core';
var CFormCheck = forwardRef(function (_a, ref) {
var className = _a.className, button = _a.button, feedback = _a.feedback, feedbackInvalid = _a.feedbackInvalid, feedbackValid = _a.feedbackValid, floatingLabel = _a.floatingLabel, tooltipFeedback = _a.tooltipFeedback, hitArea = _a.hitArea, id = _a.id, indeterminate = _a.indeterminate, inline = _a.inline, invalid = _a.invalid, label = _a.label, reverse = _a.reverse, _b = _a.type, type = _b === void 0 ? 'checkbox' : _b, valid = _a.valid, rest = __rest(_a, ["className", "button", "feedback", "feedbackInvalid", "feedbackValid", "floatingLabel", "tooltipFeedback", "hitArea", "id", "indeterminate", "inline", "invalid", "label", "reverse", "type", "valid"]);
var inputRef = useRef(null);
var forkedRef = useForkedRef(ref, inputRef);
useEffect(function () {
if (inputRef.current && indeterminate) {
inputRef.current.indeterminate = indeterminate;
}
}, [indeterminate, inputRef.current]);
var FormControl = function () { return (React.createElement("input", __assign({ type: type, className: classNames(button ? 'btn-check' : 'form-check-input', {
'is-invalid': invalid,
'is-valid': valid,
'me-2': hitArea,
}), id: id }, rest, { ref: forkedRef }))); };
var FormValidation = function () { return (React.createElement(CFormControlValidation, { describedby: rest['aria-describedby'], feedback: feedback, feedbackInvalid: feedbackInvalid, feedbackValid: feedbackValid, floatingLabel: floatingLabel, invalid: invalid, tooltipFeedback: tooltipFeedback, valid: valid })); };
var FormLabel = function () {
var _a;
return (React.createElement(CFormLabel, __assign({ customClassName: classNames(button
? classNames('btn', button.variant ? "btn-".concat(button.variant, "-").concat(button.color) : "btn-".concat(button.color), (_a = {},
_a["btn-".concat(button.size)] = button.size,
_a), "".concat(button.shape))
: 'form-check-label') }, (id && { htmlFor: id })), label));
};
var FormCheck = function () {
if (button) {
return (React.createElement(React.Fragment, null,
React.createElement(FormControl, null),
label && React.createElement(FormLabel, null),
React.createElement(FormValidation, null)));
}
if (label) {
return hitArea ? (React.createElement(React.Fragment, null,
React.createElement(FormControl, null),
React.createElement(CFormLabel, __assign({ customClassName: classNames('form-check-label stretched-link', className) }, (id && { htmlFor: id })), label),
React.createElement(FormValidation, null))) : (React.createElement("div", { className: classNames('form-check', {
'form-check-inline': inline,
'form-check-reverse': reverse,
'is-invalid': invalid,
'is-valid': valid,
}, className) },
React.createElement(FormControl, null),
React.createElement(FormLabel, null),
React.createElement(FormValidation, null)));
}
return React.createElement(FormControl, null);
};
return React.createElement(FormCheck, null);
});
CFormCheck.propTypes = __assign({ button: PropTypes.object, className: PropTypes.string, hitArea: PropTypes.oneOf(['full']), id: PropTypes.string, indeterminate: PropTypes.bool, inline: PropTypes.bool, label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), reverse: PropTypes.bool, type: PropTypes.oneOf(['checkbox', 'radio']) }, CFormControlValidation.propTypes);
CFormCheck.displayName = 'CFormCheck';
export { CFormCheck };
//# sourceMappingURL=CFormCheck.js.map