UNPKG

react-bootstrap-v5

Version:

Bootstrap 4 components built with React

55 lines (49 loc) 2.17 kB
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 warning from 'warning'; import Feedback from './Feedback'; import FormContext from './FormContext'; import { useBootstrapPrefix } from './ThemeProvider'; var FormControl = React.forwardRef(function (_ref, ref) { var bsPrefix = _ref.bsPrefix, type = _ref.type, size = _ref.size, htmlSize = _ref.htmlSize, id = _ref.id, className = _ref.className, _ref$isValid = _ref.isValid, isValid = _ref$isValid === void 0 ? false : _ref$isValid, _ref$isInvalid = _ref.isInvalid, isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid, plaintext = _ref.plaintext, readOnly = _ref.readOnly, _ref$as = _ref.as, Component = _ref$as === void 0 ? 'input' : _ref$as, props = _objectWithoutPropertiesLoose(_ref, ["bsPrefix", "type", "size", "htmlSize", "id", "className", "isValid", "isInvalid", "plaintext", "readOnly", "as"]); var _useContext = useContext(FormContext), controlId = _useContext.controlId; bsPrefix = useBootstrapPrefix(bsPrefix, 'form-control'); var classes; if (plaintext) { var _classes; classes = (_classes = {}, _classes[bsPrefix + "-plaintext"] = true, _classes); } else { var _classes2; classes = (_classes2 = {}, _classes2[bsPrefix] = true, _classes2[bsPrefix + "-" + size] = size, _classes2); } process.env.NODE_ENV !== "production" ? warning(controlId == null || !id, '`controlId` is ignored on `<FormControl>` when `id` is specified.') : void 0; return /*#__PURE__*/React.createElement(Component, _extends({}, props, { type: type, size: htmlSize, ref: ref, readOnly: readOnly, id: id || controlId, className: classNames(className, classes, isValid && "is-valid", isInvalid && "is-invalid", type === 'color' && bsPrefix + "-color") })); }); FormControl.displayName = 'FormControl'; export default Object.assign(FormControl, { Feedback: Feedback });