-
Notifications
You must be signed in to change notification settings - Fork 0
Media Queries
Douglas Waltman II edited this page Oct 2, 2019
·
2 revisions
const Test = styled.div`
${minWidth(420)`
display: flex;
`}
`;
const Test = styled.div`
${maxWidth(420)`
display: flex;
`}
`;
const Test = styled.div`
${minHeight(420)`
display: flex;
`}
`;
const Test = styled.div`
${maxHeight(420)`
display: flex;
`}
`;
Rather than repeating yourself with the same breakpoint values, define theme once in a media query helper, and then call them by name:
// lib/styles/media.js
import { minWidth } from 'styled-tidy'
export default {
xsmall: minWidth(400),
small: minWidth(640),
medium: minWidth(832),
large: minWidth(1024),
xlarge: minWidth(1200),
}
Then adding breakpoints is a breeze:
// my-component.js
import styled from 'styled-components'
import { rem } from 'styled-tidy'
import media from 'lib/styles/media'
const Example = styled.div`
font-size: ${rem(14)};
${media.medium`
font-size: ${rem(16)}
`}
${media.large`
font-size: ${rem(18)}
`}
`