Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 12 additions & 0 deletions lib/themes/helpers.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand Down Expand Up @@ -84,3 +85,14 @@ export const getTheme = (themeIdentifier) => {
* @returns {String}
*/
export const toStyle = (themes = []) => themes.join('\n');

/**
* 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 {*} light
* @param {*} dark
* @return {*}
*/
export const getLightOrDark = (light, dark) => {
return document.body.classList.contains(DARK_MODE_CLASS) ? dark : light;
};