Skip to content

Commit

Permalink
Add media queries
Browse files Browse the repository at this point in the history
  • Loading branch information
bchiang7 committed Aug 21, 2018
1 parent b7b8a85 commit e6dd14f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:react/recommended"],
"plugins": ["prettier"],
"extends": [
"eslint:recommended",
"plugin:jsx-a11y/recommended",
"plugin:prettier/recommended",
"plugin:react/recommended"
],
"plugins": ["jsx-a11y"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
Expand All @@ -17,15 +22,12 @@
"rules": {
"no-console": ["error", { "allow": ["warn", "error"] }],

// Best Practices
"curly": "error",
"eqeqeq": "error",
"no-eq-null": "error",

// Variables
"no-use-before-define": ["error", "nofunc"],

// Stylistic Issues
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
Expand All @@ -41,15 +43,13 @@
"space-before-function-paren": ["error", "never"],
"space-infix-ops": "error",

// ECMAScript 6
"arrow-spacing": "error",
"no-duplicate-imports": "error",
"no-useless-constructor": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-template": "error",

// React
"react/no-unescaped-entities": ["error", { "forbid": [">", "\"", "}"] }]
}
}
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"babel-eslint": "^8.2.6",
"eslint": "^5.3.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-react": "^7.11.1",
"husky": "^0.14.3",
Expand Down
2 changes: 2 additions & 0 deletions src/style/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import theme from './theme';
import base from './base';
import mixins from './mixins';
import media from './media';
import Img from './Img';
import A from './A';
import Button from './Button';
Expand All @@ -20,6 +21,7 @@ export {
theme,
base,
mixins,
media,
Img,
A,
Button,
Expand Down
30 changes: 30 additions & 0 deletions src/style/media.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { css } from 'styled-components';

const sizes = {
giant: 1440,
desktop: 1000,
tablet: 768,
phablet: 480,
phone: 376,
};

// iterate through the sizes and create a media template
export const media = Object.keys(sizes).reduce((accumulator, label) => {
// use em in breakpoints to work properly cross-browser and support users
// changing their browsers font-size: https://zellwk.com/blog/media-query-units/
const emSize = sizes[label] / 16;
accumulator[label] = (...args) => css`
@media (max-width: ${emSize}em) {
${css(...args)};
}
`;
return accumulator;
}, {});

// Usage
// const Container = styled.div`
// color: #333;
// ${media.desktop`padding: 0 20px;`}
// ${media.tablet`padding: 0 10px;`}
// ${media.phone`padding: 0 5px;`}
// `;

0 comments on commit e6dd14f

Please sign in to comment.