|
| 1 | +import Box from "@material-ui/core/Box" |
| 2 | +import Typography from "@material-ui/core/Typography" |
| 3 | +import { makeStyles } from "@material-ui/core/styles" |
| 4 | +import React from "react" |
| 5 | +import { HeaderButton } from "./HeaderButton" |
| 6 | + |
| 7 | +export interface HeaderAction { |
| 8 | + readonly text: string |
| 9 | + readonly onClick?: (event: MouseEvent) => void |
| 10 | +} |
| 11 | + |
| 12 | +export interface HeaderProps { |
| 13 | + description?: string |
| 14 | + title: string |
| 15 | + subTitle?: string |
| 16 | + action?: HeaderAction |
| 17 | +} |
| 18 | + |
| 19 | +export const Header: React.FC<HeaderProps> = ({ description, title, subTitle, action }) => { |
| 20 | + const styles = useStyles() |
| 21 | + |
| 22 | + return ( |
| 23 | + <div className={styles.root}> |
| 24 | + <div className={styles.top}> |
| 25 | + <div className={styles.topInner}> |
| 26 | + <Box display="flex" flexDirection="column" minWidth={0}> |
| 27 | + <div> |
| 28 | + <Box display="flex" alignItems="center"> |
| 29 | + <Typography variant="h3" className={styles.title}> |
| 30 | + <Box component="span" maxWidth="100%" overflow="hidden" textOverflow="ellipsis"> |
| 31 | + {title} |
| 32 | + </Box> |
| 33 | + </Typography> |
| 34 | + |
| 35 | + {subTitle && ( |
| 36 | + <div className={styles.subtitle}> |
| 37 | + <Typography style={{ fontSize: 16 }}>{subTitle}</Typography> |
| 38 | + </div> |
| 39 | + )} |
| 40 | + </Box> |
| 41 | + {description && ( |
| 42 | + <Typography variant="caption" className={styles.description}> |
| 43 | + {description} |
| 44 | + </Typography> |
| 45 | + )} |
| 46 | + </div> |
| 47 | + </Box> |
| 48 | + |
| 49 | + {action && ( |
| 50 | + <> |
| 51 | + <div className={styles.actions}> |
| 52 | + <HeaderButton key={action.text} {...action} /> |
| 53 | + </div> |
| 54 | + </> |
| 55 | + )} |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + ) |
| 60 | +} |
| 61 | + |
| 62 | +const secondaryText = "#B5BFD2" |
| 63 | +const useStyles = makeStyles((theme) => ({ |
| 64 | + root: {}, |
| 65 | + top: { |
| 66 | + position: "relative", |
| 67 | + display: "flex", |
| 68 | + alignItems: "center", |
| 69 | + height: 150, |
| 70 | + background: theme.palette.hero.main, |
| 71 | + boxShadow: theme.shadows[3], |
| 72 | + }, |
| 73 | + topInner: { |
| 74 | + display: "flex", |
| 75 | + alignItems: "center", |
| 76 | + maxWidth: "1380px", |
| 77 | + margin: "0 auto", |
| 78 | + flex: 1, |
| 79 | + height: 68, |
| 80 | + minWidth: 0, |
| 81 | + }, |
| 82 | + title: { |
| 83 | + display: "flex", |
| 84 | + alignItems: "center", |
| 85 | + fontWeight: "bold", |
| 86 | + whiteSpace: "nowrap", |
| 87 | + minWidth: 0, |
| 88 | + color: theme.palette.primary.contrastText, |
| 89 | + }, |
| 90 | + description: { |
| 91 | + display: "block", |
| 92 | + marginTop: theme.spacing(1) / 2, |
| 93 | + marginBottom: -26, |
| 94 | + color: secondaryText, |
| 95 | + }, |
| 96 | + subtitle: { |
| 97 | + position: "relative", |
| 98 | + top: 2, |
| 99 | + display: "flex", |
| 100 | + alignItems: "center", |
| 101 | + borderLeft: `1px solid ${theme.palette.divider}`, |
| 102 | + height: 28, |
| 103 | + marginLeft: 16, |
| 104 | + paddingLeft: 16, |
| 105 | + color: secondaryText, |
| 106 | + }, |
| 107 | + actions: { |
| 108 | + paddingLeft: "50px", |
| 109 | + paddingRight: 0, |
| 110 | + flex: 1, |
| 111 | + display: "flex", |
| 112 | + flexDirection: "row", |
| 113 | + justifyContent: "flex-end", |
| 114 | + alignItems: "center", |
| 115 | + }, |
| 116 | +})) |
0 commit comments