/** * @prettier * @flow */ import React, { Component } from 'react'; import type { Node } from 'react'; import { Link } from 'react-router-dom'; import Button from '@material-ui/core/Button/index'; import IconButton from '@material-ui/core/IconButton/index'; import MenuItem from '@material-ui/core/MenuItem/index'; import Menu from '@material-ui/core/Menu/index'; import Info from '@material-ui/icons/Info'; import Help from '@material-ui/icons/Help'; import Tooltip from '@material-ui/core/Tooltip/index'; import AccountCircle from '@material-ui/icons/AccountCircle'; import { default as IconSearch } from '@material-ui/icons/Search'; import { getRegistryURL } from '../../utils/url'; import ExternalLink from '../Link'; import Logo from '../Logo'; import RegistryInfoDialog from '../RegistryInfoDialog'; import Label from '../Label'; import Search from '../Search'; import RegistryInfoContent from '../RegistryInfoContent'; import { IProps, IState } from './types'; import type { ToolTipType } from './types'; import { Greetings, NavBar, InnerNavBar, MobileNavBar, InnerMobileNavBar, LeftSide, RightSide, IconSearchButton, SearchWrapper } from './styles'; class Header extends Component { handleLoggedInMenu: Function; handleLoggedInMenuClose: Function; handleOpenRegistryInfoDialog: Function; handleCloseRegistryInfoDialog: Function; handleToggleLogin: Function; renderInfoDialog: Function; constructor(props: IProps) { super(props); this.state = { openInfoDialog: false, registryUrl: getRegistryURL(), showMobileNavBar: false, }; } /** * opens popover menu for logged in user. */ handleLoggedInMenu = (event: SyntheticEvent) => { this.setState({ anchorEl: event.currentTarget, }); }; /** * closes popover menu for logged in user */ handleLoggedInMenuClose = () => { this.setState({ anchorEl: null, }); }; /** * opens registry information dialog. */ handleOpenRegistryInfoDialog = () => { this.setState({ openInfoDialog: true, }); }; /** * closes registry information dialog. */ handleCloseRegistryInfoDialog = () => { this.setState({ openInfoDialog: false, }); }; /** * close/open popover menu for logged in users. */ handleToggleLogin = () => { const { onToggleLoginModal } = this.props; this.setState( { anchorEl: null, }, onToggleLoginModal ); }; handleToggleMNav = () => { const { showMobileNavBar } = this.state; this.setState({ showMobileNavBar: !showMobileNavBar, }); }; handleDismissMNav = () => { this.setState({ showMobileNavBar: false, }); }; renderLeftSide = (): Node => { const { withoutSearch = false } = this.props; return ( {this.renderLogo()} {!withoutSearch && ( )} ); }; renderLogo = (): Node => { const { logo } = this.props; if (logo) { return {'logo'}; } else { return ; } }; renderToolTipIcon = (title: string, type: ToolTipType) => { let content; switch (type) { case 'help': content = ( ); break; case 'info': content = ( ); break; case 'search': content = ( ); break; } return ( {content} ); }; renderRightSide = (): Node => { const { username = '', withoutSearch = false } = this.props; return ( {!withoutSearch && this.renderToolTipIcon('Search packages', 'search')} {this.renderToolTipIcon('Documentation', 'help')} {this.renderToolTipIcon('Registry Information', 'info')} {username ? ( this.renderMenu() ) : ( )} ); }; renderGreetings = () => { const { username = '' } = this.props; return ( <> {`Hi,`}