1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | var _excluded = ["id", "bsPrefix", "bsCustomPrefix", "inline", "disabled", "isValid", "isInvalid", "feedbackTooltip", "feedback", "className", "style", "title", "type", "label", "children", "custom", "as"];
|
4 | import classNames from 'classnames';
|
5 | import all from 'prop-types-extra/lib/all';
|
6 | import React, { useContext, useMemo } from 'react';
|
7 | import Feedback from './Feedback';
|
8 | import FormCheckInput from './FormCheckInput';
|
9 | import FormCheckLabel from './FormCheckLabel';
|
10 | import FormContext from './FormContext';
|
11 | import { useBootstrapPrefix } from './ThemeProvider';
|
12 | var FormCheck = React.forwardRef(function (_ref, ref) {
|
13 | var id = _ref.id,
|
14 | bsPrefix = _ref.bsPrefix,
|
15 | bsCustomPrefix = _ref.bsCustomPrefix,
|
16 | _ref$inline = _ref.inline,
|
17 | inline = _ref$inline === void 0 ? false : _ref$inline,
|
18 | _ref$disabled = _ref.disabled,
|
19 | disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
20 | _ref$isValid = _ref.isValid,
|
21 | isValid = _ref$isValid === void 0 ? false : _ref$isValid,
|
22 | _ref$isInvalid = _ref.isInvalid,
|
23 | isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
|
24 | _ref$feedbackTooltip = _ref.feedbackTooltip,
|
25 | feedbackTooltip = _ref$feedbackTooltip === void 0 ? false : _ref$feedbackTooltip,
|
26 | feedback = _ref.feedback,
|
27 | className = _ref.className,
|
28 | style = _ref.style,
|
29 | _ref$title = _ref.title,
|
30 | title = _ref$title === void 0 ? '' : _ref$title,
|
31 | _ref$type = _ref.type,
|
32 | type = _ref$type === void 0 ? 'checkbox' : _ref$type,
|
33 | label = _ref.label,
|
34 | children = _ref.children,
|
35 | propCustom = _ref.custom,
|
36 | _ref$as = _ref.as,
|
37 | as = _ref$as === void 0 ? 'input' : _ref$as,
|
38 | props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
39 |
|
40 | var custom = type === 'switch' ? true : propCustom;
|
41 |
|
42 | var _ref2 = custom ? [bsCustomPrefix, 'custom-control'] : [bsPrefix, 'form-check'],
|
43 | prefix = _ref2[0],
|
44 | defaultPrefix = _ref2[1];
|
45 |
|
46 | bsPrefix = useBootstrapPrefix(prefix, defaultPrefix);
|
47 |
|
48 | var _useContext = useContext(FormContext),
|
49 | controlId = _useContext.controlId;
|
50 |
|
51 | var innerFormContext = useMemo(function () {
|
52 | return {
|
53 | controlId: id || controlId,
|
54 | custom: custom
|
55 | };
|
56 | }, [controlId, custom, id]);
|
57 | var hasLabel = custom || label != null && label !== false && !children;
|
58 | var input = React.createElement(FormCheckInput, _extends({}, props, {
|
59 | type: type === 'switch' ? 'checkbox' : type,
|
60 | ref: ref,
|
61 | isValid: isValid,
|
62 | isInvalid: isInvalid,
|
63 | isStatic: !hasLabel,
|
64 | disabled: disabled,
|
65 | as: as
|
66 | }));
|
67 | return React.createElement(FormContext.Provider, {
|
68 | value: innerFormContext
|
69 | }, React.createElement("div", {
|
70 | style: style,
|
71 | className: classNames(className, bsPrefix, custom && "custom-" + type, inline && bsPrefix + "-inline")
|
72 | }, children || React.createElement(React.Fragment, null, input, hasLabel && React.createElement(FormCheckLabel, {
|
73 | title: title
|
74 | }, label), (isValid || isInvalid) && React.createElement(Feedback, {
|
75 | type: isValid ? 'valid' : 'invalid',
|
76 | tooltip: feedbackTooltip
|
77 | }, feedback))));
|
78 | });
|
79 | FormCheck.displayName = 'FormCheck';
|
80 | FormCheck.Input = FormCheckInput;
|
81 | FormCheck.Label = FormCheckLabel;
|
82 | export default FormCheck; |
\ | No newline at end of file |