https://github.com/dvpnt/styled-media-helper
:nail_care: Helps manage media queries with styled components
https://github.com/dvpnt/styled-media-helper
breakpoint breakpoints css css-in-js css-in-react cssinjs media media-queries media-query styled-components
Last synced: 9 months ago
JSON representation
:nail_care: Helps manage media queries with styled components
- Host: GitHub
- URL: https://github.com/dvpnt/styled-media-helper
- Owner: dvpnt
- License: mit
- Created: 2018-07-23T12:22:01.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T02:45:25.000Z (about 3 years ago)
- Last Synced: 2025-08-11T01:20:29.480Z (10 months ago)
- Topics: breakpoint, breakpoints, css, css-in-js, css-in-react, cssinjs, media, media-queries, media-query, styled-components
- Language: JavaScript
- Homepage:
- Size: 1.42 MB
- Stars: 76
- Watchers: 5
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# :nail_care: styled-media-helper
[](https://travis-ci.org/dvpnt/styled-media-helper)
[](https://coveralls.io/github/dvpnt/styled-media-helper?branch=master)
[](https://www.npmjs.com/package/styled-media-helper)
This module makes easy to write media queries using [styled-components](https://www.styled-components.com/).
Inspired by [Bootstrap](https://getbootstrap.com/) `media-breakpoint-...` mixins.
## Installation
$ npm install styled-media-helper
## Usage
```js
import styled from 'styled-components';
import mediaHelper from 'styled-media-helper';
const media = mediaHelper({
sm: 320,
md: 768,
lg: 1240
});
export default styled.div`
width: 100px;
height: 100px;
background-color: blue;
${media.up('lg')} {
width: 150px;
}
// Output:
// @media (min-width: 1240px) {
// width: 150px;
// }
${media.down('sm')} {
background-color: black;
}
// Output:
// @media (max-width: 767.98px) {
// background-color: black;
// }
${media.between('sm', 'lg')} {
width: 200px;
}
// Output:
// @media (min-width: 320px) and (max-width: 1239.98px) {
// width: 200px;
// }
${media.only('md')} {
background-color: green;
}
// Output:
// @media (min-width: 768px) and (max-width: 1239.98px) {
// background-color: green;
// }
${media.only('sm')} {
background-color: green;
}
// Output:
// @media (min-width: 320px) and (max-width: 767.98px) {
// background-color: green;
// }
${media.only('lg')} {
border-radius: 15px;
}
// Output:
// @media (min-width: 1240px) {
// border-radius: 15px;
// }
`;
```
## License
[The MIT License (MIT)](/LICENSE)