({
size = "sm",
label,
hint,
placeholder = "Choose a file",
isDisabled,
isInvalid,
isRequired,
hideRequiredIndicator,
isLoading,
acceptedFileTypes,
allowsMultiple,
onChange,
className,
buttonText = "Upload",
}: InputFileProps)
| 45 | } |
| 46 | |
| 47 | export const InputFile = ({ |
| 48 | size = "sm", |
| 49 | label, |
| 50 | hint, |
| 51 | placeholder = "Choose a file", |
| 52 | isDisabled, |
| 53 | isInvalid, |
| 54 | isRequired, |
| 55 | hideRequiredIndicator, |
| 56 | isLoading, |
| 57 | acceptedFileTypes, |
| 58 | allowsMultiple, |
| 59 | onChange, |
| 60 | className, |
| 61 | buttonText = "Upload", |
| 62 | }: InputFileProps) => { |
| 63 | const inputRef = useRef<HTMLInputElement>(null); |
| 64 | const [fileNames, setFileNames] = useState(""); |
| 65 | |
| 66 | const handleClick = () => { |
| 67 | if (inputRef.current?.value) { |
| 68 | inputRef.current.value = ""; |
| 69 | } |
| 70 | inputRef.current?.click(); |
| 71 | }; |
| 72 | |
| 73 | const handleChange = () => { |
| 74 | const files = inputRef.current?.files ?? null; |
| 75 | if (files && files.length > 0) { |
| 76 | setFileNames( |
| 77 | Array.from(files) |
| 78 | .map((f) => f.name) |
| 79 | .join(", "), |
| 80 | ); |
| 81 | } else { |
| 82 | setFileNames(""); |
| 83 | } |
| 84 | onChange?.(files); |
| 85 | }; |
| 86 | |
| 87 | return ( |
| 88 | <> |
| 89 | <InputGroup |
| 90 | size={size} |
| 91 | label={label} |
| 92 | hint={hint} |
| 93 | isDisabled={isDisabled} |
| 94 | isInvalid={isInvalid} |
| 95 | isRequired={isRequired} |
| 96 | hideRequiredIndicator={hideRequiredIndicator} |
| 97 | className={className} |
| 98 | trailingAddon={ |
| 99 | <Button size={size} color="secondary" onClick={handleClick} isDisabled={isDisabled}> |
| 100 | {buttonText} |
| 101 | </Button> |
| 102 | } |
| 103 | > |
| 104 | <div className="relative flex min-w-0 flex-1"> |
nothing calls this directly
no outgoing calls
no test coverage detected