# FileInputList

FileInput with the chosen files listed below the zone: each row shows an icon in the color of the file type (a thumbnail for images), the name, the size and a button that removes it. While files are listed the zone becomes a single line (`compact`). The app can show the upload of each file with `fileStatus`: a progress bar, a check when it is done, an error with its message. `view="grid"` shows cards with large thumbnails instead of rows; `readonly` shows only the list. It takes every prop of FileInput (`accept`, `maxSize`, `maxFiles`, `replace`, `name`, ...), and its zone is styled with the `--file-input-*` variables of FileInput. `--file-input-list-height` sets the height of the whole field, and the list scrolls when it does not fit.

```ts
import { FileInputList } from '@likable-hair/svelte';
```

Category: simple. Source: `src/lib/components/simple/forms/FileInputList.svelte`.

## Examples

### Basic

The chosen files are listed below the zone with an icon in the color of their type, the size and a button that removes them; images show a thumbnail. While files are listed the zone shrinks to one line. `bind:files` holds the list, so the app sends it when the form is saved.

```svelte
<script lang="ts">
	import { FileInputList } from '@likable-hair/svelte';

	let files: File[] = $state([
		new File([new Uint8Array(284_000)], 'invoice_2026_09.pdf', { type: 'application/pdf', lastModified: 0 }),
		new File([new Uint8Array(1_200_000)], 'service_price_list.xlsx', {
			type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
			lastModified: 0
		}),
		new File([new Uint8Array(48_500)], 'opening_hours.docx', {
			type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
			lastModified: 0
		})
	]);
</script>

<div class="demo">
	<FileInputList label="Attachments" description="PDF, Office files up to 10 MB" maxSize={10_000_000} bind:files />
	<p>{files.length} files ready to be saved</p>
</div>

<style>
	.demo {
		display: grid;
		gap: 12px;
		width: 100%;
		max-width: 420px;
	}

	p {
		margin: 0;
		font-size: 13px;
	}
</style>
```

### Upload progress

`fileStatus` tells each row how its upload is going: a progress bar while `uploading` (with `progress` from 0 to 100), a check when `done`, an alert and the message on `error`. Here every added file is "uploaded" with a timer; a `SvelteMap` keeps the states reactive. Removing a file is reported by `onchange` as `removed`, so the app can stop its upload.

```svelte
<script lang="ts">
	import { FileInputList, type FileStatus } from '@likable-hair/svelte';
	import { SvelteMap } from 'svelte/reactivity';

	const invoice = new File([new Uint8Array(284_000)], 'invoice_2026_09.pdf', {
		type: 'application/pdf',
		lastModified: 0
	});
	const photo = new File([new Uint8Array(2_400_000)], 'before_after_color.jpg', { lastModified: 0 });
	const archive = new File([new Uint8Array(31_000_000)], 'salon_photos_2025.zip', {
		type: 'application/zip',
		lastModified: 0
	});

	let files: File[] = $state([invoice, photo, archive]);
	const statuses = new SvelteMap<File, FileStatus>([
		[invoice, { state: 'done' }],
		[photo, { state: 'uploading', progress: 64 }],
		[archive, { state: 'error', message: 'larger than the 25 MB limit' }]
	]);

	function upload(file: File) {
		let progress = 0;
		statuses.set(file, { state: 'uploading', progress });
		const timer = setInterval(() => {
			if (!statuses.has(file)) return clearInterval(timer);
			progress = Math.min(100, progress + 20);
			statuses.set(file, progress < 100 ? { state: 'uploading', progress } : { state: 'done' });
			if (progress === 100) clearInterval(timer);
		}, 400);
	}
</script>

<div class="demo">
	<FileInputList
		label="Documents"
		bind:files
		fileStatus={(file) => statuses.get(file)}
		onchange={({ added, removed }) => {
			added.forEach(upload);
			removed.forEach((file) => statuses.delete(file));
		}}
	/>
</div>

<style>
	.demo {
		width: 100%;
		max-width: 420px;
	}
</style>
```

### Grid

`view="grid"` shows a card for each file, with a large thumbnail for images: handy for photos and media. `accept="image/*"` keeps other files out.

