Header.tsx 2.29 KiB
Newer Older
Andrei Eres's avatar
Andrei Eres committed
import React from 'react'
Andrei Eres's avatar
Andrei Eres committed
import styled from 'styled-components'
import { EXT_NAME } from '../../utils/constants'
Andrei Eres's avatar
Andrei Eres committed
import { BaseProps } from '../types'
import { goHome, goTo } from '../utils/routing'
Andrei Eres's avatar
Andrei Eres committed

Andrei Eres's avatar
Andrei Eres committed
type Props = BaseProps & {
Andrei Eres's avatar
Andrei Eres committed
  showAdd?: boolean
  showBackArrow?: boolean
  smallMargin?: boolean
  text?: React.ReactNode
}

const Header: React.FC<Props> = ({
  className,
  showAdd,
  showBackArrow,
  smallMargin,
  text,
}) => {
  const toggleAdd = () => goTo('/account/import-qr')

  return (
    <div className={`${className} ${smallMargin ? 'smallMargin' : ''}`}>
      <div className='container'>
        <div className='branding'>
          {showBackArrow && (
Andrei Eres's avatar
Andrei Eres committed
            <button className='backlink' onClick={goHome}>
Andrei Eres's avatar
Andrei Eres committed
              Back
            </button>
          )}
          <span className='logoText'>{text || EXT_NAME}</span>
        </div>
        <div className='popupMenus'>
          {showAdd && (
            <button className='popupToggle' onClick={toggleAdd}>
              Add
            </button>
          )}
        </div>
      </div>
    </div>
  )
}

export default styled(Header)`
  max-width: 100%;
  box-sizing: border-box;
  font-weight: normal;
  margin: 0;
  position: relative;
  margin-bottom: 25px;

  && {
    padding: 0 0 0;
  }

  > .container {
    display: flex;
    justify-content: space-between;
    width: 100%;
Andrei Eres's avatar
Andrei Eres committed
    border-bottom: 1px solid ${({ theme }: Props) => theme.inputBorderColor};
Andrei Eres's avatar
Andrei Eres committed
    min-height: 70px;

    .branding {
      display: flex;
      justify-content: center;
      align-items: center;
Andrei Eres's avatar
Andrei Eres committed
      color: ${({ theme }: Props) => theme.labelColor};
      font-family: ${({ theme }: Props) => theme.fontFamily};
Andrei Eres's avatar
Andrei Eres committed
      text-align: center;
      margin-left: 24px;

      .logoText {
Andrei Eres's avatar
Andrei Eres committed
        color: ${({ theme }: Props) => theme.textColor};
        font-family: ${({ theme }: Props) => theme.fontFamily};
Andrei Eres's avatar
Andrei Eres committed
        font-size: 20px;
        line-height: 27px;
      }
    }

    .backLink {
      display: inline-block;
      vertical-align: middle;
    }

    .popupMenus {
      align-self: center;

      .popupToggle {
        display: inline-block;
        vertical-align: middle;

        &:last-child {
          margin-right: 24px;
        }
      }

      .popupToggle + .popupToggle {
        margin-left: 8px;
      }
    }
  }

  &.smallMargin {
    margin-bottom: 15px;
  }
`