better text view

This commit is contained in:
Aria Moradi
2021-08-29 21:46:20 +04:30
parent 900847eab3
commit c0c734dbd5

View File

@@ -38,6 +38,8 @@ const useStyles = makeStyles({
bottom: 0, bottom: 0,
padding: '0.5em', padding: '0.5em',
color: 'white', color: 'white',
fontSize: '1.05rem',
textShadow: '0px 0px 3px #000000',
}, },
image: { image: {
height: '100%', height: '100%',
@@ -50,6 +52,17 @@ const useStyles = makeStyles({
}, },
}); });
const truncateText = (str: string, maxLength: number) => {
const ending = '...';
// trim the string to the maximum length
const trimmedString = str.substr(0, maxLength - ending.length);
if (trimmedString.length < str.length) {
return trimmedString + ending;
}
return str;
};
interface IProps { interface IProps {
manga: IMangaCard manga: IMangaCard
} }
@@ -75,7 +88,9 @@ const MangaCard = React.forwardRef((props: IProps, ref) => {
imgClassName={classes.image} imgClassName={classes.image}
/> />
<div className={classes.gradient} /> <div className={classes.gradient} />
<Typography className={classes.title} variant="h5" component="h2">{title}</Typography> <Typography className={classes.title}>
{truncateText(title, 61)}
</Typography>
</div> </div>
</CardActionArea> </CardActionArea>
</Card> </Card>