index.js

import styled from 'styled-components'
import { useAuthContext } from '../../../state/AuthContext'
import Button from '../../atoms/button'
import StyledLink from '../../atoms/link'

export function Header() {
  const authObj = useAuthContext()
  const { authData, onLogout } = authObj
  return <StyledHeader isLoggedIn={Boolean(authData)} onLogout={onLogout} />
}

function HeaderSkeleton(props) {
  const { className } = props
  return (
    <div className={`menu ${className}`}>
      <div className="menu-items left">
        <div className="menu-item logo">
          <StyledLink to="/" classes="logo">
            Bubbles
          </StyledLink>
        </div>
      </div>
      <div className="menu-items right">
        <div className="menu-item account">
          <StyledLink to="account" classes="account">
            Account
          </StyledLink>
        </div>
        <div className="menu-item auth">
          <LoginLogoutBtn {...props} />
        </div>
      </div>
    </div>
  )
}

function LoginLogoutBtn({ isLoggedIn, onLogout }) {
  return isLoggedIn ? (
    <Button text="Log Out" classes="sign-out" onClick={onLogout} />
  ) : (
    <StyledLink to="login" classes="login">
      Login
    </StyledLink>
  )
}

const StyledHeader = styled(HeaderSkeleton)`
  display: flex;
  padding: 1.2rem;
  align-items: center;
  border-bottom: 2px solid #cccccc;
  border-top: 2px solid #cccccc;
  justify-content: space-between;
  .menu-item {
    cursor: pointer;
  }
  .menu-item.logo {
    font-weight: 300;
    font-size: 1.4rem;
  }
  .menu-items.right {
    display: flex;
    align-items: center;
  }
  .menu-items.right .menu-item {
    padding-left: 24px;
  }
`