Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Patterns
File Dropzone
Drag files in or browse, with previews and upload progress.
import { FileDropzone } from "@/registry/vcare/ui/file-dropzone"
export default function FileDropzoneDemo() {
return <FileDropzone className="max-w-md" multiple accept="image/*,application/pdf" maxSize={5 * 1024 * 1024} hint="Scans and PDFs up to 5 MB" />
}Installation
npx shadcn@latest add @vcare/file-dropzoneOr install directly from the URL: https://ui.vcarehms.com/r/file-dropzone.json
- Install the dependencies:
npm i lucide-react - Add the registry items it uses: button, i18n, use-file-upload, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/file-dropzone.tsx
import { CheckCircle2, FileText, ImageIcon, UploadCloud, X } from 'lucide-react';
import { useTranslation } from '@/registry/vcare/lib/i18n';
import { Button } from '@/registry/vcare/ui/button';
import { useFileUpload, type FileUploadOptions } from '@/registry/vcare/hooks/use-file-upload';
import { cn } from '@/registry/vcare/lib/utils';
const size = (bytes: number) =>
bytes < 1024 ? `${bytes} B` : bytes < 1048576 ? `${(bytes / 1024).toFixed(0)} KB` : `${(bytes / 1048576).toFixed(1)} MB`;
interface Props extends FileUploadOptions {
/** 0 to 100 per file id while it uploads. A missing id means the file is only selected, 100 means done. */
progress?: Record<string, number>;
hint?: string;
disabled?: boolean;
className?: string;
}
/** Drop zone with a file list: drag in, validate size and type, show progress, remove. Wraps `useFileUpload`. */
export function FileDropzone({ progress, hint, disabled, className, onError, ...options }: Props) {
const { t } = useTranslation();
const [{ files, isDragging, errors }, up] = useFileUpload({ ...options, onError });
return (
<div data-slot="file-dropzone" className={cn('flex w-full flex-col gap-2', className)}>
<div
role="button"
tabIndex={disabled ? -1 : 0}
aria-disabled={disabled}
onClick={() => !disabled && up.openFileDialog()}
onKeyDown={(e) => {
if (!disabled && (e.key === 'Enter' || e.key === ' ')) {
e.preventDefault();
up.openFileDialog();
}
}}
onDragEnter={up.handleDragEnter}
onDragLeave={up.handleDragLeave}
onDragOver={up.handleDragOver}
onDrop={up.handleDrop}
data-dragging={isDragging || undefined}
className={cn(
'flex cursor-pointer flex-col items-center gap-1.5 rounded-2xl border border-dashed border-input bg-secondary/40 px-4 py-6 text-center outline-none transition-[border-color,background-color] duration-150 ease-power3-out',
'hover:bg-secondary focus-visible:ring-2 focus-visible:ring-ring/50 data-[dragging]:border-primary data-[dragging]:bg-primary/5 aria-disabled:pointer-events-none aria-disabled:opacity-50',
)}
>
<span className="grid size-10 place-items-center rounded-full bg-muted text-muted-foreground">
<UploadCloud className="size-5" />
</span>
<p className="text-sm font-medium">
{t('upload.drop', { defaultValue: 'Drop files here or' })}{' '}
<span className="text-primary">{t('upload.browse', { defaultValue: 'browse' })}</span>
</p>
{hint && <p className="text-xs text-muted-foreground">{hint}</p>}
<input {...up.getInputProps({ className: 'sr-only', tabIndex: -1, disabled })} />
</div>
{errors.length > 0 && (
<ul role="alert" className="flex flex-col gap-0.5 text-xs text-destructive">
{errors.map((e) => (
<li key={e}>{e}</li>
))}
</ul>
)}
{files.length > 0 && (
<ul className="flex flex-col gap-1.5">
{files.map(({ file, id, preview }) => {
const pct = progress?.[id];
const done = pct === undefined ? false : pct >= 100;
const image = file.type.startsWith('image/');
return (
<li key={id} className="flex items-center gap-3 rounded-2xl border bg-card p-2">
{image && preview ? (
<img src={preview} alt="" className="size-9 shrink-0 rounded-lg object-cover" />
) : (
<span className="grid size-9 shrink-0 place-items-center rounded-lg bg-muted text-muted-foreground">
{image ? <ImageIcon className="size-4" /> : <FileText className="size-4" />}
</span>
)}
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium">{file.name}</p>
{pct !== undefined && !done ? (
<div
role="progressbar"
aria-valuenow={Math.round(pct)}
aria-valuemin={0}
aria-valuemax={100}
className="mt-1.5 h-1 overflow-hidden rounded-full bg-muted"
>
<div className="h-full rounded-full bg-primary transition-[width] duration-300 ease-out" style={{ width: `${pct}%` }} />
</div>
) : (
<p className="text-xs text-muted-foreground">{size(file.size)}</p>
)}
</div>
{done ? (
<CheckCircle2 className="size-4 shrink-0 text-success" aria-label={t('upload.done', { defaultValue: 'Uploaded' })} />
) : (
<Button variant="ghost" size="icon-xs" aria-label={t('remove', { defaultValue: 'Remove' })} onClick={() => up.removeFile(id)}>
<X />
</Button>
)}
</li>
);
})}
</ul>
)}
</div>
);
}Usage
import { FileDropzone } from "@/components/ui/file-dropzone"Exports
FileDropzone
Dependencies
lucide-react@^1.80.0(npm)@vcare/button(registry)@vcare/i18n(registry)@vcare/use-file-upload(registry)@vcare/utils(registry)
Raw item: /r/file-dropzone.json