Skip to content

DropZone

File drop target that wraps arbitrary content. Shows an overlay on drag-over with optional file type validation via the accept prop.

import { DropZone } from "phoundry-ui";

Basic

Loading interactive example…

View source
basic.svelte
<script lang="ts">
import { DropZone } from "phoundry-ui";
let droppedFiles = $state<string[]>([]);
function handleDrop(files: File[]) {
droppedFiles = files.map(
(f) => `${f.name} (${(f.size / 1024).toFixed(1)} KB)`,
);
}
</script>
<DropZone ondrop={(files) => handleDrop(files)}>
<div
class="rounded-lg border-2 border-dashed border-border-muted p-8 text-center text-xs text-txt-tertiary"
>
<p>Drag files here to upload</p>
<p class="mt-1 text-[10px]">
Drop overlay appears automatically on drag-over
</p>
</div>
</DropZone>
{#if droppedFiles.length > 0}
<div class="mt-2 text-xs text-txt-secondary">
<p class="font-medium">Dropped:</p>
<ul class="list-inside list-disc">
{#each droppedFiles as f (f)}
<li>{f}</li>
{/each}
</ul>
</div>
{/if}

With Accept Filter (images only)

Loading interactive example…

View source
with-accept-filter-images-only.svelte
<script lang="ts">
import { DropZone } from "phoundry-ui";
let imageFiles = $state<string[]>([]);
function handleImageDrop(files: File[]) {
imageFiles = files.map((f) => f.name);
}
</script>
<DropZone ondrop={(files) => handleImageDrop(files)} accept={["image/*"]}>
<div
class="rounded-lg border-2 border-dashed border-border-muted p-8 text-center text-xs text-txt-tertiary"
>
<p>Drop images only (*.png, *.jpg, etc.)</p>
<p class="mt-1 text-[10px]">Non-image files will show an error overlay</p>
</div>
</DropZone>
{#if imageFiles.length > 0}
<div class="mt-2 text-xs text-txt-secondary">
<p class="font-medium">Accepted images:</p>
<ul class="list-inside list-disc">
{#each imageFiles as f (f)}
<li>{f}</li>
{/each}
</ul>
</div>
{/if}

Disabled

Loading interactive example…

View source
disabled.svelte
<script lang="ts">
import { DropZone } from "phoundry-ui";
</script>
<DropZone ondrop={() => {}} disabled>
<div
class="rounded-lg border-2 border-dashed border-border-muted p-6 text-center text-xs text-txt-tertiary"
>
Uploads disabled - drag still shows browser cursor but this zone ignores it.
</div>
</DropZone>

Custom active overlay

Loading interactive example…

View source
custom-active-overlay.svelte
<script lang="ts">
import { DropZone } from "phoundry-ui";
let droppedFiles = $state<string[]>([]);
function handleDrop(files: File[]) {
droppedFiles = files.map(
(f) => `${f.name} (${(f.size / 1024).toFixed(1)} KB)`,
);
}
</script>
{#snippet releaseHint()}
<div
class="rounded-lg bg-accent-primary/15 p-4 text-center text-sm font-medium text-accent-secondary"
>
Release to import
</div>
{/snippet}
<DropZone ondrop={(files) => handleDrop(files)} active={releaseHint}>
<div
class="rounded-lg border-2 border-dashed border-border-muted p-8 text-center text-xs text-txt-tertiary"
>
Custom overlay replaces the default “Drop to upload” chrome.
</div>
</DropZone>

API

From phoundry-ui@0.4.21

NameTypeDefaultDescription
ondroprequired(files: File[], event: DragEvent) => void—Called with accepted files on drop.
acceptstring[]—MIME types or extensions to accept (e.g. ['image/*', '.pdf']).
disabledbooleanfalseDisable the drop zone.
classClassValue—Additional CSS classes on the wrapper.
stylestring—Inline styles on the stable component root.
childrenSnippet<[]>—Default content inside the drop zone.
activeSnippet<[]>—Custom overlay content shown during drag-over.

Usage tips

  • The default overlay shows “Drop to upload” on valid drag and “Invalid file type” when files don’t match accept.
  • Use the active snippet to fully customize the drag-over overlay.
  • The accept array supports MIME types ('image/*'), exact MIME ('application/pdf'), and extensions ('.csv').
  • Files that don’t match accept are silently filtered out of the ondrop callback.

Styling

.ph-drop-zone is the stable root hook. Consumer class values are additive, and style applies to that root. Styling uses vanilla CSS with semantic state attributes. The root exposes data-dragging, data-invalid, and aria-disabled. CSS owns valid/invalid overlay colors, while drag counters, accept filtering, drop callbacks, and the optional active snippet retain their existing behavior. Overlay text uses the Theme’s on-accent foreground; reduced motion removes its color transition. Internal part selectors and --_ph-* properties remain implementation details.

Documentation is licensed under CC BY 4.0. Phoundry names and marks remain reserved.