File input
A button and a drop target, the list of chosen files with a remove button each, and the limits.
import { FileInput, formatFileSize } from "@forgeron/ui";Drop files here, orimage/*, .pdf · up to 5 MB
import { FileInput, type FileRejection } from "@forgeron/ui";
import { useState } from "react";
export default function Attachments() {
const [refused, setRefused] = useState<FileRejection[]>([]);
return (
<div style={{ display: "grid", gap: 8 }}>
<FileInput
label="Attachments"
multiple
accept="image/*,.pdf"
maxSize={5 * 1024 * 1024}
maxFiles={3}
onReject={setRefused}
/>
{refused.length > 0 ? (
<code>{refused.map((r) => `${r.file.name}: ${r.reason}`).join(", ")}</code>
) : null}
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the field for assistive technology. |
value / defaultValue | File[] | — | Controlled or not. |
onChange | (files: File[]) => void | — | On every change. |
accept | string | — | `image/*,.pdf`. Checked on a drop too. |
multiple | boolean | false | Several files; else a new one replaces the old. |
maxSize / maxFiles | number | — | Bytes, and a count. |
onReject | (rejections) => void | — | { file, reason: "type" | "size" | "count" }[]: tell the person. |
hint | string | — | The line in the drop target. |
disabled | boolean | — | Not editable. |
className | string | — | Extra classes. |