Documentation / Forms
FileSelector
The file selector: a drop zone (drag and drop or click) or a plain button, which validates each file against accept and maxSize (10 MB by default) and lists the selection with each file’s size. mode picks what it accepts: files, a folder (traversed recursively, through webkitdirectory), or both.
Controlled (value + onChange, which returns a File[]) or not. A rejected file does not enter the selection and is not reported on screen: onReject(file, reason) is what lets you announce it, for instance in error. Beyond maxFiles, the extra files are silently ignored.
Client component ("use client"). Its texts, rejection reasons included, are fileSelector… labels: English by default, French under <UILabelsProvider labels={frenchUILabels}>. For one instance, placeholder, browseLabel, browseFolderLabel and the labels prop win over the provider.
Examples
Basic usage
Uncontrolled: the drop zone keeps the selection, onChange passes it on at each addition.
import { FileSelector } from "@synertech/ui";
export function Basic() {
return (
<FileSelector
label="Pièce jointe"
placeholder="Glissez un fichier ici, ou"
browseLabel="parcourir"
onChange={(files) =>
console.log(
"Sélection :",
files.map((f) => f.name)
)
}
/>
);
}Several files, controlled
multiple and maxFiles cap the selection; onReject explains the rejections.
import { useState } from "react";
import { FileSelector } from "@synertech/ui";
export function Multiple() {
const [files, setFiles] = useState<File[]>([]);
const [rejection, setRejection] = useState<string>();
return (
<FileSelector
label="Justificatifs"
multiple
maxFiles={5}
maxSize={5 * 1024 * 1024}
accept=".pdf,image/*"
placeholder="Déposez vos justificatifs ici, ou"
browseLabel="parcourir"
value={files}
onChange={(next) => {
setFiles(next);
setRejection(undefined);
}}
onReject={(file) => setRejection(`« ${file.name} » refusé : PDF ou image de 5 Mo maximum.`)}
error={rejection}
helperText={`${files.length} / 5 fichiers`}
/>
);
}Button variant
variant="button" replaces the drop zone with a compact button, for a dense form.
import { FileSelector } from "@synertech/ui";
export function ButtonVariant() {
return (
<FileSelector
variant="button"
size="sm"
label="CV"
accept=".pdf,.docx"
browseLabel="Choisir un fichier"
helperText="PDF ou Word."
/>
);
}Folders
mode="directory" selects a whole folder; mode="both" offers both buttons. A folder is a list of files: both modes keep all of them, with or without multiple.
import { FileSelector } from "@synertech/ui";
export function Directories() {
return (
<div className="flex flex-col gap-6">
<FileSelector
mode="directory"
label="Dossier du projet"
placeholder="Glissez un dossier ici, ou"
browseLabel="choisir un dossier"
/>
<FileSelector
mode="both"
multiple
label="Documents à importer"
placeholder="Glissez des fichiers ou des dossiers ici, ou"
browseLabel="Fichiers"
browseFolderLabel="Dossier"
/>
</div>
);
}Uploading an import
A real case: the controlled selection is sent then cleared; readOnly freezes it during the upload.
import { useState } from "react";
import { Button, FileSelector } from "@synertech/ui";
export function UploadForm() {
const [files, setFiles] = useState<File[]>([]);
const [sending, setSending] = useState(false);
const send = async () => {
setSending(true);
const body = new FormData();
files.forEach((file) => body.append("files", file));
await fetch("/api/imports", { method: "POST", body });
setSending(false);
setFiles([]);
};
return (
<form
className="flex flex-col gap-3"
onSubmit={(event) => {
event.preventDefault();
void send();
}}
>
<FileSelector
label="Fichiers CSV"
multiple
accept=".csv"
placeholder="Glissez vos exports CSV ici, ou"
browseLabel="parcourir"
value={files}
onChange={setFiles}
readOnly={sending}
/>
<Button type="submit" loading={sending} disabled={files.length === 0} className="self-end">
Importer {files.length > 0 && `(${files.length})`}
</Button>
</form>
);
}API reference
Components
import { FileSelector } from "@synertech/ui";Props — FileSelectorProps
| Prop | Type | Default | Description |
|---|---|---|---|
accept |
string |
— | Accepted file types (MIME types or extensions, e.g. "image/*,.pdf,.docx"), checked on every file, dropped ones included. Checked in the browser only: a name and a type are what the reader's machine says they are, and the server that receives the files checks again. |
browseFolderLabel |
string |
— | Custom text for the browse folder button (used in "directory" and "both" modes) |
browseLabel |
string |
— | Custom text for the browse button |
className |
string |
— | Additional class names |
disabled |
boolean |
false |
Disabled state |
error |
boolean | string |
— |
|
helperText |
string |
— | Written under the field; a message passed as |
icon |
ReactNode |
— | Custom icon for the dropzone |
label |
string |
— | Label text |
labels |
UILabelsOf<"fileSelector"> |
— | The strings the selector writes itself, for this instance: any |
maxFiles |
number |
— | Maximum number of files, wherever several can be selected |
maxSize |
number |
10 * 1024 * 1024 |
Maximum file size in bytes (default: 10MB). Checked in the browser only, like |
mode |
"file" | "directory" | "both" |
"file" |
Selection mode: file only, directory only, or both. A directory is handed to |
multiple |
boolean |
false |
Allow several files to be selected. Only |
onChange |
(files: File[]) => void |
— | Callback when files change |
onReject |
(file: File, reason: string) => void |
— | Called for each file left out — too large, of a type |
placeholder |
string |
— | Custom placeholder text for dropzone |
readOnly |
boolean |
false |
Read-only state (shows files but can't change) |
showFileList |
boolean |
true |
Show file list below the selector |
size |
"sm" | "md" | "lg" |
"md" |
Component size |
value |
File[] |
— | Currently selected files (controlled mode) |
variant |
"dropzone" | "button" |
"dropzone" |
Visual variant |
Types
SelectedFile
Interfaceinterface SelectedFile| Field | Type | Default | Description |
|---|---|---|---|
file• |
File |
— | |
id• |
string |
— | |
error |
string |
— |