Saudi forms and dates
ImageField
An image upload with a preview, Replace and Remove. A wrong type or a file over maxSizeMb (default 2) is refused before the upload. upload sends the file and returns its URL; while it runs the field shows a spinner. A failed upload keeps the old image and says so. name posts the URL with the form.
import { ImageField } from "@percentsa/ui";Examples
Square, PNG or JPG
Code
export function ImageFieldExample() {
const t = useT();
const [logo, setLogo] = useState<string | null>(null);
return (
<Field label={t("Store logo", "شعار المتجر")} hint={t("Square, PNG or JPG", "مربع، بصيغة PNG أو JPG")} className="w-full max-w-md">
<ImageField
value={logo}
onValueChange={setLogo}
// A real app sends the file to its storage and returns the file's URL.
upload={(file) => new Promise((done) => setTimeout(() => done(URL.createObjectURL(file)), 800))}
alt={t("Store logo", "شعار المتجر")}
aspect="1 / 1"
name="logo"
/>
</Field>
);
}