ImageUpload
An image with its preview: a logo, a cover. Choose, replace or remove; a file that is too large or not an image is refused with a message that says what to do.
import { ImageUpload, ImageUploadSkeleton } from '@sypnia/ui/react'
On this page
A project logo
PNG, JPG, SVG or WebP, up to 2 MB.
Code
import { useState } from 'react';
import { ImageUpload, ImageUploadSkeleton } from '@sypnia/ui/react';
// Choose an image to see it; a file over 2 MB is refused with a message. The skeleton is under it.
export default function Logo() {
const [file, setFile] = useState<File | null>(null);
return <div className="sy-stack"><ImageUpload label="Project logo" file={file} onChange={setFile} /><ImageUploadSkeleton /></div>;
} When to use it
Use it when
- Logos, covers, product images.
Do not use it when
- People's photos: use AvatarUpload.
For everyone
- The preview has the image's name as its text; errors are read when they appear.
Props
| ImageUpload | Type | Default |
|---|---|---|
labelrequired | string | |
onChangerequiredReceives the new file, or null when the person removes the image. | (f: File | null) => void | |
fileThe chosen file, before it is saved. | File | null | |
maxSize | number | 2 * 1024 * 1024 |
ratio | "square" | "wide" | wide |
valueThe current image on the server. | string | null |
| ImageUploadSkeleton | Type | Default |
|---|---|---|
ratio | "square" | "wide" | wide |