File size: 1,503 Bytes
9b906ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { LoaderCircle } from "lucide-react";
import FileIcon from "#/icons/file.svg?react";
import { RemoveFileButton } from "./remove-file-button";
import { cn, getFileExtension } from "#/utils/utils";

interface UploadedFileProps {
  file: File;
  onRemove: () => void;
  isLoading?: boolean;
}

export function UploadedFile({
  file,
  onRemove,
  isLoading = false,
}: UploadedFileProps) {
  const fileExtension = getFileExtension(file.name);

  return (
    <div className="group flex gap-2 rounded-lg bg-[var(--oh-interactive-hover)] max-w-[160px] px-3 py-1 relative">
      <div className="flex flex-col justify-center gap-0.25">
        <RemoveFileButton onClick={onRemove} />
        <div className="flex items-center gap-2 w-full">
          <span
            className={cn(
              "text-sm font-normal leading-5 flex-1 max-w-[136px] truncate",
              isLoading ? "max-w-[108px] text-[var(--oh-muted)]" : "text-white",
            )}
          >
            {file.name}
          </span>
        </div>
        <div className="flex items-center gap-2">
          <FileIcon width={12} height={12} color="var(--oh-muted)" />
          <span className="text-[9px] font-normal leading-5 text-[var(--oh-muted)]">
            {fileExtension}
          </span>
        </div>
      </div>
      {isLoading && (
        <div className="flex items-center justify-center">
          <LoaderCircle className="animate-spin w-5 h-5" color="white" />
        </div>
      )}
    </div>
  );
}