Skip to content

Instantly share code, notes, and snippets.

@simonfranzen
Last active October 18, 2018 12:28
Show Gist options
  • Save simonfranzen/4cc070d0e0e88da21faf7210e8ca37ef to your computer and use it in GitHub Desktop.
Save simonfranzen/4cc070d0e0e88da21faf7210e8ca37ef to your computer and use it in GitHub Desktop.
styled-component boilerplate
import styled, { css } from 'styled-components'
import { media } from 'styled-bootstrap-grid'
import { padding } from 'polished'
const Sample = styled.div`
/* 1. Default mobile first styles */
${ padding('10px', '14px', '10px', '8px') }
color: black;
/* 2. DOM element states (hover, active, ...) */
&:hover{
color: green;
}
/* 3. Modifiers with properties */
${props => props.primary && css`
color: red;
`}
/* 4. Child element stylings (layouting only) */
& > ${Header} {
font-size: 2em;
}
/* 5. Media queries (order phone -> giant) */
${media.phone`
`}
${media.tablet`
`}
${media.desktop`
`}
${media.giant`
`}
`
export default Sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment