import * as React from "react"; import { ExtFile, Localization, Method, ServerAction, ValidateFileResponse } from "@files-ui/core"; /** * Options for useFilesUI hook */ export interface UseFilesUIOptions { /** * Comma-separated list of allowed MIME types or file extensions * @example "image/*,.pdf,video/mp4" */ accept?: string; /** * Maximum file size in bytes * @example 5242880 (5MB) */ maxFileSize?: number; /** * Maximum number of files allowed */ maxFiles?: number; /** * Custom validation function */ validator?: (f: File) => ValidateFileResponse; /** * Upload endpoint URL */ url?: string; /** * Function to derive URL per file */ urlFromExtFile?: (f: ExtFile) => string; /** * HTTP method for upload * @default "POST" */ method?: Method; /** * Request headers */ headers?: Record; /** * Form field name for the file * @default "file" */ uploadLabel?: string; /** * Upload as raw blob instead of FormData * @default false */ asBlob?: boolean; /** * Enable chunked upload * @default false */ chunked?: boolean; /** * Chunk size in bytes for chunked uploads * @default 1048576 (1MB) */ chunkSize?: number; /** * Maximum number of concurrent uploads * @default 1 */ maxConcurrentUploads?: number; /** * How to handle new files: add to existing or replace all * @default "add" */ behaviour?: "add" | "replace"; /** * Automatically remove invalid files after validation * @default false */ autoClean?: boolean; /** * Remove invalid files before upload * @default false */ cleanOnUpload?: boolean; /** * Language code for localization * @default "EN-en" */ localization?: Localization; /** * Server Action for Next.js App Router * If provided, takes precedence over `url` * @example * ```tsx * "use server" * async function uploadAction(formData: FormData) { * const file = formData.get("file"); * // Process file... * return { success: true }; * } * * const { uploadFiles } = useFilesUI({ action: uploadAction }); * ``` */ action?: ServerAction; /** * Called when files are added or changed */ onChange?: (files: ExtFile[]) => void; /** * Called when upload starts */ onUploadStart?: (files: ExtFile[]) => void; /** * Called when upload finishes */ onUploadFinish?: (files: ExtFile[]) => void; /** * Called when a file is deleted */ onDelete?: (id: string | number) => void; /** * Called when all files are cleaned/cleared */ onClean?: (files: ExtFile[]) => void; /** * Optional dropzone ID for managing multiple instances * If not provided, one will be generated automatically */ dropzoneId?: string | number; /** * Initial files (controlled mode) */ value?: ExtFile[]; } /** * Return type of useFilesUI hook */ export interface UseFilesUIReturn { /** * Current list of files */ files: ExtFile[]; /** * Number of valid files */ numberOfValidFiles: number; /** * Whether upload is in progress */ isUploading: boolean; /** * Whether files are being dragged over */ isDragging: boolean; /** * Dropzone ID for managing multiple instances */ dropzoneId: string | number; /** * Add files to the list */ addFiles: (fileList: FileList | File[]) => void; /** * Remove a specific file by ID */ removeFile: (id: string | number) => void; /** * Update a file's properties */ updateFile: (id: string | number, updates: Partial) => void; /** * Clear all files */ clearFiles: () => void; /** * Clear only invalid files */ cleanFiles: () => void; /** * Upload all valid files */ uploadFiles: () => Promise; /** * Abort ongoing upload */ abortUpload: () => void; /** * Manually trigger validation */ validateFiles: () => void; /** * Get drag-and-drop event handlers */ getDragHandlers: () => { onDragEnter: React.DragEventHandler; onDragLeave: React.DragEventHandler; onDragOver: React.DragEventHandler; onDrop: React.DragEventHandler; }; /** * Get input element props */ getInputProps: () => { onChange: React.ChangeEventHandler; accept?: string; multiple: boolean; }; } export type { ServerAction }; /** * Headless hook for file upload management * * Provides all the business logic for file validation, state management, * and upload orchestration without any UI components. * * @example * ```tsx * const { files, addFiles, uploadFiles, getDragHandlers } = useFilesUI({ * accept: "image/*", * maxFileSize: 5 * 1024 * 1024, * url: "https://api.example.com/upload" * }); * * return ( *
* {files.map(f =>
{f.name}
)} *
* ); * ``` */ export declare const useFilesUI: (options?: UseFilesUIOptions) => UseFilesUIReturn;