UNPKG

1.78 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import classNames from 'classnames';
4import React, { useContext } from 'react';
5import FormContext from './FormContext';
6import { useBootstrapPrefix } from './ThemeProvider';
7var FormCheckInput = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
8 var id = _ref.id,
9 bsPrefix = _ref.bsPrefix,
10 bsCustomPrefix = _ref.bsCustomPrefix,
11 className = _ref.className,
12 _ref$type = _ref.type,
13 type = _ref$type === void 0 ? 'checkbox' : _ref$type,
14 _ref$isValid = _ref.isValid,
15 isValid = _ref$isValid === void 0 ? false : _ref$isValid,
16 _ref$isInvalid = _ref.isInvalid,
17 isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
18 isStatic = _ref.isStatic,
19 _ref$as = _ref.as,
20 Component = _ref$as === void 0 ? 'input' : _ref$as,
21 props = _objectWithoutPropertiesLoose(_ref, ["id", "bsPrefix", "bsCustomPrefix", "className", "type", "isValid", "isInvalid", "isStatic", "as"]);
22
23 var _useContext = useContext(FormContext),
24 controlId = _useContext.controlId,
25 custom = _useContext.custom;
26
27 var _ref2 = custom ? [bsCustomPrefix, 'custom-control-input'] : [bsPrefix, 'form-check-input'],
28 prefix = _ref2[0],
29 defaultPrefix = _ref2[1];
30
31 bsPrefix = useBootstrapPrefix(prefix, defaultPrefix);
32 return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
33 ref: ref,
34 type: type,
35 id: id || controlId,
36 className: classNames(className, bsPrefix, isValid && 'is-valid', isInvalid && 'is-invalid', isStatic && 'position-static')
37 }));
38});
39FormCheckInput.displayName = 'FormCheckInput';
40export default FormCheckInput;
\No newline at end of file