import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { Card, CardActionArea, CardMedia, Avatar, 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, height: 500, margin: '20px auto' }, images: { height: 400, width: 300 }, imagesBlock: { display: 'flex' }, percentage: { position: 'absolute', color: 'white', top: '86%', fontSize: 20 }, percentageLeft: { left: 30 }, percentageRight: { right: 30 } }); 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 ( {author.name[0].toUpperCase()} )} title={author.name} />
); }; export default PollCard;