saleor-dashboard/src/components/Timeline/TimelineEvent.tsx

101 lines
2.7 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import ExpansionPanel from "@material-ui/core/ExpansionPanel";
import ExpansionPanelDetails from "@material-ui/core/ExpansionPanelDetails";
import ExpansionPanelSummary from "@material-ui/core/ExpansionPanelSummary";
import {
createStyles,
Theme,
withStyles,
WithStyles
} from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
import { DateTime } from "../Date";
2019-10-28 16:16:49 +00:00
const styles = theme =>
2019-06-19 14:40:52 +00:00
createStyles({
date: {
color: theme.typography.caption.color,
},
dateExpander:{
color: theme.typography.caption.color,
position: "absolute",
2019-10-28 16:16:49 +00:00
right: theme.spacing(3)
2019-06-19 14:40:52 +00:00
},
dot: {
backgroundColor: theme.palette.primary.main,
borderRadius: "100%",
height: 8,
left: -29,
position: "absolute",
top: 6,
width: 8
},
noExpander: {
alignItems: "center",
display: "flex",
justifyContent: "space-between",
2019-10-28 16:16:49 +00:00
marginBottom: theme.spacing(),
marginLeft: theme.spacing(3),
2019-06-19 14:40:52 +00:00
width: "100%"
},
panel: {
"&:before": {
display: "none"
},
background: "none",
width: "100%"
},
root: {
"&:last-child:after": {
background: theme.palette.background.default,
content: "''",
height: "calc(50% - 4px)",
2019-10-28 16:16:49 +00:00
left: -theme.spacing(3) - 2,
2019-06-19 14:40:52 +00:00
position: "absolute",
top: "calc(50% + 4px)",
width: "2px"
},
alignItems: "center",
display: "flex",
2019-10-28 16:16:49 +00:00
marginBottom: theme.spacing(3),
2019-06-19 14:40:52 +00:00
position: "relative",
width: "100%"
}
});
interface TimelineEventProps extends WithStyles<typeof styles> {
children?: React.ReactNode;
date: string;
title: string;
}
export const TimelineEvent = withStyles(styles)(
({ classes, children, date, title }: TimelineEventProps) => (
<div className={classes.root}>
<span className={classes.dot} />
{children ? (
<ExpansionPanel className={classes.panel} elevation={0}>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<Typography>{title}</Typography>
<Typography className={classes.dateExpander}>{title}</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>{children}</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
) : (
<div className={classes.noExpander}>
<Typography>{title}</Typography>
<Typography className={classes.date}>
<DateTime date={date} />
</Typography>
</div>
)}
</div>
)
);
TimelineEvent.displayName = "TimelineEvent";
export default TimelineEvent;