/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import Spinner from "./Spinner"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faFile } from "@fortawesome/free-solid-svg-icons"; import "./FileInput.css"; import { useTranslation } from "react-i18next"; interface Props { id: string; name: string; label: string; register?: Function; required?: boolean; disabled?: boolean; fileName?: string; staticFileName?: string; hint?: string | React.ReactNode; accept?: string; errors?: any; loading?: boolean; onFileProcessed?: Function; } function FileInput(props: Props) { const { t } = useTranslation(); let content = ( ); if (props.loading) { content = ; } else if (props.fileName || props.staticFileName) { content = (
{t("SelectedFile")}{" "} {t("ChangeFile")}
); } return (
0 ? " usa-form-group--error" : "" }`} >
{props.hint}
{props.errors && ( {props.errors.reduce( (accumulator: string, currentValue: any) => `${currentValue.message}\n${accumulator}`, "", )} )}
0 ? "usa-form-group--error margin-left-1px " : "" }usa-file-input__target`} > {content}
) => { if (props.onFileProcessed) { props.onFileProcessed( event.target.files?.length && event.target.files[0], ); } }} />
); } export default FileInput;