From 48ece125761c4dce8175265c3b4de717a249eb0e Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 7 Jun 2020 16:36:50 +0300 Subject: feat: improve PollCard component --- src/PollCard/PollCard.tsx | 69 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 17 deletions(-) (limited to 'src/PollCard') diff --git a/src/PollCard/PollCard.tsx b/src/PollCard/PollCard.tsx index 05e941c..ee81b7d 100644 --- a/src/PollCard/PollCard.tsx +++ b/src/PollCard/PollCard.tsx @@ -8,6 +8,28 @@ import { CardHeader } from '@material-ui/core/'; +interface ImageData { + url: string; + votes: number; +} + +interface PropTypes { + author: { + name: string; + avatarUrl: string; + }; + contents: { + left: ImageData; + right: ImageData; + }; +} + +interface PercentageBarPropTypes { + value: number; + which: 'left' | 'right'; +} + + const useStyles = makeStyles({ root: { maxWidth: 600, @@ -21,55 +43,68 @@ const useStyles = makeStyles({ imagesBlock: { display: 'flex' }, - percentageLeft: { + percentage: { position: 'absolute', color: 'white', top: '86%', - left: 30, fontSize: 20 }, + percentageLeft: { + left: 30 + }, percentageRight: { - position: 'absolute', - color: 'white', - top: '86%', - right: 30, - fontSize: 20 + right: 30 } - }); -const PollCard: React.FC = () => { + +const PercentageBar: React.FC = ({ value, which }) => { const classes = useStyles(); + const positionClassName = which === 'left' ? 'percentageLeft' : 'percentageRight'; + + return ( +
+ {value} + % +
+ ); +}; + + +const PollCard: React.FC = ({ author, contents: { left, right } }) => { + const classes = useStyles(); + + const leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); + const rightPercentage = 100 - leftPercentage; return ( - R + {author.name[0].toUpperCase()} )} - title="Nick Name" + title={author.name} />
-
25%
+
-
75%
+
); }; export default PollCard; + -- cgit v1.2.3