UNPKG

ultra-design

Version:
107 lines (106 loc) 3.51 kB
import React, { ReactNode } from 'react'; export interface UploadProps { /** * @description.zh-CN 默认显示图片列表 * @description.en-US default images */ fileList?: BaseImageData[]; /** * @description.zh-CN 文件列表改变后的回调 * @description.en-US after image list change callback */ onChange?: (imageList: BaseImageData[]) => void; /** * @description.zh-CN 点击每个文件后的回调 * @description.en-US image click callback */ onClick?: (image: BaseImageData) => void; /** * @description.zh-CN 删除图片后的回调 * @description.en-US after remove image callback */ onRemove?: (image: BaseImageData) => void; /** * @description.zh-CN 是否支持一次选择多个文件 * @description.en-US support select multi files * @default true */ multiple?: boolean; /** * @description.zh-CN 支持的文件后缀名 * @description.en-US support file extensions * @default ['.jpg', '.jpeg', '.gif', '.png'] */ extensions?: string[]; /** * @description.zh-CN 上传的图片不是合法的后缀名触发的回调 * @description.en-US A callback triggered by an uploaded image is not a valid suffix */ onOverExtensions?: (ext: string, extensions: string[]) => (void | 'continue' | 'break') | Promise<void | 'continue' | 'break'>; /** * @description.zh-CN 图片最大数量 * @description.en-US max image counts * @default 10 */ maxCount?: number; /** * @description.zh-CN 上传的图片超过最大数量限制后的回调 * @description.en-US A callback after the maximum number of images uploaded exceeds the limit */ onOverCount?: (count: number, maxCount: number) => (void | false) | Promise<void | false>; /** * @description.zh-CN 图片最大的字节数 * @description.en-US max byte count * @default 5242880 */ maxSize?: number; /** * @description.zh-CN 上传的图片大小超过限制后的回调 * @description.en-US A callback after the size of an uploaded image exceeds the limit */ onOverSize?: (size: number, maxSize: number) => (void | 'continue' | 'break') | Promise<void | 'continue' | 'break'>; /** * @description.zh-CN 在图片中显示错误信息 * @description.en-US show an error message in the image */ renderError?: (image: ImageData) => React.ReactNode; /** * @description.zh-CN 添加头部内容 * @description.en-US add header content */ header?: React.ReactNode; /** * @description.zh-CN 添加尾部内容 * @description.en-US add footer content */ footer?: React.ReactNode; name?: string; children?: ReactNode; } declare const defaultProps: { maxSize: number; maxCount: number; fileList: never[]; extensions: string[]; multiple: boolean; }; export declare type MergedUploadProps = typeof defaultProps & UploadProps; interface BaseImageData { url: string; name?: string; } declare enum ErrorType { OVER_COUNT = 0, OVER_SIZE = 1, OVER_EXTENSTIONS = 2, SERVER_ERROR = 3 } interface ImageData extends BaseImageData { file?: File; errorCode?: keyof typeof ErrorType; } export interface UploadRef { imageList: ImageData[]; } declare const Upload: React.ForwardRefExoticComponent<UploadProps & React.RefAttributes<UploadRef>>; export default Upload;