From 3ea2d2fe9d1e2d9cfd008825292133bcdd850f83 Mon Sep 17 00:00:00 2001 From: econdepe Date: Fri, 24 Jan 2020 17:38:43 +0100 Subject: [PATCH 1/3] create getDarkOrLight helper --- lib/constants.ts | 2 ++ lib/themes/helpers.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/constants.ts b/lib/constants.ts index 20d71bca..bcc9519f 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -317,6 +317,8 @@ export const LABEL_COLORS = [ ]; export const REGEX_IMAGE_EXTENSION = /\.(gif|jpe?g|tiff|png)$/i; +export const DARK_MODE_CLASS = 'isDarkMode'; + export enum LINK_WARNING { KEY = 'link_warning', VALUE = 'dontAsk' diff --git a/lib/themes/helpers.js b/lib/themes/helpers.js index c8bdbbae..387bb1cb 100644 --- a/lib/themes/helpers.js +++ b/lib/themes/helpers.js @@ -84,3 +84,14 @@ export const getTheme = (themeIdentifier) => { * @returns {String} */ export const toStyle = (themes = []) => themes.join('\n'); + +/** + * Given two arguments, one meant to be used in dark mode and the other one in the other cases, + * pick the appropiate one depending on whether the class 'isDarkMode' is in the body or not + * @param dark + * @param light + * @return {*} + */ +export const getLightOrDark = ({ dark, light }) => { + return document.body.classList.contains('isDarkMode') ? dark : light; +}; From 249b2b7b36b8d55b7eecada408974cbabf1493d7 Mon Sep 17 00:00:00 2001 From: econdepe Date: Fri, 24 Jan 2020 18:07:28 +0100 Subject: [PATCH 2/3] use the class just moved --- lib/themes/helpers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/themes/helpers.js b/lib/themes/helpers.js index 387bb1cb..4a599291 100644 --- a/lib/themes/helpers.js +++ b/lib/themes/helpers.js @@ -1,4 +1,5 @@ import { PROTON_THEMES, CUSTOM_THEME, DEFAULT_THEME } from './themes'; +import { DARK_MODE_CLASS } from '../constants'; const { protonThemeIdentifiers, protonThemes } = Object.values(PROTON_THEMES).reduce( (acc, { identifier, theme }) => { @@ -93,5 +94,5 @@ export const toStyle = (themes = []) => themes.join('\n'); * @return {*} */ export const getLightOrDark = ({ dark, light }) => { - return document.body.classList.contains('isDarkMode') ? dark : light; + return document.body.classList.contains(DARK_MODE_CLASS) ? dark : light; }; From 224c723ced63060b54674820a2eecff9607e7a42 Mon Sep 17 00:00:00 2001 From: econdepe Date: Fri, 24 Jan 2020 18:17:50 +0100 Subject: [PATCH 3/3] use two arguments instead of an object --- lib/themes/helpers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/themes/helpers.js b/lib/themes/helpers.js index 4a599291..781215c6 100644 --- a/lib/themes/helpers.js +++ b/lib/themes/helpers.js @@ -87,12 +87,12 @@ export const getTheme = (themeIdentifier) => { export const toStyle = (themes = []) => themes.join('\n'); /** - * Given two arguments, one meant to be used in dark mode and the other one in the other cases, + * Given two arguments, the second meant to be used in dark mode and the first in the other cases, * pick the appropiate one depending on whether the class 'isDarkMode' is in the body or not - * @param dark - * @param light + * @param {*} light + * @param {*} dark * @return {*} */ -export const getLightOrDark = ({ dark, light }) => { +export const getLightOrDark = (light, dark) => { return document.body.classList.contains(DARK_MODE_CLASS) ? dark : light; };