UNPKG

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