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

102 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";
2019-10-30 14:34:24 +00:00
import { makeStyles } from "@material-ui/core/styles";
2019-06-19 14:40:52 +00:00
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-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
date: {
color: theme.typography.caption.color
2019-06-19 14:40:52 +00:00
},
2019-12-03 15:28:40 +00:00
dateExpander: {
color: theme.typography.caption.color,
2019-06-19 14:40:52 +00:00
position: "absolute",
2019-12-03 15:28:40 +00:00
right: theme.spacing(3)
2019-06-19 14:40:52 +00:00
},
2019-12-03 15:28:40 +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",
marginBottom: theme.spacing(),
marginLeft: theme.spacing(3),
width: "100%"
},
panel: {
"&:before": {
display: "none"
},
background: "none",
width: "100%"
},
root: {
"&:last-child:after": {
background: theme.palette.background.default,
content: "''",
height: "calc(50% - 4px)",
left: -theme.spacing(3) - 2,
position: "absolute",
top: "calc(50% + 4px)",
width: "2px"
},
alignItems: "center",
display: "flex",
marginBottom: theme.spacing(3),
position: "relative",
width: "100%"
}
}),
{ name: "TimelineEvent" }
);
2019-06-19 14:40:52 +00:00
2019-10-30 14:34:24 +00:00
interface TimelineEventProps {
2019-06-19 14:40:52 +00:00
children?: React.ReactNode;
date: string;
title: string;
}
2019-10-30 14:34:24 +00:00
export const TimelineEvent: React.FC<TimelineEventProps> = props => {
const { children, date, title } = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<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>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
TimelineEvent.displayName = "TimelineEvent";
export default TimelineEvent;