Drag and Drop

A flexible drop zone component for handling file uploads or custom drag-and-drop interactions.

Example

Installation

Install following dependencies:

npm install react-aria-components tw-animate-css tailwindcss-react-aria-components class-variance-authority lucide-react clsx tailwind-merge motion

Add cn helper using clsx and twMerge for conditional class merging in Tailwind components.

lib/utils.ts

Copy and paste the following code into your project.

components/ui/core/drag-and-drop.tsx
npx @libravelui@latest add drag-and-drop

Anatomy

import { DragAndDrop } from "@/components/ui/core/drag-and-drop";
<DragAndDrop
  label="Upload your files"
  description="Drag files here or click to select"
  badge="Supported: images, videos, docs"
  acceptedFileType={[
    "image/png",
    "image/jpeg",
    "video/mp4",
    "application/pdf",
    "text/plain",
  ]}
  maxSize={10} // max size 10MB
  multiple={true}
  size="lg"
  isLoading={false}
  hidePreview={false}
  onError={(error) => console.error("Error:", error)}
  onFileAdd={(file) => console.log("File added:", file)}
  onFileRemove={(file) => console.log("File removed:", file)}
  onClear={() => console.log("Files cleared")}
  classNames={{
    wrapper: "border border-gray-300 rounded-md p-4",
    dropZone: "bg-gray-50 hover:bg-gray-100 transition",
  }}

  {/* Controlled props (uncomment to test controlled mode) */}
  files={controlledFiles}
  errors={controlledErrors}
  onFilesChange={setControlledFiles}
  onErrorsChange={setControlledErrors}
  disableErrorMessage={false}
/>

Another Examples

Accepted Type(s)

Drag and drop that only accepts specific data types. Useful for restricting interactions to valid targets.

Controlled

Drag and drop behavior managed entirely through external state. Ideal for complex logic or synced updates.

Custom Build Children

Drag and drop with fully customizable children. Offers complete control over layout and interactive behavior.

Props

Loading types…