saleor-dashboard/src/components/AppHeader/AppHeader.tsx

82 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Portal from "@material-ui/core/Portal";
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 ArrowBackIcon from "@material-ui/icons/ArrowBack";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
import AppHeaderContext from "../AppLayout/AppHeaderContext";
import Skeleton from "../Skeleton";
export interface AppHeaderProps {
children: React.ReactNode;
onBack();
}
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
backArrow: {
fontSize: 30
2019-09-12 10:38:23 +00:00
},
2019-12-03 15:28:40 +00:00
menuButton: {
flex: "0 0 auto",
marginLeft: -theme.spacing(2),
marginRight: theme.spacing(),
marginTop: -theme.spacing(2)
},
root: {
"&:hover": {
color: theme.typography.body1.color
},
alignItems: "center",
color: theme.palette.grey[500],
cursor: "pointer",
display: "flex",
marginTop: theme.spacing(0.5),
transition: theme.transitions.duration.standard + "ms",
[theme.breakpoints.down("sm")]: {
display: "none"
}
},
skeleton: {
marginBottom: theme.spacing(2),
width: "10rem"
},
title: {
color: "inherit",
flex: 1,
marginLeft: theme.spacing(),
textTransform: "uppercase",
[theme.breakpoints.down("sm")]: {
display: "none"
}
2019-11-04 19:31:23 +00:00
}
2019-12-03 15:28:40 +00:00
}),
{ name: "AppHeader" }
);
2019-11-04 19:31:23 +00:00
2019-10-30 14:34:24 +00:00
const AppHeader: React.FC<AppHeaderProps> = props => {
const { children, onBack } = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<AppHeaderContext.Consumer>
{anchor =>
anchor ? (
<Portal container={anchor.current}>
<div className={classes.root} onClick={onBack}>
2019-09-12 10:38:23 +00:00
<ArrowBackIcon className={classes.backArrow} />
2019-06-19 14:40:52 +00:00
{children ? (
<Typography className={classes.title}>{children}</Typography>
) : (
<Skeleton className={classes.skeleton} />
)}
</div>
</Portal>
) : null
}
</AppHeaderContext.Consumer>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
AppHeader.displayName = "AppHeader";
export default AppHeader;