Files
Checkmate/Client/src/Components/ProgressBars/index.jsx
T

141 lines
4.0 KiB
React
Raw Normal View History

2024-06-26 19:12:50 -04:00
import React from "react";
2024-06-26 19:06:10 -04:00
import { useTheme } from "@emotion/react";
2024-06-26 19:12:50 -04:00
import PropTypes from "prop-types";
2024-06-26 19:06:10 -04:00
import {
Box,
IconButton,
LinearProgress,
Stack,
Typography,
} from "@mui/material";
import CloseIcon from "@mui/icons-material/Close";
2024-07-02 14:51:31 -04:00
import ErrorOutlineOutlinedIcon from "@mui/icons-material/ErrorOutlineOutlined";
2024-06-26 19:06:10 -04:00
import "./index.css";
/**
* @param {Object} props - The component props.
2024-06-26 19:12:50 -04:00
* @param {JSX.Element} props.icon - The icon element to display (optional).
* @param {string} props.label - The label text for the progress item.
* @param {string} props.size - The size information for the progress item.
* @param {number} props.progress - The current progress value (0-100).
* @param {function} props.onClick - The function to handle click events on the remove button.
2024-06-26 19:06:10 -04:00
* @returns {JSX.Element} The rendered component.
*/
2024-07-02 14:51:31 -04:00
const ProgressUpload = ({
icon,
label,
size,
progress = 0,
onClick,
error,
}) => {
2024-06-26 19:06:10 -04:00
const theme = useTheme();
return (
<Box
className="progress-bar-container"
mt="20px"
sx={{
minWidth: "200px",
height: "fit-content",
borderRadius: `${theme.shape.borderRadius}px`,
border: `solid 1px ${theme.palette.otherColors.graishWhite}`,
}}
>
2024-07-02 14:51:31 -04:00
<Stack
direction="row"
mb={error ? "0" : "10px"}
gap="10px"
alignItems={error ? "center" : "flex-end"}
>
{error ? (
<ErrorOutlineOutlinedIcon />
) : icon ? (
2024-06-26 19:06:10 -04:00
<IconButton
sx={{
backgroundColor: theme.palette.otherColors.white,
pointerEvents: "none",
borderRadius: `${theme.shape.borderRadius}px`,
border: `solid ${theme.shape.borderThick}px ${theme.palette.otherColors.graishWhite}`,
boxShadow: theme.shape.boxShadow,
}}
>
{icon}
</IconButton>
) : (
""
)}
2024-07-02 14:51:31 -04:00
{error ? (
<Typography component="p" className="input-error">
{error}
2024-06-26 19:06:10 -04:00
</Typography>
2024-07-02 14:51:31 -04:00
) : (
<Box>
<Typography component="h2" mb="5px">
{error ? error : label}
</Typography>
<Typography component="p">{!error && size}</Typography>
</Box>
)}
2024-06-26 19:06:10 -04:00
<IconButton
onClick={onClick}
2024-07-02 14:51:31 -04:00
sx={
!error
? {
alignSelf: "flex-start",
ml: "auto",
mr: "-5px",
mt: "-5px",
padding: "5px",
"&:focus": {
outline: "none",
},
}
: {
ml: "auto",
}
}
2024-06-26 19:06:10 -04:00
>
<CloseIcon
sx={{
fontSize: "20px",
}}
/>
</IconButton>
</Stack>
2024-07-02 14:51:31 -04:00
{!error ? (
<Stack direction="row" alignItems="center">
<Box sx={{ width: "100%", mr: "10px" }}>
<LinearProgress
variant="determinate"
value={progress}
sx={{
width: "100%",
height: "10px",
borderRadius: `${theme.shape.borderRadius}px`,
maxWidth: "500px",
backgroundColor: theme.palette.otherColors.graishWhite,
}}
/>
</Box>
<Typography component="p" sx={{ minWidth: "max-content" }}>
{progress}
<span>%</span>
</Typography>
</Stack>
) : (
""
)}
2024-06-26 19:06:10 -04:00
</Box>
);
};
2024-06-26 19:12:50 -04:00
ProgressUpload.propTypes = {
icon: PropTypes.element, // JSX element for the icon (optional)
label: PropTypes.string.isRequired, // Label text for the progress item
size: PropTypes.string.isRequired, // Size information for the progress item
progress: PropTypes.number.isRequired, // Current progress value (0-100)
onClick: PropTypes.func.isRequired, // Function to handle click events on the remove button
};
2024-06-26 19:06:10 -04:00
export default ProgressUpload;