import { useState, type ReactNode, type ChangeEvent, type Dispatch, type SetStateAction } from 'react'; import { Box, Typography, IconButton } from '@mui/material'; import RdsButton from '../rds-button/rds-button'; import { type FileWithProgress } from './rds-file-uploader'; interface RdsFileUploaderStandardViewProps { viewConfig: { showTitle: boolean; isMandatory: boolean; showHint: boolean; showPreview: boolean; }; interactionConfig: { disabled: boolean; dragAndDrop: boolean; isDragOver: boolean; multiple: boolean; }; mandatoryError: string | null; hintText: string; selectedFileName: string | null; handleFileSelect: (e: ChangeEvent) => void; addFiles: (files: File[]) => void; setSelectedFileName: (name: string | null) => void; setFiles: Dispatch>; onFilesChange?: (files: FileWithProgress[]) => void; children?: ReactNode; title?: string; } const RdsFileUploaderStandardView = ({ viewConfig, interactionConfig, mandatoryError, hintText, selectedFileName, handleFileSelect, addFiles, setSelectedFileName, setFiles, onFilesChange, children, title }: RdsFileUploaderStandardViewProps) => { const { showTitle, isMandatory, showHint, showPreview } = viewConfig; const { disabled, dragAndDrop, isDragOver, multiple } = interactionConfig; return ( {showTitle && ( {title || 'File'}{isMandatory && *} )} { e.preventDefault(); } : undefined} onDragLeave={dragAndDrop && !disabled ? (e) => { e.preventDefault(); } : undefined} onDrop={dragAndDrop && !disabled ? (e) => { e.preventDefault(); addFiles(Array.from(e.dataTransfer.files)); } : undefined} > )} > Choose File {showPreview ? (selectedFileName ? selectedFileName : 'No file chosen') : 'No file chosen'} {showPreview && selectedFileName && ( { setSelectedFileName(null); setFiles([]); onFilesChange?.([]); }} disabled={disabled} sx={{ ml: 'var(--rds-spacing-xs, 4px)' }} > {children} )} {showHint ? hintText : '\u00A0'} {isMandatory && mandatoryError && ( {mandatoryError} )} ); }; export default RdsFileUploaderStandardView; RdsFileUploaderStandardView.displayName = 'RdsFileUploaderStandardView';