From afda959598a04553e0a27c5b543f161472b79828 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Wed, 12 Aug 2020 02:32:57 +0300
Subject: feat: implement mobile search

---
 src/components/Header/MobileHeader.tsx | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

(limited to 'src/components/Header/MobileHeader.tsx')

diff --git a/src/components/Header/MobileHeader.tsx b/src/components/Header/MobileHeader.tsx
index a20d54a..752e4bc 100644
--- a/src/components/Header/MobileHeader.tsx
+++ b/src/components/Header/MobileHeader.tsx
@@ -1,16 +1,18 @@
-import React from 'react';
+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;
-  search: JSX.Element;
 }
 
 const useStyles = makeStyles({
@@ -24,15 +26,23 @@ const useStyles = makeStyles({
 const MobileHeader: React.FC<PropTypes> = React.memo(props => {
   const classes = useStyles();
   const trigger = useScrollTrigger();
-  const { menu, search, logo } = props;
+  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}
-          {logo}
-          {search}
+          {isSearchOpen ? <SearchBar callback={handleToggle} /> : logo}
+          <IconButton onClick={handleToggle}>
+            {isSearchOpen ? <Clear /> : <Search />}
+          </IconButton>
         </Toolbar>
       </AppBar>
     </Slide>
-- 
cgit v1.2.3

