Skip to content

Instantly share code, notes, and snippets.

@innerdaze
Created April 20, 2018 11:22
Show Gist options
  • Save innerdaze/9770aa7cf818766e894236c1c26d7c3d to your computer and use it in GitHub Desktop.
Save innerdaze/9770aa7cf818766e894236c1c26d7c3d to your computer and use it in GitHub Desktop.
Styled System Box
/**
* Box
*
* Usage:
* <Box
* margin='small|medium|large|none'
* margin={{
* hz: 'small|medium|large|none',
* vt: 'small|medium|large|none'
* }}
* padding='small|medium|large|none'
* padding={{
* hz: 'small|medium|large|none',
* vt: 'small|medium|large|none'
* }}
* >
*
* @type {React.StatelessComponent}
*/
import styled from 'styled-components'
import {
responsiveStyle,
theme,
space,
width,
fontSize,
fontWeight,
color,
flex,
flexWrap,
flexDirection,
alignItems,
alignSelf,
justifyContent,
textAlign,
borderRadius,
borderColor,
borderWidth,
boxShadow,
hover,
focus,
active,
disabled
} from 'styled-system'
const letterSpacing = responsiveStyle({
prop: 'letterSpacing',
cssProperty: 'letter-spacing'
})
const StyledBox = styled.div`
flex: 0 0 auto;
${flex}
${flexWrap}
${flexDirection}
${alignItems}
${alignSelf}
${justifyContent}
${space}
${width}
${fontSize}
${fontWeight}
${letterSpacing}
${color}
${textAlign}
${borderColor}
${borderRadius}
${borderWidth}
${boxShadow}
${hover}
${focus}
${active}
${disabled}
font-family: ${props => props.fontFamily || theme('font.family', 'Arial')};
overflow-y: ${props =>
props.scroll === 'vertical' || props.scroll === 'both' ?
'scroll' :
'visible'};
overflow-x: ${props =>
props.scroll === 'horizontal' || props.scroll === 'both' ?
'scroll' :
'visible'};
display: ${props => (props.flexContainer ? 'flex' : 'block')};
height: ${props => (props.full ? '100%' : props.height || 'auto')};
`
export default StyledBox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment