interface.d.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import type * as React from 'react';
  2. export type BeforeUploadFileType = File | Blob | boolean | string;
  3. export type Action = string | ((file: RcFile) => string | PromiseLike<string>);
  4. export interface UploadProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onError' | 'onProgress'> {
  5. name?: string;
  6. style?: React.CSSProperties;
  7. className?: string;
  8. disabled?: boolean;
  9. component?: React.ComponentType<any> | string;
  10. action?: Action;
  11. method?: UploadRequestMethod;
  12. directory?: boolean;
  13. data?: Record<string, unknown> | ((file: RcFile | string | Blob) => Record<string, unknown>);
  14. headers?: UploadRequestHeader;
  15. accept?: string;
  16. multiple?: boolean;
  17. onBatchStart?: (fileList: {
  18. file: RcFile;
  19. parsedFile: Exclude<BeforeUploadFileType, boolean>;
  20. }[]) => void;
  21. onStart?: (file: RcFile) => void;
  22. onError?: (error: Error, ret: Record<string, unknown>, file: RcFile) => void;
  23. onSuccess?: (response: Record<string, unknown>, file: RcFile, xhr: XMLHttpRequest) => void;
  24. onProgress?: (event: UploadProgressEvent, file: RcFile) => void;
  25. beforeUpload?: (file: RcFile, FileList: RcFile[]) => BeforeUploadFileType | Promise<void | BeforeUploadFileType> | void;
  26. customRequest?: (option: UploadRequestOption) => void | {
  27. abort: () => void;
  28. };
  29. withCredentials?: boolean;
  30. openFileDialogOnClick?: boolean;
  31. prefixCls?: string;
  32. id?: string;
  33. onMouseEnter?: (e: React.MouseEvent<HTMLDivElement>) => void;
  34. onMouseLeave?: (e: React.MouseEvent<HTMLDivElement>) => void;
  35. onClick?: (e: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
  36. classNames?: {
  37. input?: string;
  38. };
  39. styles?: {
  40. input?: React.CSSProperties;
  41. };
  42. hasControlInside?: boolean;
  43. pastable?: boolean;
  44. }
  45. export interface UploadProgressEvent extends Partial<ProgressEvent> {
  46. percent?: number;
  47. }
  48. export type UploadRequestMethod = 'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch';
  49. export type UploadRequestHeader = Record<string, string>;
  50. export type UploadRequestFile = Exclude<BeforeUploadFileType, File | boolean> | RcFile;
  51. export interface UploadRequestError extends Error {
  52. status?: number;
  53. method?: UploadRequestMethod;
  54. url?: string;
  55. }
  56. export interface UploadRequestOption<T = any> {
  57. onProgress?: (event: UploadProgressEvent, file?: UploadRequestFile) => void;
  58. onError?: (event: UploadRequestError | ProgressEvent, body?: T) => void;
  59. onSuccess?: (body: T, fileOrXhr?: UploadRequestFile | XMLHttpRequest) => void;
  60. data?: Record<string, unknown>;
  61. filename?: string;
  62. file: UploadRequestFile;
  63. withCredentials?: boolean;
  64. action: string;
  65. headers?: UploadRequestHeader;
  66. method: UploadRequestMethod;
  67. }
  68. export interface RcFile extends File {
  69. uid: string;
  70. }