@coreui/react-pro
Version:
UI Components Library for React.js
62 lines (58 loc) • 4.01 kB
JavaScript
'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');
require('@popperjs/core');
var useForkedRef = require('../../hooks/useForkedRef.js');
const CFormCheck = React.forwardRef((_a, ref) => {
var { className, button, feedback, feedbackInvalid, feedbackValid, floatingLabel, tooltipFeedback, hitArea, id, indeterminate, inline, invalid, label, reverse, type = 'checkbox', valid } = _a, rest = tslib_es6.__rest(_a, ["className", "button", "feedback", "feedbackInvalid", "feedbackValid", "floatingLabel", "tooltipFeedback", "hitArea", "id", "indeterminate", "inline", "invalid", "label", "reverse", "type", "valid"]);
const inputRef = React.useRef(null);
const forkedRef = useForkedRef.useForkedRef(ref, inputRef);
React.useEffect(() => {
if (inputRef.current && indeterminate) {
inputRef.current.indeterminate = indeterminate;
}
}, [indeterminate, inputRef.current]);
const FormControl = () => (React.createElement("input", Object.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 })));
const FormValidation = () => (React.createElement(CFormControlValidation.CFormControlValidation, { describedby: rest['aria-describedby'], feedback: feedback, feedbackInvalid: feedbackInvalid, feedbackValid: feedbackValid, floatingLabel: floatingLabel, invalid: invalid, tooltipFeedback: tooltipFeedback, valid: valid }));
const FormLabel = () => (React.createElement(CFormLabel.CFormLabel, Object.assign({ customClassName: index.default(button
? index.default('btn', button.variant ? `btn-${button.variant}-${button.color}` : `btn-${button.color}`, {
[`btn-${button.size}`]: button.size,
}, `${button.shape}`)
: 'form-check-label') }, (id && { htmlFor: id })), label));
const FormCheck = () => {
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, Object.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 = Object.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