Skip to content

Commit

Permalink
Merge pull request #62 from arcticicestudio/feature/gh-61-base-media-…
Browse files Browse the repository at this point in the history
…query-setup

Base Media Query Setup
  • Loading branch information
arcticicestudio authored Dec 5, 2018
2 parents c014694 + b209edb commit 6b78d69
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/styles/theme/breakpoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.3.0
*/

/**
* Breakpoints for the "mobile-first" pattern based on and adjusted to the site content.
*
* @type {Object}
* @since 0.3.0
*/
const breakpoints = { minimal: 320 };

export default breakpoints;
7 changes: 5 additions & 2 deletions src/styles/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
* @since 0.2.0
*/

import breakpoints from "./breakpoints";
import colors, { nord, palettes } from "./colors";
import globals from "./globals";
import media from "./media";
import motion from "./motion";
import normalize from "./normalize";
import { themedMode, themedModeVariant } from "./utils";
import { generateMediaQuery, themedMode, themedModeVariant } from "./utils";
import typography from "./typography";
import { MODE_BRIGHT_SNOW_FLURRY, MODE_DARK_NIGHT_FROST, THEME_KEY_MODE } from "./constants";

const theme = { colors, motion, typography };
const theme = { breakpoints, colors, media, motion, typography };

export {
colors,
generateMediaQuery,
globals,
motion,
nord,
Expand Down
34 changes: 34 additions & 0 deletions src/styles/theme/media.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.2.0
*/

import { em } from "polished";

import breakpoints from "./breakpoints";
import typography from "./typography";
import { generateMediaQuery } from "./utils";

/**
* Provides media query template functions based on the configured breakpoints.
*
* @type {Object}
* @since 0.3.0
*/
const media = {
base: generateMediaQuery`(max-width: ${em(breakpoints.minimal - 1, typography.sizes.root)})`,
minimal: generateMediaQuery`(min-width: ${em(breakpoints.minimal, typography.sizes.root)})`,
breakpoints
};

export default media;
35 changes: 35 additions & 0 deletions src/styles/theme/utils/generateMediaQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.3.0
*/

import { css } from "styled-components";

/**
* Generates a tag function for the specified media query that can be used to automatically wrap the tagged template
* literal in its media query.
*
* @param {string} query The string or template literal containing the media query features
* @returns {function} The tag function for the specified media query
* @see https://www.styled-components.com/docs/advanced#media-templates
* @see https://www.styled-components.com/docs/api#css
* @since 0.3.0
*/
const generateMediaQuery = (...query) => (...rules) =>
css`
@media ${css(...query)} {
${css(...rules)};
}
`;

export default generateMediaQuery;
3 changes: 2 additions & 1 deletion src/styles/theme/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* @since 0.2.0
*/

import generateMediaQuery from "./generateMediaQuery";
import themedMode from "./themedMode";
import themedModeVariant from "./themedModeVariant";

export { themedMode, themedModeVariant };
export { generateMediaQuery, themedMode, themedModeVariant };

0 comments on commit 6b78d69

Please sign in to comment.