From ddb2ba73406d6982e81bc779c155e6c687f98bb5 Mon Sep 17 00:00:00 2001
From: Eug-VS <eug-vs@keemail.me>
Date: Mon, 3 Feb 2020 20:19:57 +0300
Subject: feat: separate HeaderTab component

@asketonim, feel free to correct these changes
---
 src/lib/Header/Header.tsx | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

(limited to 'src/lib/Header/Header.tsx')

diff --git a/src/lib/Header/Header.tsx b/src/lib/Header/Header.tsx
index 2b13e3f..cc73fd9 100644
--- a/src/lib/Header/Header.tsx
+++ b/src/lib/Header/Header.tsx
@@ -10,14 +10,13 @@ import {
 
 import { makeStyles } from '@material-ui/core/styles';
 
-
 interface PropTypes {
   logo: {
     icon: React.ReactNode;
     title: string;
   };
   contents: {
-    [key: string]: React.ReactNode;
+    [key: string]: React.ReactNode | null;
   };
   page: string;
   setPage: any;
@@ -49,6 +48,19 @@ const useStyles = makeStyles((theme: any) => ({
 const Header: React.FC<PropTypes> = ({ logo, contents, page, setPage }) => {
   const classes = useStyles();
 
+  const HeaderTab: React.FC<{ item: string }> = ({ item }) => {
+    const icon = contents[item];
+    return (
+      <Tab
+        label={item}
+        icon={icon}
+        value={item}
+        className={classes.tab}
+        key={item}
+      />
+    )
+  };
+
   const handleChange = (event: any, newPage: string) => {
     setPage(newPage);
   };
@@ -61,14 +73,8 @@ const Header: React.FC<PropTypes> = ({ logo, contents, page, setPage }) => {
         {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}
-          />
+        {contents && Object.keys(contents).map((item: string) => (
+          <HeaderTab item={item}/>
         ))}
       </Tabs>
     </Toolbar>
-- 
cgit v1.2.3

