analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
72 lines • 2.19 kB
TypeScript
/**
* Represents an attached file with unique identifier
*/
export interface AttachedFile {
/** The file object */
file: File;
/** Unique identifier for the file */
id: string;
}
/**
* Props for the FileAttachment component
*/
export interface FileAttachmentProps {
/** List of attached files */
files: AttachedFile[];
/** Callback when files are added */
onFilesAdd: (files: File[]) => void;
/** Callback when a file is removed */
onFileRemove: (id: string) => void;
/** Whether the files are read-only (no removal allowed) */
readOnly?: boolean;
/** Text for the attach button */
buttonLabel?: string;
/** Whether to accept multiple files */
multiple?: boolean;
/** Additional CSS class */
className?: string;
/** Whether to hide the attach button */
hideButton?: boolean;
}
/**
* Formats file size to human-readable string
* @param bytes - File size in bytes
* @returns Formatted string (e.g., "1.5 MB")
*/
declare const formatFileSize: (bytes: number) => string;
/**
* Generates a unique ID for file tracking
* @returns Unique string identifier
*/
declare const generateFileId: () => string;
/**
* Reusable file attachment component
*
* Allows users to attach multiple files with preview and removal functionality.
* No file size or type restrictions are applied on the client side.
*
* @param props - Component props
* @returns JSX element
*
* @example
* ```tsx
* const [files, setFiles] = useState<AttachedFile[]>([]);
*
* <FileAttachment
* files={files}
* onFilesAdd={(newFiles) => {
* const attachedFiles = newFiles.map(file => ({
* file,
* id: generateFileId()
* }));
* setFiles(prev => [...prev, ...attachedFiles]);
* }}
* onFileRemove={(id) => setFiles(prev => prev.filter(f => f.id !== id))}
* multiple
* />
* ```
*/
declare const FileAttachment: ({ files, onFilesAdd, onFileRemove, readOnly, buttonLabel, multiple, className, hideButton, }: FileAttachmentProps) => import("react/jsx-runtime").JSX.Element;
export { generateFileId, formatFileSize };
export default FileAttachment;
//# sourceMappingURL=FileAttachment.d.ts.map