index.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /* eslint-disable max-len */
  2. import React, { ReactNode, CSSProperties, RefObject, ChangeEvent, DragEvent } from 'react';
  3. import cls from 'classnames';
  4. import PropTypes from 'prop-types';
  5. import { noop } from 'lodash-es';
  6. import UploadFoundation, { BaseFileItem, UploadAdapter, BeforeUploadObjectResult, AfterUploadResult } from '@douyinfe/semi-foundation/upload/foundation';
  7. import { strings, cssClasses } from '@douyinfe/semi-foundation/upload/constants';
  8. import FileCard from './fileCard';
  9. import BaseComponent, { ValidateStatus } from '../_base/baseComponent';
  10. import LocaleConsumer from '../locale/localeConsumer';
  11. import { IconUpload } from '@douyinfe/semi-icons';
  12. import { ArrayElement } from '../_base/base';
  13. import { Locale } from '../locale/interface';
  14. import '@douyinfe/semi-foundation/upload/upload.scss';
  15. const prefixCls = cssClasses.PREFIX;
  16. export interface FileItem extends BaseFileItem {
  17. validateMessage?: ReactNode;
  18. }
  19. export type UploadListType = ArrayElement<typeof strings.LIST_TYPE>;
  20. export type PromptPositionType = ArrayElement<typeof strings.PROMPT_POSITION>;
  21. export interface RenderFileItemProps extends FileItem {
  22. previewFile: (fileItem: FileItem) => ReactNode;
  23. listType: UploadListType;
  24. onRemove: () => void;
  25. onRetry: () => void;
  26. onReplace: () => void;
  27. key: string;
  28. showRetry: boolean;
  29. showReplace: boolean;
  30. style: CSSProperties;
  31. disabled: boolean;
  32. onPreviewClick: () => void;
  33. }
  34. export interface BeforeUploadProps {
  35. file: FileItem;
  36. fileList: Array<FileItem>;
  37. }
  38. export interface AfterUploadProps {
  39. file: FileItem;
  40. fileList: Array<FileItem>;
  41. response: any;
  42. }
  43. export interface OnChangeProps {
  44. fileList: Array<FileItem>;
  45. currentFile: FileItem;
  46. }
  47. export interface customRequestArgs {
  48. fileName: string; // Current file name
  49. data: Record<string, any>; // User-set props.data
  50. file: FileItem;
  51. fileInstance: File; // Original File Object which extends to the blob, the file object actually acquired by the browser (https://developer.mozilla.org/zh-CN/docs/Web/API/File)
  52. onProgress: (event: { total: number; loaded: number }) => any; // The function that should be called during the upload process, the event needs to contain the total and loaded attributes
  53. onError: (userXhr: { status?: number }, e: Event) => any; // Functions to call in case of upload error
  54. onSuccess: (response: any, e: Event) => any; // The function that should be called after the upload is successful, the response is the request result after the upload is successful
  55. withCredentials: boolean; // User-set props.with Credentials
  56. action: string; // User-set props.action
  57. }
  58. export interface CustomError extends Error {
  59. status: number;
  60. method: string;
  61. url: string;
  62. }
  63. export interface UploadProps {
  64. accept?: string;
  65. action: string;
  66. afterUpload?: (object: AfterUploadProps) => AfterUploadResult;
  67. beforeUpload?: (object: BeforeUploadProps) => BeforeUploadObjectResult | Promise<BeforeUploadObjectResult> | boolean;
  68. beforeClear?: (fileList: Array<FileItem>) => boolean | Promise<boolean>;
  69. beforeRemove?: (file: FileItem, fileList: Array<FileItem>) => boolean | Promise<boolean>;
  70. capture?: boolean | string | undefined;
  71. children?: ReactNode;
  72. className?: string;
  73. customRequest?: (object: customRequestArgs) => void;
  74. data?: Record<string, any> | ((file: File) => Record<string, unknown>);
  75. defaultFileList?: Array<FileItem>;
  76. directory?: boolean;
  77. disabled?: boolean;
  78. dragIcon?: ReactNode;
  79. dragMainText?: ReactNode;
  80. dragSubText?: ReactNode;
  81. draggable?: boolean;
  82. fileList?: Array<FileItem>;
  83. fileName?: string;
  84. headers?: Record<string, any> | ((file: File) => Record<string, string>);
  85. itemStyle?: CSSProperties;
  86. limit?: number;
  87. listType?: UploadListType;
  88. maxSize?: number;
  89. minSize?: number;
  90. multiple?: boolean;
  91. name?: string;
  92. onAcceptInvalid?: (files: File[]) => void;
  93. onChange?: (object: OnChangeProps) => void;
  94. onClear?: () => void;
  95. onDrop?: (e: Event, files: Array<File>, fileList: Array<FileItem>) => void;
  96. onError?: (e: CustomError, file: File, fileList: Array<FileItem>, xhr: XMLHttpRequest) => void;
  97. onExceed?: (fileList: Array<File>) => void;
  98. onFileChange?: (files: Array<File>) => void;
  99. onOpenFileDialog?: () => void;
  100. onPreviewClick?: (fileItem: FileItem) => void;
  101. onProgress?: (percent: number, file: File, fileList: Array<FileItem>) => void;
  102. onRemove?: (currentFile: File, fileList: Array<FileItem>, currentFileItem: FileItem) => void;
  103. onRetry?: (fileItem: FileItem) => void;
  104. onSizeError?: (file: File, fileList: Array<FileItem>) => void;
  105. onSuccess?: (responseBody: any, file: File, fileList: Array<FileItem>) => void;
  106. previewFile?: (fileItem: FileItem) => ReactNode;
  107. prompt?: ReactNode;
  108. promptPosition?: PromptPositionType;
  109. renderFileItem?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
  110. showClear?: boolean;
  111. showReplace?: boolean; // Display replacement function
  112. showRetry?: boolean;
  113. showUploadList?: boolean;
  114. style?: CSSProperties;
  115. timeout?: number;
  116. transformFile?: (file: File) => FileItem;
  117. uploadTrigger?: 'auto' | 'custom';
  118. validateMessage?: ReactNode;
  119. validateStatus?: ValidateStatus;
  120. withCredentials?: boolean;
  121. }
  122. export interface UploadState {
  123. dragAreaStatus: 'default' | 'legal' | 'illegal'; // Status of the drag zone
  124. fileList: Array<FileItem>;
  125. inputKey: number;
  126. localUrls: Array<string>;
  127. replaceIdx: number;
  128. replaceInputKey: number;
  129. }
  130. class Upload extends BaseComponent<UploadProps, UploadState> {
  131. static propTypes = {
  132. accept: PropTypes.string, // Limit allowed file types
  133. action: PropTypes.string.isRequired,
  134. afterUpload: PropTypes.func,
  135. beforeClear: PropTypes.func,
  136. beforeRemove: PropTypes.func,
  137. beforeUpload: PropTypes.func,
  138. children: PropTypes.node,
  139. className: PropTypes.string,
  140. customRequest: PropTypes.func,
  141. data: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), // Extra parameters attached when uploading
  142. defaultFileList: PropTypes.array,
  143. directory: PropTypes.bool, // Support folder upload
  144. disabled: PropTypes.bool,
  145. dragIcon: PropTypes.node,
  146. dragMainText: PropTypes.node,
  147. dragSubText: PropTypes.node,
  148. draggable: PropTypes.bool,
  149. fileList: PropTypes.array, // files had been uploaded
  150. fileName: PropTypes.string, // same as name, to avoid props conflict in Form.Upload
  151. headers: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
  152. itemStyle: PropTypes.object,
  153. limit: PropTypes.number, // 最大允许上传文件个数
  154. listType: PropTypes.oneOf<UploadProps['listType']>(strings.LIST_TYPE),
  155. maxSize: PropTypes.number, // 文件大小限制,单位kb
  156. minSize: PropTypes.number, // 文件大小限制,单位kb
  157. multiple: PropTypes.bool,
  158. name: PropTypes.string, // file name
  159. onAcceptInvalid: PropTypes.func,
  160. onChange: PropTypes.func,
  161. onClear: PropTypes.func,
  162. onDrop: PropTypes.func,
  163. onError: PropTypes.func,
  164. onExceed: PropTypes.func, // Callback exceeding limit
  165. onFileChange: PropTypes.func, // Callback when file is selected
  166. onOpenFileDialog: PropTypes.func,
  167. onPreviewClick: PropTypes.func,
  168. onProgress: PropTypes.func,
  169. onRemove: PropTypes.func,
  170. onRetry: PropTypes.func,
  171. onSizeError: PropTypes.func, // Callback with invalid file size
  172. onSuccess: PropTypes.func,
  173. previewFile: PropTypes.func, // Custom preview
  174. prompt: PropTypes.node,
  175. promptPosition: PropTypes.oneOf<UploadProps['promptPosition']>(strings.PROMPT_POSITION),
  176. renderFileItem: PropTypes.func,
  177. showClear: PropTypes.bool,
  178. showReplace: PropTypes.bool,
  179. showRetry: PropTypes.bool,
  180. showUploadList: PropTypes.bool, // whether to show fileList
  181. style: PropTypes.object,
  182. timeout: PropTypes.number,
  183. transformFile: PropTypes.func,
  184. uploadTrigger: PropTypes.oneOf<UploadProps['uploadTrigger']>(strings.UPLOAD_TRIGGER), // auto、custom
  185. validateMessage: PropTypes.node,
  186. validateStatus: PropTypes.oneOf<UploadProps['validateStatus']>(strings.VALIDATE_STATUS),
  187. withCredentials: PropTypes.bool,
  188. };
  189. static defaultProps: Partial<UploadProps> = {
  190. defaultFileList: [],
  191. disabled: false,
  192. listType: 'list' as const,
  193. multiple: false,
  194. onAcceptInvalid: noop,
  195. onChange: noop,
  196. beforeRemove: () => true,
  197. beforeClear: () => true,
  198. onClear: noop,
  199. onDrop: noop,
  200. onError: noop,
  201. onExceed: noop,
  202. onFileChange: noop,
  203. onOpenFileDialog: noop,
  204. onProgress: noop,
  205. onRemove: noop,
  206. onRetry: noop,
  207. onSizeError: noop,
  208. onSuccess: noop,
  209. promptPosition: 'right' as const,
  210. showClear: true,
  211. showReplace: false,
  212. showRetry: true,
  213. showUploadList: true,
  214. uploadTrigger: 'auto' as const,
  215. withCredentials: false,
  216. };
  217. static FileCard = FileCard;
  218. constructor(props: UploadProps) {
  219. super(props);
  220. this.state = {
  221. fileList: props.defaultFileList || [],
  222. replaceIdx: -1,
  223. inputKey: Math.random(),
  224. replaceInputKey: Math.random(),
  225. // Status of the drag zone
  226. dragAreaStatus: 'default',
  227. localUrls: [],
  228. };
  229. this.foundation = new UploadFoundation(this.adapter);
  230. this.inputRef = React.createRef<HTMLInputElement>();
  231. this.replaceInputRef = React.createRef<HTMLInputElement>();
  232. }
  233. static getDerivedStateFromProps(props: UploadProps): Partial<UploadState> | null {
  234. const { fileList } = props;
  235. if ('fileList' in props) {
  236. return {
  237. fileList: fileList || []
  238. };
  239. }
  240. return null;
  241. }
  242. get adapter(): UploadAdapter<UploadProps, UploadState> {
  243. return {
  244. ...super.adapter,
  245. notifyFileSelect: (files): void => this.props.onFileChange(files),
  246. notifyError: (error, fileInstance, fileList, xhr): void => this.props.onError(error, fileInstance, fileList, xhr),
  247. notifySuccess: (responseBody, file, fileList): void => this.props.onSuccess(responseBody, file, fileList),
  248. notifyProgress: (percent, file, fileList): void => this.props.onProgress(percent, file, fileList),
  249. notifyRemove: (file, fileList, fileItem): void => this.props.onRemove(file, fileList, fileItem),
  250. notifySizeError: (file, fileList): void => this.props.onSizeError(file, fileList),
  251. notifyExceed: (fileList): void => this.props.onExceed(fileList),
  252. updateFileList: (fileList, cb): void => {
  253. if (typeof cb === 'function') {
  254. this.setState({ fileList }, cb);
  255. } else {
  256. this.setState({ fileList });
  257. }
  258. },
  259. notifyBeforeUpload: ({ file, fileList }): boolean | BeforeUploadObjectResult | Promise<BeforeUploadObjectResult> => this.props.beforeUpload({ file, fileList }),
  260. notifyAfterUpload: ({ response, file, fileList }): AfterUploadResult => this.props.afterUpload({ response, file, fileList }),
  261. resetInput: (): void => {
  262. this.setState(prevState => ({
  263. inputKey: Math.random()
  264. }));
  265. },
  266. resetReplaceInput: (): void => {
  267. this.setState(prevState => ({
  268. replaceInputKey: Math.random()
  269. }));
  270. },
  271. updateDragAreaStatus: (dragAreaStatus: string): void => this.setState({ dragAreaStatus } as { dragAreaStatus: 'default' | 'legal' | 'illegal' }),
  272. notifyChange: ({ currentFile, fileList }): void => this.props.onChange({ currentFile, fileList }),
  273. updateLocalUrls: (urls): void => this.setState({ localUrls: urls }),
  274. notifyClear: (): void => this.props.onClear(),
  275. notifyPreviewClick: (file): void => this.props.onPreviewClick(file),
  276. notifyDrop: (e, files, fileList): void => this.props.onDrop(e, files, fileList),
  277. notifyAcceptInvalid: (invalidFiles): void => this.props.onAcceptInvalid(invalidFiles),
  278. notifyBeforeRemove: (file, fileList): boolean | Promise<boolean> => this.props.beforeRemove(file, fileList),
  279. notifyBeforeClear: (fileList): boolean | Promise<boolean> => this.props.beforeClear(fileList),
  280. };
  281. }
  282. foundation: UploadFoundation;
  283. inputRef: RefObject<HTMLInputElement> = null;
  284. replaceInputRef: RefObject<HTMLInputElement> = null;
  285. componentWillUnmount(): void {
  286. this.foundation.destroy();
  287. }
  288. onClick = (): void => {
  289. const { inputRef, props } = this;
  290. const { onOpenFileDialog } = props;
  291. const isDisabled = Boolean(this.props.disabled);
  292. if (isDisabled || !inputRef || !inputRef.current) {
  293. return;
  294. }
  295. inputRef.current.click();
  296. if (onOpenFileDialog && typeof onOpenFileDialog) {
  297. onOpenFileDialog();
  298. }
  299. };
  300. onChange = (e: ChangeEvent<HTMLInputElement>): void => {
  301. const { files } = e.target;
  302. this.foundation.handleChange(files);
  303. };
  304. replace = (index: number): void => {
  305. this.setState({ replaceIdx: index }, () => {
  306. this.replaceInputRef.current.click();
  307. });
  308. };
  309. onReplaceChange = (e: ChangeEvent<HTMLInputElement>): void => {
  310. const { files } = e.target;
  311. this.foundation.handleReplaceChange(files);
  312. };
  313. clear = (): void => {
  314. this.foundation.handleClear();
  315. };
  316. remove = (fileItem: FileItem): void => {
  317. this.foundation.handleRemove(fileItem);
  318. };
  319. upload = (): void => {
  320. const { fileList } = this.state;
  321. this.foundation.startUpload(fileList);
  322. };
  323. renderFile = (file: FileItem, index: number, locale: Locale['Upload']): ReactNode => {
  324. const { name, status, validateMessage, _sizeInvalid } = file;
  325. const { previewFile, listType, itemStyle, showRetry, renderFileItem, disabled, onPreviewClick, showReplace } = this.props;
  326. const onRemove = (): void => this.remove(file);
  327. const onRetry = (): void => {
  328. this.foundation.retry(file);
  329. };
  330. const onReplace = (): void => {
  331. this.replace(index);
  332. };
  333. const fileCardProps = {
  334. ...file,
  335. previewFile,
  336. listType,
  337. onRemove,
  338. onRetry,
  339. key: `${name}${index}`,
  340. showRetry: typeof file.showRetry !== 'undefined' ? file.showRetry : showRetry,
  341. style: itemStyle,
  342. disabled,
  343. showReplace: typeof file.showReplace !== 'undefined' ? file.showReplace : showReplace,
  344. onReplace,
  345. onPreviewClick: typeof onPreviewClick !== 'undefined' ? (): void => this.foundation.handlePreviewClick(file) : undefined,
  346. };
  347. if (status === strings.FILE_STATUS_UPLOAD_FAIL && !validateMessage) {
  348. fileCardProps.validateMessage = locale.fail;
  349. }
  350. if (_sizeInvalid && !validateMessage) {
  351. fileCardProps.validateMessage = locale.illegalSize;
  352. }
  353. if (typeof renderFileItem === 'undefined') {
  354. return <FileCard {...fileCardProps} />;
  355. } else {
  356. return renderFileItem(fileCardProps);
  357. }
  358. };
  359. renderFileList = (): ReactNode => {
  360. const { showUploadList, listType, limit, disabled, children } = this.props;
  361. const { fileList: stateFileList } = this.state;
  362. const fileList = this.props.fileList || stateFileList;
  363. const isPicType = listType === strings.FILE_LIST_PIC;
  364. const showAddTriggerInList = isPicType && (limit ? limit > fileList.length : true);
  365. const uploadAddCls = cls(`${prefixCls }-add`, {
  366. [`${prefixCls }-picture-add`]: isPicType,
  367. [`${prefixCls}-picture-add-disabled`]: disabled
  368. });
  369. const addContent = (
  370. <div className={uploadAddCls} onClick={this.onClick}>
  371. {children}
  372. </div>
  373. );
  374. if (!showUploadList || !fileList.length) {
  375. if (showAddTriggerInList) {
  376. return addContent;
  377. }
  378. return null;
  379. }
  380. const fileListCls = cls(`${prefixCls }-file-list`, {
  381. [`${prefixCls }-picture-file-list`]: isPicType,
  382. });
  383. const titleCls = `${prefixCls }-file-list-title`;
  384. const mainCls = `${prefixCls }-file-list-main`;
  385. const showTitle = limit !== 1 && fileList.length && listType !== strings.FILE_LIST_PIC;
  386. const showClear = this.props.showClear && !disabled;
  387. return (
  388. <LocaleConsumer componentName="Upload">
  389. {(locale: Locale['Upload']): ReactNode => (
  390. <div className={fileListCls}>
  391. {showTitle ? (
  392. <div className={titleCls}>
  393. <span className={`${titleCls }-choosen`}>{locale.selectedFiles}</span>
  394. {showClear ? (
  395. <span onClick={this.clear} className={`${titleCls }-clear`}>
  396. {locale.clear}
  397. </span>
  398. ) : null}
  399. </div>
  400. ) : null}
  401. <div className={mainCls}>
  402. {fileList.map((file, index) => this.renderFile(file, index, locale))}
  403. {showAddTriggerInList ? addContent : null}
  404. </div>
  405. </div>
  406. )}
  407. </LocaleConsumer>
  408. );
  409. };
  410. onDrop = (e: DragEvent<HTMLDivElement>): void => {
  411. this.foundation.handleDrop(e);
  412. };
  413. onDragOver = (e: DragEvent<HTMLDivElement>): void => {
  414. // When a drag element moves within the target element
  415. this.foundation.handleDragOver(e);
  416. };
  417. onDragLeave = (e: DragEvent<HTMLDivElement>): void => {
  418. this.foundation.handleDragLeave(e);
  419. };
  420. onDragEnter = (e: DragEvent<HTMLDivElement>): void => {
  421. this.foundation.handleDragEnter(e);
  422. };
  423. renderDragArea = (): ReactNode => {
  424. const { dragAreaStatus } = this.state;
  425. const { children, dragIcon, dragMainText, dragSubText } = this.props;
  426. const dragAreaBaseCls = `${prefixCls }-drag-area`;
  427. const dragAreaCls = cls(dragAreaBaseCls, {
  428. [`${dragAreaBaseCls }-legal`]: dragAreaStatus === strings.DRAG_AREA_LEGAL,
  429. [`${dragAreaBaseCls }-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL,
  430. [`${dragAreaBaseCls }-custom`]: children,
  431. });
  432. return (
  433. <LocaleConsumer componentName="Upload">
  434. {(locale: Locale['Upload']): ReactNode => (
  435. <div
  436. className={dragAreaCls}
  437. onDrop={this.onDrop}
  438. onDragOver={this.onDragOver}
  439. onDragLeave={this.onDragLeave}
  440. onDragEnter={this.onDragEnter}
  441. onClick={this.onClick}
  442. >
  443. {children ? (
  444. children
  445. ) : (
  446. <>
  447. <div className={`${dragAreaBaseCls }-icon`}>
  448. {dragIcon || <IconUpload size="extra-large" />}
  449. </div>
  450. <div className={`${dragAreaBaseCls }-text`}>
  451. <div className={`${dragAreaBaseCls }-main-text`}>
  452. {dragMainText || locale.mainText}
  453. </div>
  454. <div className={`${dragAreaBaseCls }-sub-text`}>{dragSubText}</div>
  455. <div className={`${dragAreaBaseCls }-tips`}>
  456. {dragAreaStatus === strings.DRAG_AREA_LEGAL && (
  457. <span className={`${dragAreaBaseCls }-tips-legal`}>{locale.legalTips}</span>
  458. )}
  459. {dragAreaStatus === strings.DRAG_AREA_ILLEGAL && (
  460. <span className={`${dragAreaBaseCls }-tips-illegal`}>
  461. {locale.illegalTips}
  462. </span>
  463. )}
  464. </div>
  465. </div>
  466. </>
  467. )}
  468. </div>
  469. )}
  470. </LocaleConsumer>
  471. );
  472. };
  473. render(): ReactNode {
  474. const {
  475. style,
  476. className,
  477. multiple,
  478. accept,
  479. disabled,
  480. children,
  481. capture,
  482. listType,
  483. prompt,
  484. promptPosition,
  485. draggable,
  486. validateMessage,
  487. validateStatus,
  488. directory,
  489. } = this.props;
  490. const uploadCls = cls(prefixCls, {
  491. [`${prefixCls }-picture`]: listType === strings.FILE_LIST_PIC,
  492. [`${prefixCls }-disabled`]: disabled,
  493. [`${prefixCls }-default`]: validateStatus === 'default',
  494. [`${prefixCls }-error`]: validateStatus === 'error',
  495. [`${prefixCls }-warning`]: validateStatus === 'warning',
  496. [`${prefixCls }-success`]: validateStatus === 'success',
  497. }, className);
  498. const uploadAddCls = cls(`${prefixCls }-add`);
  499. const inputCls = cls(`${prefixCls }-hidden-input`);
  500. const inputReplaceCls = cls(`${prefixCls }-hidden-input-replace`);
  501. const promptCls = cls(`${prefixCls }-prompt`);
  502. const validateMsgCls = cls(`${prefixCls }-validate-message`);
  503. const dirProps = directory ? { directory: 'directory', webkitdirectory: 'webkitdirectory' } : {};
  504. const addContent =
  505. listType !== strings.FILE_LIST_PIC ? (
  506. <div className={uploadAddCls} onClick={this.onClick}>
  507. {children}
  508. </div>
  509. ) : null;
  510. return (
  511. <div className={uploadCls} style={style} x-prompt-pos={promptPosition}>
  512. <input
  513. key={this.state.inputKey}
  514. capture={capture}
  515. multiple={multiple}
  516. accept={accept}
  517. onChange={this.onChange}
  518. type="file"
  519. autoComplete="off"
  520. tabIndex={-1}
  521. className={inputCls}
  522. ref={this.inputRef}
  523. {...dirProps}
  524. />
  525. <input
  526. key={this.state.replaceInputKey}
  527. multiple={false}
  528. accept={accept}
  529. onChange={this.onReplaceChange}
  530. type="file"
  531. autoComplete="off"
  532. tabIndex={-1}
  533. className={inputReplaceCls}
  534. ref={this.replaceInputRef}
  535. />
  536. {draggable ? this.renderDragArea() : addContent}
  537. {prompt ? <div className={promptCls}>{prompt}</div> : null}
  538. {validateMessage ? <div className={validateMsgCls}>{validateMessage}</div> : null}
  539. {this.renderFileList()}
  540. </div>
  541. );
  542. }
  543. }
  544. export default Upload;