|
1 | 1 | import React from "react"; |
2 | | -import { Progress, ProgressProps } from "antd"; |
| 2 | +import { |
| 3 | + Grid, |
| 4 | + LinearProgress, |
| 5 | + CircularProgress, |
| 6 | + linearProgressClasses, |
| 7 | + circularProgressClasses |
| 8 | +} from "@mui/material"; |
| 9 | +import styled from "styled-components"; |
3 | 10 | import ReviewColors from "../../constants/reviewColors"; |
4 | 11 | import colors from "../../styles/colors"; |
5 | | -import StatsReviewColors from "../../constants/statsReviewColors"; |
6 | 12 | import { useTranslation } from "next-i18next"; |
7 | 13 |
|
8 | 14 | const ReviewProgress = ({ reviews, statsProps }) => { |
9 | 15 | const { t } = useTranslation(); |
| 16 | + |
| 17 | + return reviews.map((review) => { |
| 18 | + const BorderLinearProgress = styled(LinearProgress)(() => ({ |
| 19 | + [`& .${linearProgressClasses.bar}`]: { |
| 20 | + borderRadius: 10, |
| 21 | + backgroundColor: ReviewColors[review._id] || colors.black, |
| 22 | + }, |
| 23 | + })); |
10 | 24 |
|
11 | | - const getStyle = (reviewId) => { |
12 | | - const defaultStyle: ProgressProps = { |
13 | | - strokeWidth: statsProps.strokeWidth || 18, |
14 | | - width: statsProps.width || 80, |
15 | | - strokeLinecap: statsProps.type === "circle" ? "square" : "round", |
16 | | - trailColor: colors.neutralTertiary, |
17 | | - }; |
18 | | - |
19 | | - return { |
20 | | - ...defaultStyle, |
21 | | - strokeColor: StatsReviewColors[reviewId] || colors.black, |
22 | | - }; |
23 | | - }; |
| 25 | + const BorderCircularProgress = styled(CircularProgress)(() => ({ |
| 26 | + [`& .${circularProgressClasses.circle}`]: { |
| 27 | + color: ReviewColors[review._id] || colors.black, |
| 28 | + }, |
| 29 | + })); |
24 | 30 |
|
25 | | - return reviews.map((review) => { |
26 | | - const format = |
27 | | - statsProps.format === "count" ? () => review.count : null; |
28 | 31 | return ( |
29 | 32 | <div |
30 | 33 | style={ |
@@ -52,13 +55,53 @@ const ReviewProgress = ({ reviews, statsProps }) => { |
52 | 55 | {statsProps.countInTitle && `${review.count} `} |
53 | 56 | {t(`claimReviewForm:${review._id}`)} |
54 | 57 | </span> |
55 | | - <Progress |
56 | | - percent={review.percentage} |
57 | | - type={statsProps.type} |
58 | | - format={format} |
59 | | - {...getStyle(review._id)} |
60 | | - /> |
61 | | - </div> |
| 58 | + {statsProps.type === "circle" ? |
| 59 | + <Grid container position="relative" display="inline-flex" justifyContent="center" |
| 60 | + alignItems="center"> |
| 61 | + <CircularProgress |
| 62 | + variant="determinate" |
| 63 | + value={100} |
| 64 | + size={statsProps.size} |
| 65 | + thickness={8} |
| 66 | + sx={{ color: colors.neutralTertiary, position: "absolute" }} |
| 67 | + /> |
| 68 | + <BorderCircularProgress |
| 69 | + variant="determinate" |
| 70 | + value={review.percentage} |
| 71 | + size={statsProps.size} |
| 72 | + thickness={8} |
| 73 | + /> |
| 74 | + <p |
| 75 | + style={{ |
| 76 | + fontSize: statsProps.size === 30 ? "10px" : "14px", |
| 77 | + position: "absolute", |
| 78 | + top: "50%", |
| 79 | + left: "50%", |
| 80 | + transform: "translate(-50%, -50%)", |
| 81 | + }} |
| 82 | + > |
| 83 | + {review.count} |
| 84 | + </p> |
| 85 | + </Grid> |
| 86 | + : |
| 87 | + <Grid container alignItems="center"> |
| 88 | + <Grid item xs={11}> |
| 89 | + <BorderLinearProgress |
| 90 | + variant="determinate" |
| 91 | + value={review.percentage} |
| 92 | + sx={{ height: 18, borderRadius: 10 }} |
| 93 | + /> |
| 94 | + </Grid> |
| 95 | + <Grid item xs={1}> |
| 96 | + <p |
| 97 | + style={{ fontSize: "12px", margin: 0, padding: "0px 10px" }} |
| 98 | + > |
| 99 | + {review.percentage}% |
| 100 | + </p> |
| 101 | + </Grid> |
| 102 | + </Grid> |
| 103 | + } |
| 104 | + </div > |
62 | 105 | ); |
63 | 106 | }); |
64 | 107 | }; |
|
0 commit comments