UNPKG

shineout

Version:

Shein 前端组件库

69 lines (56 loc) 1.87 kB
import _extends from "@babel/runtime/helpers/extends"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { PureComponent } from 'react'; var inputStyle = { display: 'none' }; var FileInput = /*#__PURE__*/ function (_PureComponent) { _inheritsLoose(FileInput, _PureComponent); function FileInput(props) { var _this; _this = _PureComponent.call(this, props) || this; _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "locked", void 0); _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "input", void 0); _this.locked = false; _this.bindElement = _this.bindElement.bind(_assertThisInitialized(_assertThisInitialized(_this))); return _this; } var _proto = FileInput.prototype; _proto.bindElement = function bindElement(el) { this.input = el; }; _proto.click = function click() { var _this2 = this; if (this.locked) return; this.locked = true; this.input.value = ''; this.input.click(); setTimeout(function () { _this2.locked = false; }, 1000); }; _proto.render = function render() { var _this$props = this.props, accept = _this$props.accept, onChange = _this$props.onChange, multiple = _this$props.multiple, webkitdirectory = _this$props.webkitdirectory; var OriginProps = { webkitdirectory: webkitdirectory }; return React.createElement("input", _extends({ ref: this.bindElement, accept: accept, multiple: multiple, onChange: onChange, style: inputStyle, type: "file" }, OriginProps)); }; return FileInput; }(PureComponent); export default FileInput;