fileMultipleButtonLineComponent.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import * as React from "react";
  2. interface IFileMultipleButtonLineComponentProps {
  3. label: string;
  4. onClick: (event: any) => void;
  5. accept: string;
  6. }
  7. export class FileMultipleButtonLineComponent extends React.Component<IFileMultipleButtonLineComponentProps> {
  8. private static _IDGenerator = 0;
  9. private _id = FileMultipleButtonLineComponent._IDGenerator++;
  10. private uploadInputRef: React.RefObject<HTMLInputElement>;
  11. constructor(props: IFileMultipleButtonLineComponentProps) {
  12. super(props);
  13. this.uploadInputRef = React.createRef();
  14. }
  15. onChange(evt: any) {
  16. var files: File[] = evt.target.files;
  17. if (files && files.length) {
  18. this.props.onClick(evt);
  19. }
  20. evt.target.value = "";
  21. }
  22. render() {
  23. return (
  24. <div className="buttonLine">
  25. <label htmlFor={"file-upload" + this._id} className="file-upload">
  26. {this.props.label}
  27. </label>
  28. <input ref={this.uploadInputRef} id={"file-upload" + this._id} type="file" accept={this.props.accept} onChange={evt => this.onChange(evt)} multiple />
  29. </div>
  30. );
  31. }
  32. }