```svelte
<script lang="ts">
	import { FileInputList } from '@likable-hair/svelte';

	function swatch(name: string, from: string, to: string) {
		const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 120"><defs><linearGradient id="g" x2="1" y2="1"><stop offset="0" stop-color="${from}"/><stop offset="1" stop-color="${to}"/></linearGradient></defs><rect width="160" height="120" fill="url(#g)"/><circle cx="118" cy="38" r="18" fill="#fff" fill-opacity=".55"/></svg>`;
		return new File([svg], name, { type: 'image/svg+xml', lastModified: 0 });
	}

	let photos: File[] = $state([
		swatch('copper_balayage.svg', '#b4532a', '#f2c48d'),
		swatch('ash_blonde.svg', '#8d8f9c', '#e9e4d8'),
		swatch('midnight_blue.svg', '#16234d', '#4d8dff'),
		new File([new Uint8Array(820_000)], 'treatment_card.pdf', { type: 'application/pdf', lastModified: 0 })
	]);
</script>

<div class="demo">
	<FileInputList label="Portfolio" view="grid" bind:files={photos} description="Photos and cards" />
</div>

<style>
	.demo {
		width: 100%;
		max-width: 520px;
	}
</style>
```

### A single file

With `maxFiles={1}` the picker chooses one file and the zone is disabled once it is in the list: remove it to choose another. With `replace` instead, a new file takes the place of the old one and the zone stays active.

```svelte
<script lang="ts">
	import { FileInputList } from '@likable-hair/svelte';

	let priceList: File[] = $state([
		new File([new Uint8Array(96_000)], 'price_list_2026.csv', { type: 'text/csv', lastModified: 0 })
	]);
	let logo: File[] = $state([]);
</script>

<div class="demo">
	<FileInputList label="Price list" accept=".xlsx,.csv" maxFiles={1} bind:files={priceList} />
	<FileInputList label="Salon logo" accept="image/png,image/svg+xml" maxFiles={1} replace bind:files={logo} />
</div>

<style>
	.demo {
		display: grid;
		gap: 16px;
		width: 100%;
		max-width: 420px;
	}
</style>
```

### Read-only

`readonly` shows only the list, without the zone and the remove buttons, for a record that cannot be edited. With no files it says so (`emptyLabel`).

```svelte
<script lang="ts">
	import { FileInputList } from '@likable-hair/svelte';

	const contract = [
		new File([new Uint8Array(512_000)], 'master_agreement_signed.pdf', { type: 'application/pdf', lastModified: 0 })
	];
</script>

<div class="demo">
	<FileInputList label="Master agreement" readonly files={contract} />
	<FileInputList label="Purchase order" readonly files={[]} emptyLabel="No purchase order yet" />
</div>

<style>
	.demo {
		display: grid;
		gap: 16px;
		width: 100%;
		max-width: 420px;
	}
</style>
```

### In a form

`name` sends the listed files with the form and `required` blocks the submission while the list is empty, as with a native file input; resetting the form empties the list. Here the form data is printed instead of being sent.

```svelte
<script lang="ts">
	import { Button, FileInputList } from '@likable-hair/svelte';

	let sent = $state('');

	function submit(event: SubmitEvent & { currentTarget: HTMLFormElement }) {
		event.preventDefault();
		const data = new FormData(event.currentTarget);
		sent = data
			.getAll('attachments')
			.map((value) => (value instanceof File ? value.name : value))
			.join(', ');
	}
</script>

