Spaces:
Running
Running
File size: 2,035 Bytes
3637bbd 32b6112 3637bbd 32b6112 3637bbd 32b6112 3637bbd 32b6112 3637bbd 32b6112 | 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | // UploadedFileCard.tsx
import styles from "./UploadedFileCard.module.css";
import Text from "../Text/Text";
import { useState, useEffect } from "react"; // Import useEffect
interface UploadedFileCardProps {
fileName: string;
fileType: string;
fileSize: number;
onClose: () => void;
className?: string; // Add className prop
}
function UploadedFileCard(props: Readonly<UploadedFileCardProps>) {
const [showRawSize, setShowRawSize] = useState(false);
const [isMounted, setIsMounted] = useState(false); // New state for animation trigger
useEffect(() => {
// Trigger animation after component mounts
setIsMounted(true);
}, []);
const formatFileSize = (bytes: number) => {
const k = 1024;
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
const iteration = Math.floor(Math.log(bytes) / Math.log(k));
return (
parseFloat((bytes / Math.pow(k, iteration)).toFixed(2)) +
" " +
sizes[iteration]
);
};
const handleSizeClick = () => {
setShowRawSize((prevState) => !prevState);
};
return (
<div
className={`${styles.cardContainer} ${isMounted ? styles.enter : ""} ${props.className || ""}`}
>
<button className={styles.closeButton} onClick={props.onClose}>
×
</button>
<Text
fontWeight={"bold"}
colorVariant={"primary"}
fontSize={"large"}
className={styles.fileName}
>
{props.fileName}.{props.fileType}
</Text>
<Text
fontWeight={"regular"}
colorVariant={"secondary"}
fontSize={"small"}
className={styles.fileTypeExpansion}
>
Portable document format
</Text>
<Text
colorVariant={"primary"}
onClick={handleSizeClick}
interactable={true}
fontSize={"medium"}
className={styles.fileSize}
>
{showRawSize
? `${props.fileSize} Bytes`
: formatFileSize(props.fileSize)}
</Text>
</div>
);
}
export default UploadedFileCard;
|