Image Drop

A slot for one image that becomes the picture when one lands: it squashes, springs back, and a line of light draws around the picture with a glow outside it in the accent and brand colours that lingers a moment, then fades. Drag the paired chip onto it, drop a file from the desktop, or click to pick one. A new picture dropped on a full slot replaces the old one.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/image-drop.json

Usage

import { ImageDrop, ImageDropChip, ImageDropSlot } from "@/components/motion/image-drop"

Examples

Default

Drag the chip onto the slot, or drop or pick an image file. Let go anywhere else and the chip springs home. Drop a file on the full slot to replace the picture. Clear it with its corner button and the chip comes back.

Cover photo

size="fill" takes the container's box, so a wide slot works for a cover or a canvas. The line of light follows the slot's shape and corner. Drag the sample picture in, or drop your own: a file stays in the browser and is never uploaded.

API Reference

PropTypeDefaultDescription
src*ImageDropChipstringNoneThe picture the chip carries. It becomes the slot's picture when it lands.
altImageDropChip, ImageDropSlotstringNoneOn the chip, what the picture shows. On the slot, alt text for any landed picture, which wins over the chip's.
labelImageDropChipstring"Use this image"The chip's accessible name. Enter or Space on the chip places it in the slot.
sizeImageDropSlot"sm" | "md" | "lg" | "fill""md"Square at 80, 104 or 160px, or fill to take the container's box.
labelImageDropSlotstring"Drop an image or browse"The line in the empty slot, and its file input's accessible name.
acceptImageDropSlotstring"image/*"What a dropped or picked file may be, in the file input's own syntax.
maxSizeImageDropSlotnumberNoneThe largest file it takes, in bytes.
glowImageDropSlotbooleantrueOn landing, a line of light draws around the picture with a glow outside it in the accent and brand colours, lingers a moment and fades. It needs about 200px of room around the slot. Always off under reduced motion.
stillImageDropSlotbooleanfalseLand and clear without moving: the picture simply appears.
defaultSrcImageDropSlotstringNoneA picture already in the slot, shown still.
onDropImageDropSlot(landing: ImageDropLanding) => voidNoneA picture landed. Gets src, alt, and file when it came from the desktop or the picker; a file's src is an object URL the slot lets go when cleared.
onRejectImageDropSlot(rejection: ImageDropRejection) => voidNoneA file was turned away, with why: type or size.
onClearImageDropSlot() => voidNoneThe slot was cleared with its corner button.
disabledImageDropSlotbooleanfalseTakes no chip and no file.
src*ImageDropChipstringThe picture the chip carries. It becomes the slot's picture when it lands.
altImageDropChip, ImageDropSlotstringOn the chip, what the picture shows. On the slot, alt text for any landed picture, which wins over the chip's.
labelImageDropChipstring = "Use this image"The chip's accessible name. Enter or Space on the chip places it in the slot.
sizeImageDropSlot"sm" | "md" | "lg" | "fill" = "md"Square at 80, 104 or 160px, or fill to take the container's box.
labelImageDropSlotstring = "Drop an image or browse"The line in the empty slot, and its file input's accessible name.
acceptImageDropSlotstring = "image/*"What a dropped or picked file may be, in the file input's own syntax.
maxSizeImageDropSlotnumberThe largest file it takes, in bytes.
glowImageDropSlotboolean = trueOn landing, a line of light draws around the picture with a glow outside it in the accent and brand colours, lingers a moment and fades. It needs about 200px of room around the slot. Always off under reduced motion.
stillImageDropSlotboolean = falseLand and clear without moving: the picture simply appears.
defaultSrcImageDropSlotstringA picture already in the slot, shown still.
onDropImageDropSlot(landing: ImageDropLanding) => voidA picture landed. Gets src, alt, and file when it came from the desktop or the picker; a file's src is an object URL the slot lets go when cleared.
onRejectImageDropSlot(rejection: ImageDropRejection) => voidA file was turned away, with why: type or size.
onClearImageDropSlot() => voidThe slot was cleared with its corner button.
disabledImageDropSlotboolean = falseTakes no chip and no file.