UNPKG

@coreui/react

Version:

UI Components Library for React.js

65 lines (61 loc) 4.43 kB
'use strict'; var tslib_es6 = require('../../node_modules/tslib/tslib.es6.js'); var React = require('react'); var PropTypes = require('prop-types'); var index = require('../../_virtual/index.js'); var CFormControlValidation = require('./CFormControlValidation.js'); var CFormLabel = require('./CFormLabel.js'); var useForkedRef = require('../../hooks/useForkedRef.js'); require('@popperjs/core'); var CFormCheck = React.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 = tslib_es6.__rest(_a, ["className", "button", "feedback", "feedbackInvalid", "feedbackValid", "floatingLabel", "tooltipFeedback", "hitArea", "id", "indeterminate", "inline", "invalid", "label", "reverse", "type", "valid"]); var inputRef = React.useRef(null); var forkedRef = useForkedRef.useForkedRef(ref, inputRef); React.useEffect(function () { if (inputRef.current && indeterminate) { inputRef.current.indeterminate = indeterminate; } }, [indeterminate, inputRef.current]); var FormControl = function () { return (React.createElement("input", tslib_es6.__assign({ type: type, className: index.default(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.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.CFormLabel, tslib_es6.__assign({ customClassName: index.default(button ? index.default('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.CFormLabel, tslib_es6.__assign({ customClassName: index.default('form-check-label stretched-link', className) }, (id && { htmlFor: id })), label), React.createElement(FormValidation, null))) : (React.createElement("div", { className: index.default('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 = tslib_es6.__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.CFormControlValidation.propTypes); CFormCheck.displayName = 'CFormCheck'; exports.CFormCheck = CFormCheck; //# sourceMappingURL=CFormCheck.js.map