styled-components-mq
Compose styled components 💅 media queries in an elegant way:
- provides a clean and intuitive API allowing you to create complex breakpoints without repeating yourself
- compiles to
em
-based queries
Install
The easiest way to use styled-components-mq is to install it from NPM and include it in your own build process
yarn add styled-components-mq
Usage
Syntax
- mq($name: <$responsiveSuffix>)
- mq([$from: <$responsiveSuffix>], [$until: <$responsiveSuffix>])
$from
is inclusive while$until
is exclusive. They can be chained together or used independently.
;;const mq = ; const Column = styleddiv` width: 100 /* Portrait Phones ONLY */ /* Landscape Phones(544px) and up */ /* Landscape Phones up to Large Devices(excluding large devices) */ /* Smallest breakpoint(i.e. Portrait Phones) up to Large Devices(excluding large devices) */ `;
Recommended Usage
We can use the <ThemeProvider>
wrapper component to pass the media query object down the tree.
;const mq = ; const theme = bodyColor: 'green' mq; <ThemeProvider theme=theme> <App /></ThemeProvider> const Column = styleddiv` width: 100; color: ; `;
API
mediaQueries(breakpoints)
You can easily customize the breakpoint names and values:
Properties:
breakpoints
:Object
containing the breakpoints rules
Example:
;; const mq = ; const Column = styleddiv` width: 100; /* Landscape Phones up to Large Devices(excluding large devices) */ `;
Defaults
- Portrait Phones:
0px
up to543px
- Landscape Phones:
544px
up to767px
- Tablets:
768px
up to767px
- Large Devices:
992px
and up
Tests
yarn run test