Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
  4. import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
  5. /* eslint react/prefer-stateless-function: 0 */
  6. import React from 'react';
  7. import PropTypes from 'prop-types';
  8. import classNames from 'classnames';
  9. import { mapToCssModules, deprecated, warnOnce, tagPropType } from './utils';
  10. var propTypes = {
  11. children: PropTypes.node,
  12. type: PropTypes.string,
  13. size: PropTypes.string,
  14. bsSize: PropTypes.string,
  15. state: deprecated(PropTypes.string, 'Please use the props "valid" and "invalid" to indicate the state.'),
  16. valid: PropTypes.bool,
  17. invalid: PropTypes.bool,
  18. tag: tagPropType,
  19. innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  20. static: deprecated(PropTypes.bool, 'Please use the prop "plaintext"'),
  21. plaintext: PropTypes.bool,
  22. addon: PropTypes.bool,
  23. className: PropTypes.string,
  24. cssModule: PropTypes.object
  25. };
  26. var defaultProps = {
  27. type: 'text'
  28. };
  29. var Input =
  30. /*#__PURE__*/
  31. function (_React$Component) {
  32. _inheritsLoose(Input, _React$Component);
  33. function Input(props) {
  34. var _this;
  35. _this = _React$Component.call(this, props) || this;
  36. _this.getRef = _this.getRef.bind(_assertThisInitialized(_assertThisInitialized(_this)));
  37. _this.focus = _this.focus.bind(_assertThisInitialized(_assertThisInitialized(_this)));
  38. return _this;
  39. }
  40. var _proto = Input.prototype;
  41. _proto.getRef = function getRef(ref) {
  42. if (this.props.innerRef) {
  43. this.props.innerRef(ref);
  44. }
  45. this.ref = ref;
  46. };
  47. _proto.focus = function focus() {
  48. if (this.ref) {
  49. this.ref.focus();
  50. }
  51. };
  52. _proto.render = function render() {
  53. var _this$props = this.props,
  54. className = _this$props.className,
  55. cssModule = _this$props.cssModule,
  56. type = _this$props.type,
  57. bsSize = _this$props.bsSize,
  58. state = _this$props.state,
  59. valid = _this$props.valid,
  60. invalid = _this$props.invalid,
  61. tag = _this$props.tag,
  62. addon = _this$props.addon,
  63. staticInput = _this$props.static,
  64. plaintext = _this$props.plaintext,
  65. innerRef = _this$props.innerRef,
  66. attributes = _objectWithoutPropertiesLoose(_this$props, ["className", "cssModule", "type", "bsSize", "state", "valid", "invalid", "tag", "addon", "static", "plaintext", "innerRef"]);
  67. var checkInput = ['radio', 'checkbox'].indexOf(type) > -1;
  68. var isNotaNumber = new RegExp('\\D', 'g');
  69. var fileInput = type === 'file';
  70. var textareaInput = type === 'textarea';
  71. var selectInput = type === 'select';
  72. var Tag = tag || (selectInput || textareaInput ? type : 'input');
  73. var formControlClass = 'form-control';
  74. if (plaintext || staticInput) {
  75. formControlClass = formControlClass + "-plaintext";
  76. Tag = tag || 'input';
  77. } else if (fileInput) {
  78. formControlClass = formControlClass + "-file";
  79. } else if (checkInput) {
  80. if (addon) {
  81. formControlClass = null;
  82. } else {
  83. formControlClass = 'form-check-input';
  84. }
  85. }
  86. if (state && typeof valid === 'undefined' && typeof invalid === 'undefined') {
  87. if (state === 'danger') {
  88. invalid = true;
  89. } else if (state === 'success') {
  90. valid = true;
  91. }
  92. }
  93. if (attributes.size && isNotaNumber.test(attributes.size)) {
  94. warnOnce('Please use the prop "bsSize" instead of the "size" to bootstrap\'s input sizing.');
  95. bsSize = attributes.size;
  96. delete attributes.size;
  97. }
  98. var classes = mapToCssModules(classNames(className, invalid && 'is-invalid', valid && 'is-valid', bsSize ? "form-control-" + bsSize : false, formControlClass), cssModule);
  99. if (Tag === 'input' || tag && typeof tag === 'function') {
  100. attributes.type = type;
  101. }
  102. if (attributes.children && !(plaintext || staticInput || type === 'select' || typeof Tag !== 'string' || Tag === 'select')) {
  103. warnOnce("Input with a type of \"" + type + "\" cannot have children. Please use \"value\"/\"defaultValue\" instead.");
  104. delete attributes.children;
  105. }
  106. return React.createElement(Tag, _extends({}, attributes, {
  107. ref: innerRef,
  108. className: classes
  109. }));
  110. };
  111. return Input;
  112. }(React.Component);
  113. Input.propTypes = propTypes;
  114. Input.defaultProps = defaultProps;
  115. export default Input;