-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement theme mode utility functions
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
1 parent
687d30f
commit 24e884b
Showing
4 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |