You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
2.6 KiB

  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import classNames from 'classnames';
  4. import all from 'prop-types-extra/lib/all';
  5. import React, { useContext } from 'react';
  6. import warning from 'warning';
  7. import Feedback from './Feedback';
  8. import FormContext from './FormContext';
  9. import { useBootstrapPrefix } from './ThemeProvider';
  10. var FormControl = React.forwardRef(function (_ref, ref) {
  11. var bsPrefix = _ref.bsPrefix,
  12. bsCustomPrefix = _ref.bsCustomPrefix,
  13. type = _ref.type,
  14. size = _ref.size,
  15. id = _ref.id,
  16. className = _ref.className,
  17. isValid = _ref.isValid,
  18. isInvalid = _ref.isInvalid,
  19. plaintext = _ref.plaintext,
  20. readOnly = _ref.readOnly,
  21. custom = _ref.custom,
  22. _ref$as = _ref.as,
  23. Component = _ref$as === void 0 ? 'input' : _ref$as,
  24. props = _objectWithoutPropertiesLoose(_ref, ["bsPrefix", "bsCustomPrefix", "type", "size", "id", "className", "isValid", "isInvalid", "plaintext", "readOnly", "custom", "as"]);
  25. var _useContext = useContext(FormContext),
  26. controlId = _useContext.controlId;
  27. var _ref2 = custom ? [bsCustomPrefix, 'custom'] : [bsPrefix, 'form-control'],
  28. prefix = _ref2[0],
  29. defaultPrefix = _ref2[1];
  30. bsPrefix = useBootstrapPrefix(prefix, defaultPrefix);
  31. var classes;
  32. if (plaintext) {
  33. var _classes;
  34. classes = (_classes = {}, _classes[bsPrefix + "-plaintext"] = true, _classes);
  35. } else if (type === 'file') {
  36. var _classes2;
  37. classes = (_classes2 = {}, _classes2[bsPrefix + "-file"] = true, _classes2);
  38. } else if (type === 'range') {
  39. var _classes3;
  40. classes = (_classes3 = {}, _classes3[bsPrefix + "-range"] = true, _classes3);
  41. } else if (Component === 'select' && custom) {
  42. var _classes4;
  43. classes = (_classes4 = {}, _classes4[bsPrefix + "-select"] = true, _classes4[bsPrefix + "-select-" + size] = size, _classes4);
  44. } else {
  45. var _classes5;
  46. classes = (_classes5 = {}, _classes5[bsPrefix] = true, _classes5[bsPrefix + "-" + size] = size, _classes5);
  47. }
  48. process.env.NODE_ENV !== "production" ? warning(controlId == null || !id, '`controlId` is ignored on `<FormControl>` when `id` is specified.') : void 0;
  49. return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
  50. type: type,
  51. ref: ref,
  52. readOnly: readOnly,
  53. id: id || controlId,
  54. className: classNames(className, classes, isValid && "is-valid", isInvalid && "is-invalid")
  55. }));
  56. });
  57. FormControl.displayName = 'FormControl';
  58. FormControl.Feedback = Feedback;
  59. export default FormControl;