Skip to content

Commit

Permalink
Implement theme mode utility functions
Browse files Browse the repository at this point in the history
To simplify the usage of styled-theming's `theme()` (1) and
`theme.variants()` API functions, two utility functions has been
implemented:

- `themeMode(modeStyles : object)` — Shorthand function for the `theme`
  API to define styles based on the global theme mode(s).
- `themedModeVariant(modeStyles : object, variantPropName : string)` —
  Shorthand function for the `theme.variants` API to define variant
  styles based on the global theme mode(s).

References:
  (1) https://github.com/styled-components/styled-theming#themename-values

GH-53
  • Loading branch information
arcticicestudio committed Dec 3, 2018
1 parent 687d30f commit 24e884b
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/styles/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

import globals from "./globals";
import normalize from "./normalize";
import { themedMode, themedModeVariant } from "./utils";
import typography from "./typography";
import { MODE_BRIGHT_SNOW_FLURRY, MODE_DARK_NIGHT_FROST, THEME_KEY_MODE } from "./constants";

const theme = {
const theme = { typography };

export {
globals,
normalize,
themedMode,
themedModeVariant,
typography,
MODE_BRIGHT_SNOW_FLURRY,
MODE_DARK_NIGHT_FROST,
THEME_KEY_MODE
};

export { globals, normalize, typography };

export default theme;
20 changes: 20 additions & 0 deletions src/styles/theme/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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
*/

/**
* @file Provides theme utilities.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.2.0
*/

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

export { themedMode, themedModeVariant };
31 changes: 31 additions & 0 deletions src/styles/theme/utils/themedMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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
*/

/**
* @file Provides a shorthand function to define styles based on the global theme mode(s).
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.2.0
*/

import styledTheming from "styled-theming";

import { THEME_KEY_MODE } from "../constants";

/**
* Shorthand function to define styles based on the global theme mode(s).
*
* @method themedMode
* @param {object} modeStyles The global theme mode style(s).
* @return {function} The styles as interpolated function for usage in "styled-components" scope.
* @see https://github.com/styled-components/styled-theming#themename-values
*/
const themedMode = modeStyles => styledTheming(THEME_KEY_MODE, modeStyles);

export default themedMode;
33 changes: 33 additions & 0 deletions src/styles/theme/utils/themedModeVariant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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
*/

/**
* @file Provides a shorthand function to define variant styles based on the global theme mode(s).
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.2.0
*/

import styledTheming from "styled-theming";

import { THEME_KEY_MODE } from "../constants";

/**
* Shorthand function to define variant styles based on the global theme mode(s).
*
* @method themedModeVariant
* @param {object} modeStyles The global theme mode style(s) for each variant.
* @param {string} variantPropName The name of the prop which allows to define variants. Defaults to `variant`.
* @return {function} The styles as interpolated function for usage in styled-components scope.
* @see https://github.com/styled-components/styled-theming#themevariantsname-prop-themes
*/
const themedModeVariant = (modeStyles, variantPropName = "variant") =>
styledTheming.variants(THEME_KEY_MODE, variantPropName, modeStyles);

export default themedModeVariant;

0 comments on commit 24e884b

Please sign in to comment.