UNPKG

@coreui/react-pro

Version:

UI Components Library for React.js

60 lines (57 loc) 3.89 kB
import { __rest } 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 '@popperjs/core'; import { useForkedRef } from '../../hooks/useForkedRef.js'; const CFormCheck = forwardRef((_a, ref) => { var { className, button, feedback, feedbackInvalid, feedbackValid, floatingLabel, tooltipFeedback, hitArea, id, indeterminate, inline, invalid, label, reverse, type = 'checkbox', valid } = _a, rest = __rest(_a, ["className", "button", "feedback", "feedbackInvalid", "feedbackValid", "floatingLabel", "tooltipFeedback", "hitArea", "id", "indeterminate", "inline", "invalid", "label", "reverse", "type", "valid"]); const inputRef = useRef(null); const forkedRef = useForkedRef(ref, inputRef); useEffect(() => { if (inputRef.current && indeterminate) { inputRef.current.indeterminate = indeterminate; } }, [indeterminate, inputRef.current]); const FormControl = () => (React.createElement("input", Object.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 }))); const FormValidation = () => (React.createElement(CFormControlValidation, { describedby: rest['aria-describedby'], feedback: feedback, feedbackInvalid: feedbackInvalid, feedbackValid: feedbackValid, floatingLabel: floatingLabel, invalid: invalid, tooltipFeedback: tooltipFeedback, valid: valid })); const FormLabel = () => (React.createElement(CFormLabel, Object.assign({ customClassName: classNames(button ? classNames('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, Object.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 = 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.propTypes); CFormCheck.displayName = 'CFormCheck'; export { CFormCheck }; //# sourceMappingURL=CFormCheck.js.map