diff options
author | asketonim <anton.dubik33@gmail.com> | 2020-02-03 19:53:37 +0300 |
---|---|---|
committer | asketonim <anton.dubik33@gmail.com> | 2020-02-03 19:53:37 +0300 |
commit | cf10bd8925fe8cbffb91e2b282e16f086575bf32 (patch) | |
tree | deb6ca00818fdba03732264e8884c1d2ec4c5e7c /src/lib/Header/Header.tsx | |
parent | 6bbf39de74bbe7437bca5369e9ac751fff8f4fb8 (diff) | |
download | react-benzin-cf10bd8925fe8cbffb91e2b282e16f086575bf32.tar.gz |
feat: migrate Header to TypeScript
Diffstat (limited to 'src/lib/Header/Header.tsx')
-rw-r--r-- | src/lib/Header/Header.tsx | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/lib/Header/Header.tsx b/src/lib/Header/Header.tsx new file mode 100644 index 0000000..85dac4b --- /dev/null +++ b/src/lib/Header/Header.tsx @@ -0,0 +1,79 @@ +import React from 'react'; + +import { + AppBar, + Tabs, + Tab, + Typography, + Toolbar, +} from '@material-ui/core'; + +import { makeStyles } from '@material-ui/core/styles'; + + +interface PropTypes { + logo: { + icon: React.ReactNode; + title: string; + }; + contents: any; + page: string; + setPage: any; +} + + + +const useStyles = makeStyles((theme: any) => ({ + root: { + background: theme.palette.background.elevation2, + color: theme.palette.text.primary, + paddingLeft: theme.spacing(3), + }, + logo: { + margin: theme.spacing(0, 3, 0, 1), + }, + tab: { + '& .MuiTab-wrapper': { + padding: theme.spacing(2), + flexDirection: 'row', + fontSize: '0.8125rem', + '& svg': { + marginRight: theme.spacing(1), + marginBottom: '0 !important', + } + } + } +})); + + +const Header: React.FC<PropTypes> = ({ logo, contents, page, setPage }) => { + const classes = useStyles(); + + const handleChange = (event: any, newPage: string) => { + setPage(newPage); + }; + + return ( + <AppBar position="sticky" className={classes.root}> + <Toolbar> + {logo.icon} + <Typography variant="h5" className={classes.logo} color="primary"> + {logo.title} + </Typography> + <Tabs onChange={handleChange} value={page}> + {contents && Object.keys(contents).map(item => ( + <Tab + label={item} + icon={contents[item]} + value={item} + className={classes.tab} + key={item} + /> + ))} + </Tabs> + </Toolbar> + </AppBar> + ); +}; + +export default Header; |