saleor-dashboard/src/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx

97 lines
2.5 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { IconProps } from "@material-ui/core/Icon";
import {
createStyles,
Theme,
withStyles,
WithStyles
} from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
2019-08-09 10:26:22 +00:00
import React from "react";
import { FormattedMessage } from "react-intl";
2019-06-19 14:40:52 +00:00
2019-10-28 16:16:49 +00:00
const styles = theme =>
2019-06-19 14:40:52 +00:00
createStyles({
cardContent: {
"&:last-child": {
2019-10-28 16:16:49 +00:00
padding: theme.spacing(2, 3)
2019-06-19 14:40:52 +00:00
},
display: "grid",
2019-10-28 16:16:49 +00:00
gridColumnGap: theme.spacing(3),
2019-06-19 14:40:52 +00:00
gridTemplateColumns: "1fr 64px"
},
cardSpacing: {
[theme.breakpoints.down("sm")]: {
2019-10-28 16:16:49 +00:00
marginBottom: theme.spacing(1)
2019-06-19 14:40:52 +00:00
},
2019-10-28 16:16:49 +00:00
marginBottom: theme.spacing(3)
2019-06-19 14:40:52 +00:00
},
cardSubtitle: {
2019-09-11 09:47:39 +00:00
fontSize: 12,
2019-06-19 14:40:52 +00:00
height: "20px",
2019-09-11 09:47:39 +00:00
lineHeight: 0.9
2019-06-19 14:40:52 +00:00
},
cardTitle: {
2019-09-11 09:47:39 +00:00
fontSize: 20,
fontWeight: 500 as 500
2019-06-19 14:40:52 +00:00
},
icon: {
color: theme.palette.primary.contrastText,
fontSize: 54,
margin: ".5rem .3rem"
},
iconBackground: {
backgroundColor: theme.palette.background.default,
borderRadius: "8px",
color: "white",
fontSize: "54px",
height: "100%",
padding: "10px 5px 0px 5px",
width: "100%"
},
value: {
textAlign: "right"
}
});
interface HomeAnalyticsCardProps extends WithStyles<typeof styles> {
icon: React.ReactElement<IconProps>;
title: string;
children?: React.ReactNode;
}
const HomeAnalyticsCard = withStyles(styles, { name: "HomeAnalyticsCard" })(
({ children, classes, title, icon }: HomeAnalyticsCardProps) => (
<Card className={classes.cardSpacing}>
<CardContent className={classes.cardContent}>
<div>
<Typography className={classes.cardTitle} variant="subtitle1">
{title}
</Typography>
<Typography
className={classes.cardSubtitle}
variant="caption"
color="textSecondary"
>
<FormattedMessage
defaultMessage="Today"
id="homeAnalyticsCardHeader"
/>
2019-06-19 14:40:52 +00:00
</Typography>
<Typography
className={classes.value}
color="textPrimary"
variant="h4"
>
{children}
</Typography>
</div>
<div className={classes.iconBackground}>{icon}</div>
</CardContent>
</Card>
)
);
HomeAnalyticsCard.displayName = "HomeAnalyticsCard";
export default HomeAnalyticsCard;