<form class="demo" onsubmit={submit} onreset={() => (sent = '')}>
	<FileInputList label="Attachments" name="attachments" required />
	<div class="actions">
		<Button type="reset" buttonType="text">Reset</Button>
		<Button type="submit">Send</Button>
	</div>
	{#if sent}<p>Sent: {sent}</p>{/if}
</form>

<style>
	.demo {
		display: grid;
		gap: 12px;
		width: 100%;
		max-width: 420px;
	}

	.actions {
		display: flex;
		justify-content: flex-end;
		gap: 8px;
	}

	p {
		margin: 0;
		font-size: 13px;
	}
</style>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `view` | `'list' \| 'grid'` | `'list'` | `list`: one row per file. `grid`: cards with a large thumbnail for images. |
| `compact` | `boolean \| 'auto'` | `'auto'` | One-line zone. `auto` makes it compact while files are listed. |
| `readonly` | `boolean` | `false` | Shows only the list: no zone and no remove buttons. With no files it says "No files". |
| `fileStatus` | `(file: File) => FileStatus \| undefined` |  | Upload state of a file, read for each row: progress, done or error, and a message. It can read reactive state (`$state`, `SvelteMap`). |
| `removeLabel` | `string` |  | Tooltip of the remove buttons. Defaults to "Remove", in the language of `locale`. |
| `emptyLabel` | `string` |  | Text of the empty list with `readonly`. Defaults to "No files", in the language of `locale`. |
| `class` | `{ container?: string; label?: string; zone?: string; hint?: string; list?: string; item?: string; }` | `{}` | Extra classes for each part. |

### From FileInput

It accepts the props, snippets and events of FileInput (`/components/file-input.md`), listed in the tables "From FileInput". Except `children`.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `files` (bindable) | `File[]` |  | The chosen files. Bind it to read them and to remove or replace them from the app. |
| `accept` | `string` |  | Native `accept`: extensions (`.pdf`) and MIME types (`image/*`, `application/pdf`), comma separated. Dropped files are checked too. |
| `maxSize` | `number` |  | Largest accepted file, in bytes (decimal units: 10 MB = `10_000_000`). |
| `maxFiles` | `number` |  | Most files the list can hold. When it is full the zone is disabled; with `1` the picker chooses a single file. |
| `replace` | `boolean` | `false` | New files replace the ones in `files` instead of being added to them. The zone never counts as full. |
| `disabled` | `boolean` | `false` | Disables the zone and the native input. |
| `label` | `string` |  | Visible label above the zone, linked to the input. |
| `hint` | `string` |  | Text below the zone. With `state` it becomes the error or success message. |
| `state` | `'error' \| 'success'` |  | Validation state: colors the zone border and the hint. `error` also sets `aria-invalid`. Refused files show an error on their own. |
| `icon` | `string` | `UPLOAD_ICON` | SVG path of the icon in the zone. Defaults to a cloud with an arrow. |
| `title` | `string` |  | Main text of the zone. Defaults to "Drop files here" ("Drop a file here" with `maxFiles={1}`), in the language of `locale`. |
| `description` | `string` |  | Text after the browse link, such as the accepted formats and size ("PDF, JPG up to 10 MB"). |
| `browseLabel` | `string` |  | The highlighted words after "or". Defaults to "browse your files", in the language of `locale`. |
| `locale` | `string` |  | BCP 47 locale of the texts and of the sizes in the messages (`it` and `en` are built in, other languages fall back to English). Defaults to the one set with `setDefaultLocale`, else `en`. |
| `id` | `string` |  | `id` of the input. Generated when missing, so the label always points to the input. |
| `name` | `string` |  | Native `name`: the files are sent with the form under this name. |
| `required` | `boolean` |  | Native `required`: a form with no files does not submit. |
| `input` (bindable) | `HTMLInputElement` |  | The native `<input type="file">`. |

It also accepts the native attributes and events of `<input>` (for example `id`, `title`, `aria-label`, `onkeydown`), which are forwarded to the element.

## Snippets

| Name | Parameters | Description |
| --- | --- | --- |
| `fileSnippet` | `{ file: File; kind: FileKind; status: FileStatus \| undefined; remove: () => void }` | Replaces the content of a row or card. `remove` takes the file out of the list. |
| `fileIconSnippet` | `{ file: File; kind: FileKind }` | Replaces the icon or thumbnail of a file. |
| `fileListSnippet` | `{ files: File[]; remove: (file: File) => void }` | Replaces the whole list. `remove` takes a file out of it. |

### From FileInput

| Name | Parameters | Description |
| --- | --- | --- |
| `labelSnippet` | `{ label: string \| undefined }` | Replaces the label content. It stays linked to the input. |
| `bodySnippet` | `{ dragging: boolean; disabled: boolean }` | Replaces the content of the zone (icon and texts). `disabled` is also true when the zone is full. |
| `hintSnippet` | `{ hint: string \| undefined }` | Replaces the hint below the zone. |
| `rejectedSnippet` | `{ rejected: FileRejection[] }` | Replaces the messages about refused files. |

## Events

### From FileInput

| Name | Type | Description |
| --- | --- | --- |
| `onchange` | `(event: { files: File[]; added: File[]; removed: File[] }) => void` | Called whenever the files change: dropped or picked files (`added`), files replaced with `replace` (`removed`), form reset. |
| `onreject` | `(event: { rejected: FileRejection[] }) => void` | Called with the files that were refused and the reason of each. |

## Types

Exported by the package: `import type { FileStatus, FileKind, FileRejection } from '@likable-hair/svelte';`

### FileStatus

Upload state of one file of a FileInputList, returned by its `fileStatus` function.

`interface FileStatus`

| Name | Type | Description |
| --- | --- | --- |
| `state` | `'uploading' \| 'done' \| 'error'` | `uploading` shows a progress bar, `done` a check, `error` an alert icon and the message in the error color. |
| `progress` | `number` | Upload progress from 0 to 100, shown while `state` is `uploading`. Leave it out for a bar of unknown length. |
| `message` | `string` | Text after the file size, such as "Uploaded" or the reason of an error. Defaults to a text for `done` and `error`. |

### FileKind

Family of a file, from its MIME type or extension: it picks the icon and color of its row in FileInputList.

`type FileKind = 'pdf' \| 'image' \| 'spreadsheet' \| 'document' \| 'presentation' \| 'archive' \| 'video' \| 'audio' \| 'other'`

### FileRejection

A file that FileInput or FileInputList did not add, and why.

`interface FileRejection`

| Name | Type | Description |
| --- | --- | --- |
| `file` (required) | `File` | The refused file. |
| `reason` (required) | `'type' \| 'size' \| 'count' \| 'duplicate'` | `type`: not matched by `accept`; `size`: larger than `maxSize`; `count`: over `maxFiles`; `duplicate`: the same file (name, size and date) is already in the list. |

## CSS variables

For a single instance, pass them as style props: `<FileInputList --file-input-list-item-border-color="tomato">`. The `--file-input-list-default-*` defaults apply to the whole app: override them in `:root` or in a theme.

It also takes the variables of FileInput (`/components/file-input.md`).

| Per-instance variable | Default |
| --- | --- |
| `--file-input-list-width` | `--file-input-list-default-width`: `100%` |
| `--file-input-list-height` | `--file-input-list-default-height`: `auto` |
| `--file-input-list-gap` | `--file-input-list-default-gap`: `8px` |
| `--file-input-list-card-min-width` | `--file-input-list-default-card-min-width`: `140px` |
| `--file-input-list-item-gap` | `--file-input-list-default-item-gap`: `10px` |
| `--file-input-list-item-padding` | `--file-input-list-default-item-padding`: `8px 10px` |
| `--file-input-list-item-border-width` | `--file-input-list-default-item-border-width`: `var(--global-border-width)` |
| `--file-input-list-item-border-color` | `--file-input-list-default-item-border-color`: `var(--global-color-border)` |
| `--file-input-list-item-border-radius` | `--file-input-list-default-item-border-radius`: `var(--global-radius-md)` |
| `--file-input-list-item-background` | `--file-input-list-default-item-background`: `var(--global-color-surface-solid)` |
| `--file-input-list-icon-size` | `--file-input-list-default-icon-size`: `20px` |
| `--file-input-list-icon-box-size` | `--file-input-list-default-icon-box-size`: `32px` |
| `--file-input-list-icon-border-radius` | `--file-input-list-default-icon-border-radius`: `var(--global-radius-sm)` |
| `--file-input-list-icon-background` |  |
| `--file-input-list-icon-color` |  |
| `--file-input-list-name-color` | `--file-input-list-default-name-color`: `var(--global-color-text)` |
| `--file-input-list-name-font-size` | `--file-input-list-default-name-font-size`: `13.5px` |
| `--file-input-list-name-font-weight` | `--file-input-list-default-name-font-weight`: `500` |
| `--file-input-list-details-color` | `--file-input-list-default-details-color`: `var(--global-color-text-3)` |
| `--file-input-list-details-font-family` | `--file-input-list-default-details-font-family`: `var(--global-font-family-mono)` |
| `--file-input-list-details-font-size` | `--file-input-list-default-details-font-size`: `11.5px` |
| `--file-input-list-progress-height` | `--file-input-list-default-progress-height`: `4px` |
| `--file-input-list-status-icon-size` | `--file-input-list-default-status-icon-size`: `20px` |
| `--file-input-list-done-color` | `--file-input-list-default-done-color`: `var(--global-color-success)` |
| `--file-input-list-error-color` | `--file-input-list-default-error-color`: `var(--global-color-error)` |
| `--file-input-list-card-icon-size` | `--file-input-list-default-card-icon-size`: `36px` |
| `--file-input-list-card-media-height` | `--file-input-list-default-card-media-height`: `96px` |
| `--file-input-list-empty-color` | `--file-input-list-default-empty-color`: `var(--global-color-text-3)` |
| `--file-input-list-empty-font-size` | `--file-input-list-default-empty-font-size`: `13px` |

### Other defaults

| Variable | Value |
| --- | --- |
| `--file-input-list-default-pdf-color` | `var(--global-color-error)` |
| `--file-input-list-default-image-color` | `var(--global-color-primary)` |
| `--file-input-list-default-spreadsheet-color` | `var(--global-color-accent)` |
| `--file-input-list-default-document-color` | `var(--global-color-data-3)` |
| `--file-input-list-default-presentation-color` | `var(--global-color-data-5)` |
| `--file-input-list-default-archive-color` | `var(--global-color-warning)` |
| `--file-input-list-default-video-color` | `var(--global-color-data-6)` |
| `--file-input-list-default-audio-color` | `var(--global-color-data-4)` |
| `--file-input-list-default-other-color` | `var(--global-color-text-2)` |
