blob: 752e4bceb358ef2fe78a3a18b6442efda8cb0282 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import React, { useState } from 'react';
import {
AppBar,
Toolbar,
IconButton,
useScrollTrigger,
Slide
} from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import { Search, Clear } from '@material-ui/icons';
import SearchBar from './SearchBar';
interface PropTypes {
menu: JSX.Element;
logo: JSX.Element;
}
const useStyles = makeStyles({
root: {
display: 'flex',
justifyContent: 'space-between'
}
});
const MobileHeader: React.FC<PropTypes> = React.memo(props => {
const classes = useStyles();
const trigger = useScrollTrigger();
const [isSearchOpen, setIsSearchOpen] = useState<boolean>(false);
const { menu, logo } = props;
const handleToggle = () => {
setIsSearchOpen(value => !value);
};
return (
<Slide appear={false} direction="down" in={!trigger}>
<AppBar position="fixed">
<Toolbar className={classes.root}>
{menu}
{isSearchOpen ? <SearchBar callback={handleToggle} /> : logo}
<IconButton onClick={handleToggle}>
{isSearchOpen ? <Clear /> : <Search />}
</IconButton>
</Toolbar>
</AppBar>
</Slide>
);
});
export default MobileHeader;
|