Upload

The Upload module provide a set of flexible, user-friendly interfaces for handling file uploads in your application. These components include functionalities for selecting, previewing, uploading, and managing files, with a focus on usability and customization.

Features

📂 File Upload Handling: Supports drag-and-drop and click-to-upload functionality for a seamless user experience. This is achieved using react-dropzone for handling file selection.

🖼️ Image Preview: Automatically generates previews for image files, allowing users to see their selected files before uploading.

🔄 Progress Indicators: Real-time progress indicators, provided by @start-base/start-ui, give users feedback on the status of their uploads.

🔧 Integrated with Modals: The upload process can be managed within modals using @start-base/react-modal, providing a controlled and accessible user experience.

🛠️ File Management: Includes tools for copying file URLs, downloading files, and removing files from the upload list, leveraging utilities like FileSaver for file management.

🔔 User Notifications: The Sonner library is used for displaying toast notifications, providing feedback to users during the upload process.

What's Included

< EmptyCard />

The EmptyCard component is a UI element used to display an empty state when there are no files uploaded or when a specific file-related action is loading.

EmptyCard Props

NameTypeDefaultDescription
titlestringnullThe title text displayed in the card.
descriptionstringnullA description text to provide more context in the card.
actionReactNodenullAn optional action element (e.g., a button) displayed at the bottom.
classNamestringnullAdditional custom classes for styling the card.
loadingbooleanfalseIndicates if a loading spinner should be displayed.

< FileCard />

The FileCard component displays information about a file, including its name, size, and a preview (if available). It also includes actions for downloading, copying URLs, and removing the file.

FileCard Props

NameTypeDefaultDescription
fileobjectnullThe file object containing file metadata such as name and size.
onRemovefunctionnullA function to be called when the remove action is triggered.
onDeletefunctionnullA function to be called when the delete action is triggered.
onShowfunctionnullA function to be called when the show action (e.g., preview) is triggered.
progressbooleanfalseIndicates whether a progress bar should be displayed.
uploadedbooleanfalseIndicates whether the file has been successfully uploaded.

< PreviewButton />

The PreviewButton component is used to trigger a preview of the selected image file in a popover. This is particularly useful for reviewing uploaded images before final submission.

PreviewButton Props

NameTypeDefaultDescription
filestringnullThe URL or path to the image file to be previewed.
labelstringnullThe label text displayed on the preview button.

< UploadButton />

The UploadButton component is the main interface for initiating file uploads. It supports multiple file types, file size limits, and integrates with the UploadZone and UploadModal components for handling the upload process.

UploadButton Props

NameTypeDefaultDescription
namestringnullThe name attribute for identifying the upload button.
labelstringnullThe label text displayed on the upload button.
acceptobject{'image/*': []}Accepted file types, following the input accept attribute specification.
setFilesfunctionnullA function to update the file list after files are selected.
valueobjectnullThe current file(s) selected.
maxSizenumber4The maximum file size allowed for upload, in MB.
maxFilesnumber1The maximum number of files that can be uploaded.
disabledbooleanfalseDisables the upload button when set to true.
previewstringnullA URL to an image for previewing the currently selected file.
errorobjectnullAn error object containing error messages related to file upload.

< UploadModal />

The UploadModal component wraps the UploadZone component within a modal, allowing users to manage file uploads in a focused, isolated UI.

UploadModal Props

NameTypeDefaultDescription
isModalOpenbooleanfalseControls the visibility of the modal.
labelstringnullThe label text displayed in the modal header.
setIsModalOpenfunctionnullA function to toggle the modal's open state.
setFilesfunctionnullA function to update the file list after files are selected.
valueobjectnullThe current file(s) selected.
acceptobject{'image/*': []}Accepted file types for upload.
maxFilesnumber1The maximum number of files that can be uploaded.
maxSizenumber4The maximum file size allowed for upload, in MB.

< Uploaded />

The Uploaded component displays a list of files that have already been uploaded. It includes functionality to view, delete, or download files.

Uploaded Props

NameTypeDefaultDescription
bucketstringnullThe storage bucket from which to fetch and manage uploaded files.

< UploadZone />

The UploadZone component provides the drag-and-drop area for file uploads. It supports multiple file types, file size limits, and real-time upload progress.

UploadZone Props

NameTypeDefaultDescription
valueobjectnullThe current file(s) selected.
onValueChangefunctionnullA function to update the file list after files are selected.
namestringnullThe name attribute for identifying the upload zone.
labelstringnullThe label text displayed in the upload zone.
bucketstringnullThe storage bucket used for file uploads.
onUploadfunctionnullA function to handle the file upload process.
acceptobject{'image/*': []}Accepted file types for upload.
maxSizenumber4The maximum file size allowed for upload, in MB.
maxFilesnumberInfinityThe maximum number of files that can be uploaded.
disabledbooleanfalseDisables the upload zone when set to true.
classNamestringnullAdditional custom classes for styling the upload zone.
hiddenbooleanfalseHides the upload zone when set to true.
errorobjectnullAn error object containing error messages related to file upload.

Individual Use Cases

These components can be used individually in different sections of your application, such as the files section on the admin panel or within forms using React Hook Form. You can easily integrate them into existing forms or other parts of the UI by importing the necessary components and passing the required props.

Setup Component's Needs

Configure Environment Variables

  1. Sign Up or Log In to Supabase: Go to Supabase and sign up or log in.
  2. Create a New Supabase Project: In the Supabase dashboard, create a new project. You'll receive an API URL and an API Key for your project.
  3. Supabase Storage Buckets: Create a storage bucket in your Supabase project.
  4. Configure Environment Variables: In the root of your Next.js project, create or update your .env.local file. Add the following environment variables and replace the placeholders with your actual Supabase details:
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
NEXT_PUBLIC_FILE_SUPABASE_BUCKET=your-bucket-name
  1. Set Up Row Level Security (RLS): Use Supabase's Row Level Security (RLS) policies to restrict access to certain data based on user roles. This can be configured directly in the Supabase dashboard under your project's settings. Ensure your bucket is public.