Toast Button
uploadthingui/toast-buttonFreeComponent
An upload button component which uses toasts as its response method
Live preview
live · rendered by the registry
Rendered by uploadthingui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://uploadthingui.webdevkaleem.com/r/toast-button.jsonSource
1"use client";23import { Button } from "@/components/ui/button";4import { UploadButton, useUploadThing } from "@/lib/uploadthing";5import {6 checkFileObjectKey,7 getFileSizeFormatted,8 truncateFileName,9} from "@/lib/uploadthingui-utils";10import { useFileStorageStore, type UTUIFile } from "@/stores/main";11import { createId } from "@paralleldrive/cuid2";12import { Upload } from "lucide-react";13import { useEffect, useRef, type ComponentProps } from "react";14import { toast } from "sonner";15import { generatePermittedFileTypes } from "uploadthing/client";1617// Get the props type directly from UploadButton18type UploadButtonProps = ComponentProps<typeof UploadButton>;1920/**21 * @description An upload button component which uses toasts as its response method.22 * @param {UploadButtonProps} props - The props for the UploadButton component.23 * @param {boolean} showDetails - Whether to show the details of the upload.24 * @param {string} instanceId - The instance ID for the upload. Required to avoid multiple instances of the same component if multiple upload buttons are used.25 * @param {boolean} allowInBetweenUploads - Whether to allow in between uploads.26 * @param {routeDetails} routeDetails - Additional details for the upload; Example: maxFileCount, minFileCount, etc.27 * @param {React.ReactNode} children - React node to render a custom button component.28 */29export default function ToastButton({30 props,31 showDetails = false,32 instanceId,33 allowInBetweenUploads = true,34 routeDetails,35 children,36}: {37 props: UploadButtonProps;38 showDetails?: boolean;39 instanceId: string;40 routeDetails?: {41 maxFileCount?: number;42 minFileCount?: number;43 };44 allowInBetweenUploads?: boolean;45 children?: React.ReactNode;46}) {47 // [1]. States, Refs, Hooks, etc.48 const { endpoint, ...restProps } = props;4950 // Used to reference the file input element51 const fileInputRef = useRef<HTMLInputElement>(null);5253 const { getFiles, addFiles } = useFileStorageStore();5455 // Used to get the route config from uploadthing56 const { routeConfig } = useUploadThing(endpoint, {57 ...restProps,58 });5960 const files = getFiles(instanceId);6162 const canUpload =63 allowInBetweenUploads ||64 files.filter((file) => file.status === "uploading").length === 0;6566 // Used to generate the accepted file types67 const acceptedFileTypes = generatePermittedFileTypes(routeConfig)68 .fileTypes.map((fileType) => {69// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from uploadthingui
All 2 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Dropzone Dialogdropzone-dialog | uploadthingui | Components | Free | 5 deps · 6 files |
