FileField

Choose and upload one file.

$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/file-field.json

States

Empty drop zone (dashed) · dragging · chosen file = RAISED row with type tile, name, size and "Ganti" · uploading with progress and "Batal" (same row height, bar on the bottom edge) · error.

buku-tabungan-mandiri.pdf420 KB

Foto buku tabungan, KTP atau kartu NPWP.

kontrak-2026.pdfMengunggah… 64%
Data karyawan PT Mencari Cinta.xlsx48 baris · 11 kolom · 86 KBSiap dibaca
logo-final.pdf tidak bisa dipakai. Pilih PNG atau JPG, paling besar 1 MB.

Controlled with validation

The rule text comes from accept + maxSize ("PDF atau JPG atau PNG, paling besar 5 MB."). The app validates and shows FieldError.

Upload to done (motion)

A fake upload: the spinner turns while the bar fills, then morphs to the green check. Press "Unggah lagi" to run it again.

buku-tabungan-mandiri.pdf420 KB

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

DoSay which files are allowed before the pickThe drop zone shows type and size. The error repeats the rule and names the file.
Don'tLine-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.

terminal
bunx --bun shadcn@latest add https://mahrdesign.faizintifada.com/r/file-field.json

API

import { FileField } from "@/components/ui/file-field"
PropTypeDefaultDescription
value{ name: string; size: number } | null–The chosen file. Null = empty drop zone.
onChange(file: File | null) => void–Validate type and size here.
acceptstring–".pdf,.jpg,.jpeg". Generates the rule text.
maxSizenumber (bytes)–Shown as "paling besar 2 MB".
hintstring–Overrides the generated rule text ("PDF, JPG atau PNG · paling besar 5 MB").
promptReactNode–Overrides the first line of the empty zone. Karyawan · Detail: "Tarik file ke sini, atau pilih file" ("pilih file" in primary).
progress · onCancelUploadnumber 0–100 · () => void–Uploading state.
uploadedbooleanfalseSet true when the upload is done: the badge morphs to the green check and the meta says "Terunggah".
dragging · invalid · disabledboolean–Visual states.
metaReactNode–Chosen row, idle: replaces the size line. Impor: "48 baris · 11 kolom · 86 KB" after the file was read.
statusReactNode–Chosen row, idle: one short status before "Ganti", e.g. green check + "Siap dibaca" (text-success-text). Hidden while uploading.
FileTile name · kind · sizestring · "pdf" | "image" | "sheet" | "doc" | "other" · 44 | 48 | 56kind from the name · 44The type tile on its own (rows, file cards). "sheet" = .xlsx/.xls/.csv, green spreadsheet glyph (--file-sheet).