UNPKG

3.36 kBTypeScriptView Raw
1import React from 'react';
2import type { ReactNode, InputHTMLAttributes, ReactElement } from 'react';
3import { NativeProps } from '../../utils/native-props';
4import type { ImageProps } from '../image';
5import { GridProps } from '../grid';
6export declare type TaskStatus = 'pending' | 'fail' | 'success';
7export interface ImageUploadItem {
8 key?: string | number;
9 url: string;
10 thumbnailUrl?: string;
11 extra?: any;
12}
13declare type Task = {
14 id: number;
15 url?: string;
16 file: File;
17 status: TaskStatus;
18};
19export declare type UploadTask = Pick<Task, 'id' | 'status'>;
20export declare type ImageUploaderProps = {
21 defaultValue?: ImageUploadItem[];
22 value?: ImageUploadItem[];
23 columns?: GridProps['columns'];
24 onChange?: (items: ImageUploadItem[]) => void;
25 onUploadQueueChange?: (tasks: UploadTask[]) => void;
26 accept?: string;
27 multiple?: boolean;
28 maxCount?: number;
29 onCountExceed?: (exceed: number) => void;
30 disableUpload?: boolean;
31 showUpload?: boolean;
32 deletable?: boolean;
33 deleteIcon?: ReactNode;
34 capture?: InputHTMLAttributes<unknown>['capture'];
35 onPreview?: (index: number, item: ImageUploadItem) => void;
36 beforeUpload?: (file: File, files: File[]) => Promise<File | null> | File | null;
37 upload: (file: File) => Promise<ImageUploadItem>;
38 onDelete?: (item: ImageUploadItem) => boolean | Promise<boolean> | void;
39 preview?: boolean;
40 showFailed?: boolean;
41 imageFit?: ImageProps['fit'];
42 children?: ReactNode;
43 renderItem?: (originNode: ReactElement, file: ImageUploadItem, fileList: ImageUploadItem[]) => ReactNode;
44} & NativeProps<'--cell-size' | '--gap' | '--gap-vertical' | '--gap-horizontal'>;
45export interface ImageUploaderRef {
46 nativeElement: HTMLInputElement | null;
47}
48export declare const ImageUploader: React.ForwardRefExoticComponent<{
49 defaultValue?: ImageUploadItem[] | undefined;
50 value?: ImageUploadItem[] | undefined;
51 columns?: number | undefined;
52 onChange?: ((items: ImageUploadItem[]) => void) | undefined;
53 onUploadQueueChange?: ((tasks: UploadTask[]) => void) | undefined;
54 accept?: string | undefined;
55 multiple?: boolean | undefined;
56 maxCount?: number | undefined;
57 onCountExceed?: ((exceed: number) => void) | undefined;
58 disableUpload?: boolean | undefined;
59 showUpload?: boolean | undefined;
60 deletable?: boolean | undefined;
61 deleteIcon?: ReactNode;
62 capture?: InputHTMLAttributes<unknown>['capture'];
63 onPreview?: ((index: number, item: ImageUploadItem) => void) | undefined;
64 beforeUpload?: ((file: File, files: File[]) => Promise<File | null> | File | null) | undefined;
65 upload: (file: File) => Promise<ImageUploadItem>;
66 onDelete?: ((item: ImageUploadItem) => boolean | Promise<boolean> | void) | undefined;
67 preview?: boolean | undefined;
68 showFailed?: boolean | undefined;
69 imageFit?: ImageProps['fit'];
70 children?: ReactNode;
71 renderItem?: ((originNode: ReactElement, file: ImageUploadItem, fileList: ImageUploadItem[]) => ReactNode) | undefined;
72} & {
73 className?: string | undefined;
74 style?: (React.CSSProperties & Partial<Record<"--gap" | "--gap-vertical" | "--gap-horizontal" | "--cell-size", string>>) | undefined;
75 tabIndex?: number | undefined;
76} & React.AriaAttributes & React.RefAttributes<ImageUploaderRef>>;
77export {};
78
\No newline at end of file