file-drop
A place to drop files, or click to choose them, on a native <input type="file">, so the chosen files submit with the form under name and the keyboard opens the picker as usual. Files are listed with their size and can be removed. accept limits the types (".pdf,image/*"), multiple allows several, and max-size (in MB) turns away files that are too big, saying so.
Try it: events appear here (fileschange).
Source: file-drop.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/file-drop.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/file-drop.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/file-drop.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/file-drop.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/file-drop.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/file-drop.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/file-drop.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/file-drop.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/file-drop.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/file-drop.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/file-drop.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/file-drop.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/file-drop.js"></script>The compiled install writes src/components/zubra/file-drop.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<file-drop label="Attachments" name="files" accept=".pdf,image/*"></file-drop>
<script type="module">
import './components/zubra/file-drop.js';
const element = document.querySelector('file-drop');
element.maxSize = 10;
element.addEventListener('fileschange', (event) => console.log('fileschange', event.detail));
</script>import './components/zubra/file-drop.js';
const maxSize = 10;
export function FileDropExample() {
return (
<file-drop
label="Attachments"
name="files"
accept=".pdf,image/*"
maxSize={maxSize}
onfileschange={(event) => console.log('fileschange', event.detail)}
></file-drop>
);
}<script setup>
import './components/zubra/file-drop.js';
const maxSize = 10;
const onFileschange = (event) => console.log('fileschange', event.detail);
</script>
<template>
<file-drop
label="Attachments"
name="files"
accept=".pdf,image/*"
:maxSize.prop="maxSize"
@fileschange="onFileschange"
></file-drop>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/file-drop.js';
const maxSize = 10;
</script>
<file-drop
label="Attachments"
name="files"
accept=".pdf,image/*"
{maxSize}
onfileschange={(event) => console.log('fileschange', event.detail)}
></file-drop>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/file-drop.js';
@Component({
selector: 'app-file-drop-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<file-drop
label="Attachments"
name="files"
accept=".pdf,image/*"
[maxSize]="maxSize"
(fileschange)="onFileschange($event)"
></file-drop>
`,
})
export class FileDropExample {
maxSize = 10;
onFileschange(event: Event) {
console.log('fileschange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
label | string | "Attachments" |
hint | string | "" |
name | string | "" |
accept | string | "" |
multiple | boolean | true |
maxSizeattribute max-size | number | 0 |
disabled | boolean | false |
capture | string | "" |
look | string | "zone" |
| Event | When |
|---|---|
fileschange | The chosen files changed; detail is the array of File objects. |
Size
2.5 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 19.2 KB.