import * as React from 'react' import styled from 'styled-components' import {minWidthFactor} from '../../utilities/mixins'; import {configVar} from '../../utilities/helpers' const Base = styled('div')({ position: 'fixed', top: 0, left: 0, width: '100%', height: 'var(--height-topbar, 4rem)', zIndex: 2, backgroundColor: 'var(--color-bg, white)', '~ *': { paddingTop: 'var(--height-topbar, 4rem)', }, '~ main ~ *': { paddingTop: 0, }, [minWidthFactor(3)]: { '~ main ~ *': { paddingTop: 'var(--height-topbar, 4rem)', }, }, }) const Container = styled('div')({ padding: '0 1rem', boxSizing: 'border-box', margin: '0 auto', maxWidth: `calc(${configVar('base-width')} * 2)`, width: '100%', height: '100%', display: 'flex', alignItems: 'center', }) const NarrowContainer = styled(Container)({ maxWidth: configVar('base-width'), }) const WideContainer = styled(Container)({ [minWidthFactor(3)]: { maxWidth: `calc(${configVar('base-width')} * 3)`, }, }) const BrandContainer = styled('div')({ }) const CenterContainer = styled('div')({ flex: 'auto', padding: '0 1rem', boxSizing: 'border-box', ':first-child': { paddingLeft: 0, }, }) const ActionContainer = styled('div')({ display: 'flex', alignItems: 'center', justifyContent: 'flex-end', height: '100%', whiteSpace: 'nowrap', [minWidthFactor(2)]: { minWidth: '8rem', }, }) const LinkContainer = styled('div')({ width: 'var(--height-topbar, 4rem)', height: '100%', '> *': { width: '100%', height: '100%', display: 'inline-grid', placeContent: 'center', }, }) const MenuLinkContainer = styled(LinkContainer)({ [minWidthFactor(3)]: { position: 'absolute', left: -999999, }, }) const CONTAINER_COMPONENTS = { narrow: NarrowContainer, normal: Container, wide: WideContainer, } type Props = { span?: keyof typeof CONTAINER_COMPONENTS, brand?: React.ReactNode, menuLink?: React.ReactNode, userLink?: React.ReactNode, } const TopBar: React.FC = ({ span = 'normal', brand, menuLink, userLink, children, }) => { const { [span as keyof typeof CONTAINER_COMPONENTS]: ContainerComponent = Container } = CONTAINER_COMPONENTS return ( { Boolean(brand as unknown) && ( {brand} ) } {children} { Boolean(menuLink as unknown) && ( {menuLink} ) } { Boolean(userLink as unknown) && ( {userLink} ) } ) } export default TopBar