import AttachFileIcon from "@mui/icons-material/AttachFile"; import ClearIcon from "@mui/icons-material/Clear"; import { IconButton, InputAdornment, OutlinedInputProps, TextField, TextFieldSlotsAndSlotProps, Tooltip, } from "@mui/material"; import { filesize } from "filesize"; import React from "react"; export function FileInput( p: { label?: string; value: File | null; onChange: (file: File | null) => void; style?: React.CSSProperties; } & TextFieldSlotsAndSlotProps ): React.ReactElement { const fileInput = React.useRef(null); return ( fileInput.current?.click()} {...p} value={""} onChange={console.log} type="file" slotProps={{ input: { startAdornment: ( <>    {p.value ? p.value.name : "Select a file"} ), endAdornment: p.value ? ( {filesize(p.value.size)} { e.stopPropagation(); }} > { e.stopPropagation(); p.onChange(null); }} > ) : undefined, onChange: (e) => { const files = (e.target as any).files; p.onChange(files.length > 0 ? files[0] : null); }, }, htmlInput: { ref: fileInput, style: { opacity: 0 }, }, }} placeholder={"Insert a file"} variant="outlined" /> ); }