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

85 lines
1.8 KiB
TypeScript
Raw Normal View History

import { Typography } from "@material-ui/core";
import { makeStyles } from "@saleor/theme";
2019-08-09 11:14:35 +00:00
import classNames from "classnames";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
children: theme.mixins.gutters({}),
constantHeight: {
height: 56
},
hr: {
border: "none",
borderTop: `1px solid ${theme.palette.divider}`,
height: 0,
marginBottom: 0,
marginTop: 0,
width: "100%"
},
root: theme.mixins.gutters({
alignItems: "center",
display: "flex",
minHeight: 56
}),
title: {
flex: 1,
fontWeight: 500,
lineHeight: 1
},
toolbar: {
marginRight: -theme.spacing(1)
}
2019-10-30 14:34:24 +00:00
}),
2019-12-03 15:28:40 +00:00
{ name: "CardTitle" }
);
2019-06-19 14:40:52 +00:00
2019-10-30 14:34:24 +00:00
interface CardTitleProps {
2019-06-19 14:40:52 +00:00
children?: React.ReactNode;
className?: string;
height?: "default" | "const";
title: string | React.ReactNode;
toolbar?: React.ReactNode;
onClick?: (event: React.MouseEvent<any>) => void;
}
2019-10-30 14:34:24 +00:00
const CardTitle: React.FC<CardTitleProps> = props => {
const {
2019-06-19 14:40:52 +00:00
className,
children,
height,
title,
toolbar,
onClick,
2019-10-30 14:34:24 +00:00
...rest
} = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<>
<div
className={classNames(classes.root, {
[className]: !!className,
[classes.constantHeight]: height === "const"
})}
2019-10-30 14:34:24 +00:00
{...rest}
2019-06-19 14:40:52 +00:00
>
<Typography
className={classes.title}
variant="h5"
onClick={onClick}
component="span"
>
{title}
</Typography>
<div className={classes.toolbar}>{toolbar}</div>
</div>
<div className={classes.children}>{children}</div>
<hr className={classes.hr} />
</>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
CardTitle.displayName = "CardTitle";
export default CardTitle;