Skip to content

Commit

Permalink
refactor: set meta theme
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Jan 27, 2025
1 parent 5fe144e commit 4ac0d39
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions js/common/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ export const theme = (() => {
*/
const setDark = () => theme.set('active', 'dark');

/**
* @param {string[]} listTheme
* @returns {void}
*/
const setMetaTheme = (listTheme) => {
const now = metaTheme.getAttribute('content');
metaTheme.setAttribute('content', listTheme.some((i) => i === now) ? themeColors[now] : now);
};

/**
* @returns {void}
*/
const onLight = () => {
setLight();
document.documentElement.setAttribute('data-bs-theme', 'light');

const now = metaTheme.getAttribute('content');
metaTheme.setAttribute('content', themeDark.some((i) => i === now) ? themeColors[now] : now);
setMetaTheme(themeDark);
};

/**
Expand All @@ -50,9 +57,7 @@ export const theme = (() => {
const onDark = () => {
setDark();
document.documentElement.setAttribute('data-bs-theme', 'dark');

const now = metaTheme.getAttribute('content');
metaTheme.setAttribute('content', themeLight.some((i) => i === now) ? themeColors[now] : now);
setMetaTheme(themeLight);
};

/**
Expand Down

0 comments on commit 4ac0d39

Please sign in to comment.