2023-06-22 17:16:26 +02:00
|
|
|
import React, { forwardRef, InputHTMLAttributes, ReactElement } from "react";
|
|
|
|
|
import { Field, FieldProps, FieldState } from ":/components/Forms/Field";
|
|
|
|
|
import { FileUploaderMulti } from ":/components/Forms/FileUploader/FileUploaderMulti";
|
|
|
|
|
import { FileUploaderMono } from ":/components/Forms/FileUploader/FileUploaderMono";
|
|
|
|
|
|
|
|
|
|
export interface FileUploaderProps
|
|
|
|
|
extends Omit<FieldProps, "state">,
|
|
|
|
|
InputHTMLAttributes<HTMLInputElement> {
|
|
|
|
|
state?: FieldState | "uploading" | undefined;
|
|
|
|
|
multiple?: boolean;
|
|
|
|
|
icon?: ReactElement;
|
|
|
|
|
successIcon?: ReactElement;
|
|
|
|
|
deleteIcon?: ReactElement;
|
|
|
|
|
fileSelectedIcon?: ReactElement;
|
|
|
|
|
uploadingIcon?: ReactElement;
|
|
|
|
|
animateIcon?: boolean;
|
|
|
|
|
name?: string;
|
|
|
|
|
bigText?: string;
|
|
|
|
|
onFilesChange?: (event: { target: { value: File[] } }) => void;
|
|
|
|
|
// This is only here for storybook. It cannot be used in real conditions.
|
|
|
|
|
fakeDefaultFiles?: File[];
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 18:07:28 +02:00
|
|
|
export interface FileUploaderRefType {
|
2023-06-22 17:16:26 +02:00
|
|
|
reset: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const FileUploader = forwardRef<FileUploaderRefType, FileUploaderProps>(
|
|
|
|
|
({ fullWidth, ...props }, ref) => {
|
|
|
|
|
return (
|
2024-03-04 15:21:09 +01:00
|
|
|
<Field fullWidth={fullWidth} className={props.className}>
|
2023-06-22 17:16:26 +02:00
|
|
|
{props.multiple ? (
|
|
|
|
|
<FileUploaderMulti {...props} ref={ref} />
|
|
|
|
|
) : (
|
|
|
|
|
<FileUploaderMono {...props} ref={ref} />
|
|
|
|
|
)}
|
|
|
|
|
</Field>
|
|
|
|
|
);
|
2023-07-18 15:43:56 +02:00
|
|
|
},
|
2023-06-22 17:16:26 +02:00
|
|
|
);
|