Files
frontend/apps/as/src/shared/ui/attachment-file-field.tsx
T

65 lines
1.5 KiB
TypeScript

"use client";
import { FileAddButton } from "./file-add-button";
import { UploadedFileChip } from "./uploaded-file-chip";
interface AttachmentFileFieldItem {
fileKey: string;
fileName: string;
onDownload?: () => void;
}
interface AttachmentFileFieldProps {
files: AttachmentFileFieldItem[];
inputId: string;
isUploadingByKey: Record<string, boolean>;
onAdd: (files: FileList | null) => void;
onRemove?: (index: number) => void;
accept?: string;
multiple?: boolean;
addDisabled?: boolean;
showAddButton?: boolean;
}
function AttachmentFileField({
files,
inputId,
isUploadingByKey,
onAdd,
onRemove,
accept,
multiple = true,
addDisabled = false,
showAddButton = true,
}: AttachmentFileFieldProps) {
return (
<div className="space-y-2">
{files.length > 0 ? (
<div className="flex flex-wrap gap-2">
{files.map((file, index) => (
<UploadedFileChip
key={file.fileKey}
fileName={file.fileName}
isUploading={isUploadingByKey[file.fileKey] ?? false}
onRemove={onRemove ? () => onRemove(index) : undefined}
onDownload={file.onDownload}
/>
))}
</div>
) : null}
{showAddButton ? (
<FileAddButton
inputId={inputId}
accept={accept}
multiple={multiple}
disabled={addDisabled}
onFilesSelected={onAdd}
/>
) : null}
</div>
);
}
export { AttachmentFileField };
export type { AttachmentFileFieldItem, AttachmentFileFieldProps };