Skip to content

Commit

Permalink
Merge pull request #113 from frontendcafe/main-feature/104-create-Gam…
Browse files Browse the repository at this point in the history
…eStatus-component

[MAIN][FEATURE] create GameStatus component
  • Loading branch information
lilianaEstefanyPachari authored Sep 1, 2022
2 parents f07bace + 1b5ee16 commit f64ae07
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions modules/StudySession/components/GameStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react";

import { Box, Stack, StackProps, Text } from "@chakra-ui/react";

interface ResultBoxProps {
amount: number;
type: "correct" | "incorrect";
}
interface GameStatusProps extends StackProps {
correct: number;
incorrect: number;
total: number;
}

const ResultBox: React.FC<ResultBoxProps> = ({ amount, type }) => {
const bgColor = type === "correct" ? "status.success" : "status.error";
const label = `${amount} ${type === "correct" ? "Correctas" : "Incorrectas"}`;
return (
<Box bgColor={bgColor} px={3} py={2} borderRadius="md">
<Text>{label}</Text>
</Box>
);
};

const GameStatus: React.FC<GameStatusProps> = ({ correct, incorrect, total, ...props }) => {
const progressText = `${correct + incorrect}/${total}`;
return (
<Stack direction="row" justifyContent="space-between" {...props}>
<ResultBox amount={correct} type="incorrect" />

<Box>
<Text>{progressText}</Text>
</Box>

<ResultBox amount={incorrect} type="correct" />
</Stack>
);
};
export default GameStatus;

0 comments on commit f64ae07

Please sign in to comment.