interface.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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: (e?: { 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. index?: number;
  41. previewFile?: (fileItem: RenderFileItemProps) => ReactNode;
  42. listType: UploadListType;
  43. onRemove: () => void;
  44. onRetry: () => void;
  45. onReplace: () => void;
  46. key: string;
  47. showPicInfo?: boolean;
  48. renderPicInfo?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
  49. renderPicPreviewIcon?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
  50. renderFileOperation?: (fileItem: RenderFileItemProps) => ReactNode;
  51. showRetry?: boolean;
  52. showReplace?: boolean;
  53. style?: CSSProperties;
  54. disabled: boolean;
  55. onPreviewClick: () => void
  56. }
  57. export interface RenderPictureCloseProps {
  58. className: string;
  59. remove: (e: MouseEvent) => void
  60. }