BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/obsidianui/file-input

file-input

obsidianui/file-input
FreeComponent

obsidianui publishes no description for this item.

Live preview

live · rendered by the registry
Rendered by obsidianui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://obsidianui.dev/r/file-input.json

Source

components/ui/file-input.tsxobsidianui.dev/r/file-input.json · first 6 KB
1'use client';
2
3import { cn } from '@/lib/utils';
4import { AnimatePresence, motion } from 'framer-motion';
5import {
6 CloudUpload,
7 File,
8 Globe,
9 MapPin,
10 FileText,
11 Image as ImageIcon,
12 Trash
13} from 'lucide-react';
14import Image from 'next/image';
15import React, { useEffect, useRef, useState } from 'react';
16
17const validateFile = (
18 file: File,
19 accept?: string,
20 maxSizeInMB?: number
21): { success: boolean; message: string | null } => {
22 // Validate file type if accept is specified
23 if (accept) {
24 const acceptedTypes = accept.split(',').map((type) => type.trim());
25 const fileType = file.type;
26 const fileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
27
28 const isValidType = acceptedTypes.some((acceptedType) => {
29 if (acceptedType.startsWith('.')) {
30 return acceptedType === fileExtension;
31 }
32 return acceptedType === fileType;
33 });
34
35 if (!isValidType) {
36 return { success: false, message: 'File type not accepted.' };
37 }
38 }
39
40 // Validate file size
41 if (maxSizeInMB) {
42 const fileSizeInMB = file.size / (1024 * 1024);
43 if (fileSizeInMB > maxSizeInMB) {
44 return { success: false, message: `File size exceeds ${maxSizeInMB}MB limit.` };
45 }
46 }
47
48 return { success: true, message: null };
49};
50
51const formatFileSize = (bytes: number): string => {
52 if (bytes === 0) return '0 Bytes';
53 const k = 1024;
54 const sizes = ['Bytes', 'KB', 'MB', 'GB'];
55 const i = Math.floor(Math.log(bytes) / Math.log(k));
56 return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
57};
58
59const getFileType = (file: File): 'image' | 'pdf' | 'text' | 'other' => {
60 if (file.type.startsWith('image/')) return 'image';
61 if (file.type === 'application/pdf') return 'pdf';
62 if (file.type.startsWith('text/')) return 'text';
63 return 'other';
64};
65
66const getFileIcon = (fileType: 'image' | 'pdf' | 'text' | 'other') => {
67 switch (fileType) {
68 case 'image':
69 return <ImageIcon size={24} className="text-white" />;
70 case 'pdf':
71 return <FileText size={24} className="text-white" />;
72 case 'text':
73 return <FileText size={24} className="text-white" />;
74 default:
75 return <File size={24} className="text-white" />;
76 }
77};
78
79interface IdleProps {
80 accept?: string;
81 maxSizeInMB?: number;
82 onClick: () => void;
83 onDrop: (e: React.DragEvent) => void;
84 error: string | null;
85}
86
87const Idle = ({ accept, maxSizeInMB, onClick, onDrop, error }: IdleProps) => {
88// … truncated

What it pulls in

npm packages

  • framer-motion
  • lucide-react

Files it writes

  • public/r/file-input.json

Facts

Registry
obsidianui
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-01
Last confirmed
3 days ago

Go to the source

Docs on obsidianui obsidianui.dev Atharvsinh-codez/ObsidianUI on GitHub Raw registry item This item as JSON

More from obsidianui

All 111 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
ai-inputai-inputobsidianuiComponentsFree2 deps
alertalertobsidianuiComponentsFreeno deps
animated-tab-baranimated-tab-barobsidianuiComponentsFreeno deps
apple-spotlightapple-spotlightobsidianuiComponentsFree2 deps
avataravatarobsidianuiComponentsFree1 dep
badgebadgeobsidianuiComponentsFree1 dep
breadcrumbbreadcrumbobsidianuiComponentsFree2 deps
buttonbuttonobsidianuiComponentsFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex