-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileUpload.tsx
More file actions
executable file
·58 lines (52 loc) · 1.5 KB
/
FileUpload.tsx
File metadata and controls
executable file
·58 lines (52 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { JSX } from "react";
import Hint from "../Hint/Hint";
import ErrorMessage from "../ErrorMessage/ErrorMessage";
import Label from "../Label/Label";
import { FileUploadProps } from "./FileUpload.types";
const FileUpload: React.FC<FileUploadProps> = (props) => {
const {
className,
errorMessage,
formGroup,
hint,
label,
"aria-describedby": describedBy,
id,
...attributes
} = props;
let hintComponent: JSX.Element | undefined;
let errorMessageComponent: JSX.Element | undefined;
let describedByValue: string = describedBy || "";
if (hint) {
const hintId: string = `${props.id}-hint`;
describedByValue += ` ${hintId}`;
hintComponent = <Hint {...props.hint} id={hintId} />;
}
if (errorMessage) {
const errorId: string = `${id}-error`;
describedByValue += ` ${errorId}`;
errorMessageComponent = <ErrorMessage {...errorMessage} id={errorId} />;
}
return (
<div
className={`govuk-form-group${
errorMessage ? " govuk-form-group--error" : ""
} ${formGroup?.className || ""}`}
>
<Label {...label} htmlFor={id} />
{hintComponent}
{errorMessageComponent}
<input
{...attributes}
id={id}
className={`govuk-file-upload ${className || ""}${
errorMessage ? " govuk-file-upload--error" : ""
}`}
type="file"
aria-describedby={describedByValue || undefined}
/>
</div>
);
};
FileUpload.displayName = "FileUpload";
export default FileUpload;