dropzone
kibo-ui-registry/dropzoneFreeComponent
Allows users to drag-and-drop files into a container to upload or process them.
Live preview
live · rendered by the registry
Rendered by Kibo UI Registry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.kibo-ui.com/r/dropzone.jsonSource
1"use client";23import { UploadIcon } from "lucide-react";4import type { ReactNode } from "react";5import { createContext, useContext } from "react";6import type { DropEvent, DropzoneOptions, FileRejection } from "react-dropzone";7import { useDropzone } from "react-dropzone";8import { Button } from "@/components/ui/button";9import { cn } from "@/lib/utils";1011type DropzoneContextType = {12 src?: File[];13 accept?: DropzoneOptions["accept"];14 maxSize?: DropzoneOptions["maxSize"];15 minSize?: DropzoneOptions["minSize"];16 maxFiles?: DropzoneOptions["maxFiles"];17};1819const renderBytes = (bytes: number) => {20 const units = ["B", "KB", "MB", "GB", "TB", "PB"];21 let size = bytes;22 let unitIndex = 0;2324 while (size >= 1024 && unitIndex < units.length - 1) {25 size /= 1024;26 unitIndex++;27 }2829 return `${size.toFixed(2)}${units[unitIndex]}`;30};3132const DropzoneContext = createContext<DropzoneContextType | undefined>(33 undefined34);3536export type DropzoneProps = Omit<DropzoneOptions, "onDrop"> & {37 src?: File[];38 className?: string;39 onDrop?: (40 acceptedFiles: File[],41 fileRejections: FileRejection[],42 event: DropEvent43 ) => void;44 children?: ReactNode;45};4647export const Dropzone = ({48 accept,49 maxFiles = 1,50 maxSize,51 minSize,52 onDrop,53 onError,54 disabled,55 src,56 className,57 children,58 ...props59}: DropzoneProps) => {60 const { getRootProps, getInputProps, isDragActive } = useDropzone({61 accept,62 maxFiles,63 maxSize,64 minSize,65 onError,66 disabled,67 onDrop: (acceptedFiles, fileRejections, event) => {68 if (fileRejections.length > 0) {69 const message = fileRejections.at(0)?.errors.at(0)?.message;70 onError?.(new Error(message));71 return;72 }7374 onDrop?.(acceptedFiles, fileRejections, event);75 },76 ...props,77 });7879 return (80 <DropzoneContext.Provider81 key={JSON.stringify(src)}82 value={{ src, accept, maxSize, minSize, maxFiles }}83 >84 <Button85 className={cn(86 "relative h-auto w-full flex-col overflow-hidden p-8",87 isDragActive && "outline-none ring-1 ring-ring",88 className89 )}90 disabled={disabled}91 type="button"92 variant="outline"93 {...getRootProps()}94 >95 <input {...getInputProps()} disabled={disabled} />96 {children}97 </Button>98 </DropzoneContext.Provider>99 );100};101102const useDropzoneContext = () => {103 const context = useContext(DropzoneContext);104105 if (!context) {106// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Kibo UI Registry
All 41 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| announcementannouncement | Kibo UI Registry | Components | Free | no deps | |
| avatar-stackavatar-stack | Kibo UI Registry | Components | Free | no deps | |
| bannerbanner | Kibo UI Registry | Components | Free | 2 deps | |
| calendarcalendar | Kibo UI Registry | Components | Free | 3 deps | |
| choiceboxchoicebox | Kibo UI Registry | Components | Free | 2 deps | |
| code-blockcode-block | Kibo UI Registry | Components | Free | 5 deps · 2 files | |
| color-pickercolor-picker | Kibo UI Registry | Components | Free | 3 deps | |
| comboboxcombobox | Kibo UI Registry | Components | Free | 2 deps |
