'use client'; import clsx from 'clsx'; import { useRef, useState } from 'react'; import { IconUpload } from '../Icons'; import { CProps } from '../props'; import Button from './Button'; import Label from './Label'; interface FileInputProps extends Omit { /** Label to display in file upload button. */ label: string; /** Filter: file types. */ acceptType?: string; /** Callback to set the `value`. Value is transmitted as `event.target.files[0]`. */ onChange?: (event: React.ChangeEvent) => void; } /** * FileInput component for selecting a `file`, displaying the selected file name. */ function FileInput({ id, label, acceptType, title, className, style, onChange, ...restProps }: FileInputProps) { const inputRef = useRef(null); const [fileName, setFileName] = useState(''); const handleUploadClick = () => { inputRef.current?.click(); }; const handleFileChange = (event: React.ChangeEvent) => { if (event.target.files && event.target.files.length > 0) { setFileName(event.target.files[0].name); } else { setFileName(''); } if (onChange) { onChange(event); } }; return (
); } export default FileInput;