Dropzone (File Upload) for Nuxt and Supabase
supabase-ui-library/dropzone-nuxtjsUnverifiedBlock
Displays a control for easier uploading of files directly to Supabase Storage.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/flamingrubberduck/supabase-studio-multi-head/master/apps/ui-library/public/r/dropzone-nuxtjs.jsonSource
1<script setup lang="ts">2import { provide, inject } from 'vue'3import { cn } from '@/lib/utils'45interface File {6 name: string7 errors: Array<{ message: string }>8 size: number9 lastModified?: number10 type?: string11 preview?: string12}1314export interface DropzoneProps {15 className?: string16 isDragActive?: boolean17 isDragReject?: boolean18 isSuccess?: boolean19 maxFiles?: number20 maxFileSize?: number21 inputRef?: HTMLInputElement | null22 setFiles: (files: File[]) => void23 onUpload: () => Promise<void>24 loading?: boolean25 successes: string[]26 errors: Array<{ name: string; message: string }>27 files: File[]28 getRootProps: (options?: Record<string, unknown>) => Record<string, unknown>29 getInputProps: () => Record<string, unknown>30}3132export const formatBytes = (33 bytes: number,34 decimals = 2,35 size?: 'bytes' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB' | 'EB' | 'ZB' | 'YB'36) => {37 const k = 100038 const dm = decimals < 0 ? 0 : decimals39 const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']4041 if (!bytes || bytes < 0) return size ? `0 ${size}` : '0 bytes'4243 const i = size44 ? Math.max(0, sizes.indexOf(size))45 : Math.max(0, Math.min(sizes.length - 1, Math.floor(Math.log(bytes) / Math.log(k))))4647 return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]48}4950const DropzoneContext = Symbol('DropzoneContext')5152export function useDropzoneContext() {53 const ctx = inject<DropzoneProps>(DropzoneContext)54 if (!ctx) throw new Error('useDropzoneContext must be used within <Dropzone>')55 return ctx56}5758const props = defineProps<DropzoneProps>()5960provide(DropzoneContext, props)61</script>6263<template>64 <div65 v-bind="66 props.getRootProps({67 class: cn(68 'border-2 border-gray-300 rounded-lg p-6 text-center bg-card transition-colors duration-300 text-foreground',69 props.className,70 props.isSuccess ? 'border-solid' : 'border-dashed',71 props.isDragActive && 'border-primary bg-primary/10',72 ((props.isDragActive && props.isDragReject) ||73 (props.errors.length > 0 && !props.isSuccess) ||74 props.files.some((f) => f.errors.length !== 0)) &&75 'border-destructive bg-destructive/10'76 ),77 })78 "79 >80 <input v-bind="props.getInputProps()" />81 <slot />82 </div>83</template>
What it pulls in
npm packages
Other registry items
Files it writes
More from Supabase UI Library
All 37 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Current User Avatarcurrent-user-avatar-nuxtjs | Supabase UI Library | Blocks | Unverified | 1 dep · 3 files | |
| Current User Avatarcurrent-user-avatar-vue | Supabase UI Library | Blocks | Unverified | 1 dep · 3 files | |
| Dropzone (File Upload) for Vue and Supabasedropzone-vue | Supabase UI Library | Blocks | Unverified | 3 deps · 4 files | |
| Infinite Query Hookinfinite-query-hook | Supabase UI Library | Blocks | Unverified | 2 deps | |
| Password Based Auth flow for Nextjs and Supabasepassword-based-auth-nextjs | Supabase UI Library | Blocks | Unverified | 2 deps · 17 files | |
| Password Based Auth flow for Nuxt.js and Supabasepassword-based-auth-nuxtjs | Supabase UI Library | Blocks | Unverified | 2 deps · 12 files | |
| Password Based Auth flow for React and Supabasepassword-based-auth-react | Supabase UI Library | Blocks | Unverified | 1 dep · 5 files | |
| Password Based Auth flow for React Router and Supabasepassword-based-auth-react-router | Supabase UI Library | Blocks | Unverified | 4 deps · 11 files |
