interface.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { ReactNode, CSSProperties, MouseEvent } from 'react';
  2. import { BaseFileItem } from '@douyinfe/semi-foundation/upload/foundation';
  3. import { strings } from '@douyinfe/semi-foundation/upload/constants';
  4. import { ArrayElement } from '../_base/base';
  5. export type PromptPositionType = ArrayElement<typeof strings.PROMPT_POSITION>;
  6. export type UploadListType = ArrayElement<typeof strings.LIST_TYPE>;
  7. export interface BeforeUploadProps {
  8. file: FileItem;
  9. fileList: Array<FileItem>;
  10. }
  11. export interface AfterUploadProps {
  12. file: FileItem;
  13. fileList: Array<FileItem>;
  14. response: any;
  15. }
  16. export interface OnChangeProps {
  17. fileList: Array<FileItem>;
  18. currentFile: FileItem;
  19. }
  20. export interface customRequestArgs {
  21. fileName: string; // Current file name
  22. data: Record<string, any>; // User-set props.data
  23. file: FileItem;
  24. 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)
  25. 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
  26. onError: (userXhr: { status?: number }, e: Event) => any; // Functions to call in case of upload error
  27. 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
  28. withCredentials: boolean; // User-set props.with Credentials
  29. action: string; // User-set props.action
  30. }
  31. export interface CustomError extends Error {
  32. status: number;
  33. method: string;
  34. url: string;
  35. }
  36. export interface FileItem extends BaseFileItem {
  37. validateMessage?: ReactNode;
  38. }
  39. export interface RenderFileItemProps extends FileItem {
  40. previewFile?: (fileItem: RenderFileItemProps) => ReactNode;
  41. listType: UploadListType;
  42. onRemove: (props: RenderFileItemProps, e: MouseEvent) => void;
  43. onRetry: (props: RenderFileItemProps, e: MouseEvent) => void;
  44. onReplace: (props: RenderFileItemProps, e: MouseEvent) => void;
  45. key: string;
  46. showRetry: boolean;
  47. showReplace: boolean;
  48. style?: CSSProperties;
  49. disabled: boolean;
  50. onPreviewClick: () => void;
  51. }