|
| 1 | +import React from 'react'; |
| 2 | +import AppBar from '@material-ui/core/AppBar'; |
| 3 | +import Button from '@material-ui/core/Button'; |
| 4 | +import Toolbar from '@material-ui/core/Toolbar'; |
| 5 | +import Typography from '@material-ui/core/Typography'; |
| 6 | +import { makeStyles } from '@material-ui/core/styles'; |
| 7 | +import { Link as RouterLink } from 'react-router-dom'; |
| 8 | + |
| 9 | +const useStyles = makeStyles((theme) => ({ |
| 10 | + '@global': { |
| 11 | + ul: { |
| 12 | + margin: 0, |
| 13 | + padding: 0, |
| 14 | + listStyle: 'none', |
| 15 | + }, |
| 16 | + a: { |
| 17 | + textDecoration: 'none', |
| 18 | + }, |
| 19 | + }, |
| 20 | + appBar: { |
| 21 | + borderBottom: `1px solid ${theme.palette.divider}`, |
| 22 | + }, |
| 23 | + toolbar: { |
| 24 | + flexWrap: 'wrap', |
| 25 | + justifyContent: 'space-between', |
| 26 | + }, |
| 27 | + link: { |
| 28 | + margin: theme.spacing(1, 1.5), |
| 29 | + }, |
| 30 | + heroContent: { |
| 31 | + padding: theme.spacing(8, 0, 6), |
| 32 | + }, |
| 33 | + cardHeader: { |
| 34 | + backgroundColor: |
| 35 | + theme.palette.type === 'light' |
| 36 | + ? theme.palette.grey[200] |
| 37 | + : theme.palette.grey[700], |
| 38 | + }, |
| 39 | + cardPricing: { |
| 40 | + display: 'flex', |
| 41 | + justifyContent: 'center', |
| 42 | + alignItems: 'baseline', |
| 43 | + marginBottom: theme.spacing(2), |
| 44 | + }, |
| 45 | + footer: { |
| 46 | + borderTop: `1px solid ${theme.palette.divider}`, |
| 47 | + marginTop: theme.spacing(8), |
| 48 | + paddingTop: theme.spacing(3), |
| 49 | + paddingBottom: theme.spacing(3), |
| 50 | + [theme.breakpoints.up('sm')]: { |
| 51 | + paddingTop: theme.spacing(6), |
| 52 | + paddingBottom: theme.spacing(6), |
| 53 | + }, |
| 54 | + }, |
| 55 | +})); |
| 56 | + |
| 57 | +export default function Header({ signedIn, onSignOut }) { |
| 58 | + const classes = useStyles(); |
| 59 | + |
| 60 | + const onClick = () => { |
| 61 | + if (signedIn && onSignOut) { |
| 62 | + onSignOut(); |
| 63 | + } |
| 64 | + }; |
| 65 | + |
| 66 | + return ( |
| 67 | + <React.Fragment> |
| 68 | + <AppBar |
| 69 | + position="static" |
| 70 | + color="default" |
| 71 | + elevation={0} |
| 72 | + className={classes.appBar} |
| 73 | + > |
| 74 | + <Toolbar className={classes.toolbar}> |
| 75 | + <Typography |
| 76 | + variant="h6" |
| 77 | + color="inherit" |
| 78 | + noWrap |
| 79 | + component={RouterLink} |
| 80 | + to="/" |
| 81 | + > |
| 82 | + App |
| 83 | + </Typography> |
| 84 | + <Button |
| 85 | + color="primary" |
| 86 | + variant="outlined" |
| 87 | + className={classes.link} |
| 88 | + component={RouterLink} |
| 89 | + to={signedIn ? '/' : '/auth/signin'} |
| 90 | + onClick={onClick} |
| 91 | + > |
| 92 | + {signedIn ? 'Logout' : 'Login'} |
| 93 | + </Button> |
| 94 | + </Toolbar> |
| 95 | + </AppBar> |
| 96 | + </React.Fragment> |
| 97 | + ); |
| 98 | +} |
0 commit comments