API
ImageUploadProps
Name | Description | Type | Default |
---|---|---|---|
children | custom upload zone | React.ReactNode | |
width | image width | number | 100 |
height | image height | number | width |
value | default images | ValueType | |
onChange | callback for when the images changes | (value: ValueType ) => void | |
transform | transform images to value | (images: ImageItem[] , max: number) => ValueType | defaultTransform |
onUpload | callback for when the drop event occurs | (file: File ) => string | Promise<string> | defaultUpload |
max | max image number | number | Infinity |
readonly | for preview | boolean | |
className | root className | string | |
itemClassName | image className | string | |
dropzoneClassName | dropzone className | string | |
dropzoneOptions | DropzoneOptions | ||
photoProviderProps | Omit<PhotoProviderProps, "children"> |
Types & Defaults
type ValueItem = {
url: string;
name?: string;
};
type ValueType = string | ValueItem | (string | ValueItem)[];
type ImageItem = {
id?: string;
url?: string;
name?: string;
file?: File;
loading?: boolean;
};
const defaultUpload = (file: File) => URL.createObjectURL(file);
const defaultTransform = (images: ImageItem[], max: number): ValueType => {
const value = images.map((item) => item.url);
if (max === 1) {
return value.join(",");
}
return value;
};