FileField
Choose and upload one file.
$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/file-field.jsonStates
logo-final.pdf tidak bisa dipakai. Pilih PNG atau JPG, paling besar 1 MB.
Controlled with validation
Upload to done (motion)
When to use
- Attach one file to a form: Surat dokter (Cuti sakit), Bukti (Minta perubahan ke HR), Dokumen karyawan, Logo.
When not to use
- Many rows of data from Excel → the Impor flow (its own page with a stepper).
- Several files at once → one FileField per file, or the Dokumen tab upload sheet.
Do and don't
Say which files are allowed before the pickThe drop zone shows type and size. The error repeats the rule and names the file.
Line-draw the chosen fileA chosen file is a thing the user picked, so it is raised (--shadow-button), not drawn with the --input line.
Installation
Add FileField with the shadcn CLI (your project needs a components.json and the MaHR theme: https://mahrdesign.faizintifada.com/r/theme.json), or copy the files by hand.
API
import { FileField } from "@/components/ui/file-field"| Prop | Type | Default | Description |
|---|---|---|---|
value | { name: string; size: number } | null | – | The chosen file. Null = empty drop zone. |
onChange | (file: File | null) => void | – | Validate type and size here. |
accept | string | – | ".pdf,.jpg,.jpeg". Generates the rule text. |
maxSize | number (bytes) | – | Shown as "paling besar 2 MB". |
hint | string | – | Overrides the generated rule text ("PDF, JPG atau PNG · paling besar 5 MB"). |
prompt | ReactNode | – | Overrides the first line of the empty zone. Karyawan · Detail: "Tarik file ke sini, atau pilih file" ("pilih file" in primary). |
progress · onCancelUpload | number 0–100 · () => void | – | Uploading state. |
uploaded | boolean | false | Set true when the upload is done: the badge morphs to the green check and the meta says "Terunggah". |
dragging · invalid · disabled | boolean | – | Visual states. |
meta | ReactNode | – | Chosen row, idle: replaces the size line. Impor: "48 baris · 11 kolom · 86 KB" after the file was read. |
status | ReactNode | – | Chosen row, idle: one short status before "Ganti", e.g. green check + "Siap dibaca" (text-success-text). Hidden while uploading. |
FileTile name · kind · size | string · "pdf" | "image" | "sheet" | "doc" | "other" · 44 | 48 | 56 | kind from the name · 44 | The type tile on its own (rows, file cards). "sheet" = .xlsx/.xls/.csv, green spreadsheet glyph (--file-sheet). |