UNPKG

@navinc/base-react-components

Version:
77 lines (66 loc) 1.94 kB
import React from 'react' import styled, { withTheme } from 'styled-components' import Copy from './copy.js' import Header from './header.js' import isRebrand from './is-rebrand.js' const Label = styled(Copy)`` const LabelAlignmentWrapper = styled.div` display: flex; height: 30px; align-items: flex-end; ` const Value = styled(Header).attrs(() => ({ size: 'md', as: Copy }))` min-height: 30px; word-break: break-word; ${({ theme }) => isRebrand(theme) && 'font-weight: 800;'} ` const Wrapper = styled.div` width: 122px; max-width: 270px; display: flex; flex-flow: column nowrap; border-bottom: solid 1px ${({ theme }) => (isRebrand(theme) ? 'none' : theme.neutral300)}; border-top: solid 1px ${({ theme }) => (isRebrand(theme) ? 'none' : theme.white)}; padding-bottom: 16px; padding-top: 16px; flex-grow: 1; ` const Container = styled.div` display: flex; flex-flow: row wrap; align-items: stretch; ${({ borderColor }) => (borderColor ? `border: 1px solid ${borderColor}` : '')}; border-radius: 4px; padding: 16px; flex-grow: ${({ length = 1 }) => length}; flex-shrink: ${({ length = 1 }) => length}; margin-top: -16px; /* these margin-tops are to give space between rows when they wrap */ margin-right: -16px; & > * { margin-right: 16px; margin-top: 16px; } & > & { margin-top: 16px; margin-right: 16px; & > ${Wrapper} { margin-top: 0; border: none; padding-bottom: 0; padding-top: 0; } } ` export const LabelOverValue = withTheme(({ value = '', label = '', theme }) => ( <Wrapper> <LabelAlignmentWrapper> <Label size={isRebrand(theme) ? 'md' : 'xs'}>{label}</Label> </LabelAlignmentWrapper> <Value>{value}</Value> </Wrapper> )) export const LabelOverValueContainer = ({ children = [], borderColor }) => ( <Container length={children.length} borderColor={borderColor}> {children} </Container> )