zent
Version:
一套前端设计语言和基于React的实现
36 lines (35 loc) • 1.52 kB
JavaScript
import { __extends } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { createRef, PureComponent } from 'react';
var FileInput = (function (_super) {
__extends(FileInput, _super);
function FileInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.inputRef = createRef();
_this.open = function () {
_this.inputRef.current && _this.inputRef.current.click();
};
_this.onFileInputChange = function (evt) {
evt.preventDefault();
evt.stopPropagation();
if (evt.target.files) {
var files = Array.from(evt.target.files);
_this.props.onChange(files);
}
};
_this.onFileInputClick = function () {
if (_this.inputRef.current) {
_this.inputRef.current.value = '';
}
};
return _this;
}
FileInput.prototype.render = function () {
var _a = this.props, remainAmount = _a.remainAmount, accept = _a.accept, multiple = _a.multiple, disabled = _a.disabled;
var isDisabled = disabled;
var isMultiple = multiple && remainAmount > 1;
return (_jsx("input", { hidden: true, ref: this.inputRef, type: "file", disabled: isDisabled, multiple: isMultiple, accept: accept, onClick: this.onFileInputClick, onChange: this.onFileInputChange, "data-zv": '10.0.17' }, void 0));
};
return FileInput;
}(PureComponent));
export default FileInput;