Gazebo_simulation-Frontend/node_modules/react-bootstrap/esm/FormCheck.js
2020-12-21 10:29:31 -05:00

76 lines
2.8 KiB
JavaScript

import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import classNames from 'classnames';
import all from 'prop-types-extra/lib/all';
import React, { useContext, useMemo } from 'react';
import Feedback from './Feedback';
import FormCheckInput from './FormCheckInput';
import FormCheckLabel from './FormCheckLabel';
import FormContext from './FormContext';
import { useBootstrapPrefix } from './ThemeProvider';
var defaultProps = {
type: 'checkbox',
inline: false,
disabled: false,
isValid: false,
isInvalid: false,
title: ''
};
var FormCheck = React.forwardRef(function (_ref, ref) {
var id = _ref.id,
bsPrefix = _ref.bsPrefix,
bsCustomPrefix = _ref.bsCustomPrefix,
inline = _ref.inline,
disabled = _ref.disabled,
isValid = _ref.isValid,
isInvalid = _ref.isInvalid,
feedback = _ref.feedback,
className = _ref.className,
style = _ref.style,
title = _ref.title,
type = _ref.type,
label = _ref.label,
children = _ref.children,
propCustom = _ref.custom,
_ref$as = _ref.as,
as = _ref$as === void 0 ? 'input' : _ref$as,
props = _objectWithoutPropertiesLoose(_ref, ["id", "bsPrefix", "bsCustomPrefix", "inline", "disabled", "isValid", "isInvalid", "feedback", "className", "style", "title", "type", "label", "children", "custom", "as"]);
var custom = type === 'switch' ? true : propCustom;
bsPrefix = custom ? useBootstrapPrefix(bsCustomPrefix, 'custom-control') : useBootstrapPrefix(bsPrefix, 'form-check');
var _useContext = useContext(FormContext),
controlId = _useContext.controlId;
var innerFormContext = useMemo(function () {
return {
controlId: id || controlId,
custom: custom
};
}, [controlId, custom, id]);
var hasLabel = label != null && label !== false && !children;
var input = React.createElement(FormCheckInput, _extends({}, props, {
type: type === 'switch' ? 'checkbox' : type,
ref: ref,
isValid: isValid,
isInvalid: isInvalid,
isStatic: !hasLabel,
disabled: disabled,
as: as
}));
return React.createElement(FormContext.Provider, {
value: innerFormContext
}, React.createElement("div", {
style: style,
className: classNames(className, bsPrefix, custom && "custom-" + type, inline && bsPrefix + "-inline")
}, children || React.createElement(React.Fragment, null, input, hasLabel && React.createElement(FormCheckLabel, {
title: title
}, label), (isValid || isInvalid) && React.createElement(Feedback, {
type: isValid ? 'valid' : 'invalid'
}, feedback))));
});
FormCheck.displayName = 'FormCheck';
FormCheck.defaultProps = defaultProps;
FormCheck.Input = FormCheckInput;
FormCheck.Label = FormCheckLabel;
export default FormCheck;