Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (4.9 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
labelstring"Attachments"
hintstring""
namestring""
acceptstring""
multiplebooleantrue
maxSize
attribute max-size
number0
disabledbooleanfalse
capturestring""
lookstring"zone"
Events
EventWhen
fileschangeThe 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour