Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

148 wiersze
5.1 KiB

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