mirror of
https://github.com/SomboChea/ui
synced 2024-05-20 18:31:37 +07:00
d1ce82854a
* refactor: replaced class by func.comp * refactor: replacing jest test by react-testing-library * refactor: added test todos * feat: added more unit tests * fix: fixed tooltip import * fix: fixed test * fix: fixed typo * fix: fixed imports
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import React, { useState } from 'react';
|
|
|
|
import Search from '../Search';
|
|
import { getRegistryURL } from '../../utils/url';
|
|
import Button from '../../muiComponents/Button';
|
|
|
|
import { NavBar, InnerNavBar, MobileNavBar, InnerMobileNavBar } from './styles';
|
|
import HeaderLeft from './HeaderLeft';
|
|
import HeaderRight from './HeaderRight';
|
|
import HeaderInfoDialog from './HeaderInfoDialog';
|
|
|
|
interface Props {
|
|
logo?: string;
|
|
username?: string;
|
|
onLogout: () => void;
|
|
onToggleLoginModal: () => void;
|
|
scope: string;
|
|
withoutSearch?: boolean;
|
|
}
|
|
|
|
/* eslint-disable react/jsx-max-depth */
|
|
/* eslint-disable react/jsx-no-bind*/
|
|
const Header: React.FC<Props> = ({ logo, withoutSearch, username, onLogout, onToggleLoginModal, scope }) => {
|
|
const [isInfoDialogOpen, setOpenInfoDialog] = useState();
|
|
const [showMobileNavBar, setShowMobileNavBar] = useState();
|
|
|
|
return (
|
|
<>
|
|
<NavBar position="static">
|
|
<InnerNavBar>
|
|
<HeaderLeft logo={logo} />
|
|
<HeaderRight
|
|
onLogout={onLogout}
|
|
onOpenRegistryInfoDialog={() => setOpenInfoDialog(true)}
|
|
onToggleLogin={onToggleLoginModal}
|
|
onToggleMobileNav={() => setShowMobileNavBar(!showMobileNavBar)}
|
|
username={username}
|
|
withoutSearch={withoutSearch}
|
|
/>
|
|
</InnerNavBar>
|
|
<HeaderInfoDialog isOpen={isInfoDialogOpen} onCloseDialog={() => setOpenInfoDialog(false)} registryUrl={getRegistryURL()} scope={scope} />
|
|
</NavBar>
|
|
{showMobileNavBar && !withoutSearch && (
|
|
<MobileNavBar>
|
|
<InnerMobileNavBar>
|
|
<Search />
|
|
</InnerMobileNavBar>
|
|
<Button color="inherit">{'Cancel'}</Button>
|
|
</MobileNavBar>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Header;
|