react-bootstrap-v5
Version:
Bootstrap 4 components built with React
33 lines (31 loc) • 1.45 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import classNames from 'classnames';
import React, { useContext } from 'react';
import FormContext from './FormContext';
import { useBootstrapPrefix } from './ThemeProvider';
var FormCheckInput = React.forwardRef(function (_ref, ref) {
var id = _ref.id,
bsPrefix = _ref.bsPrefix,
className = _ref.className,
_ref$type = _ref.type,
type = _ref$type === void 0 ? 'checkbox' : _ref$type,
_ref$isValid = _ref.isValid,
isValid = _ref$isValid === void 0 ? false : _ref$isValid,
_ref$isInvalid = _ref.isInvalid,
isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
_ref$as = _ref.as,
Component = _ref$as === void 0 ? 'input' : _ref$as,
props = _objectWithoutPropertiesLoose(_ref, ["id", "bsPrefix", "className", "type", "isValid", "isInvalid", "as"]);
var _useContext = useContext(FormContext),
controlId = _useContext.controlId;
bsPrefix = useBootstrapPrefix(bsPrefix, 'form-check-input');
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
ref: ref,
type: type,
id: id || controlId,
className: classNames(className, bsPrefix, isValid && 'is-valid', isInvalid && 'is-invalid')
}));
});
FormCheckInput.displayName = 'FormCheckInput';
export default FormCheckInput;