-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfileInput.tsx
More file actions
39 lines (35 loc) · 985 Bytes
/
fileInput.tsx
File metadata and controls
39 lines (35 loc) · 985 Bytes
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
import type { ReactNode } from 'react';
import { forwardRef } from 'react';
import { useFileInput } from 'molecules/fileInput/useFileInput';
import { Text } from 'ui';
type FileInputProps = {
handleChange: (filesSrc: string[]) => void;
children: ReactNode;
name: string;
isSinglePhoto?: boolean;
};
export const FileInput = forwardRef<HTMLInputElement, FileInputProps>(
({ children, name, isSinglePhoto }, ref) => {
const { errorMessage, getInputProps, getRootProps, open, onChange } =
useFileInput({
isSinglePhoto,
});
return (
<div
className="flex h-full cursor-pointer flex-col items-center justify-start"
{...getRootProps()}
>
<input ref={ref} {...getInputProps({ name, onChange })} />
<button className="min-h-full" onClick={open}>
{children}
</button>
{errorMessage && (
<Text size="medium" variant="error" tag="p">
{errorMessage}
</Text>
)}
</div>
);
},
);
FileInput.displayName = 'FileInput';