Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Add meta tag for theme color
Browse files Browse the repository at this point in the history
  • Loading branch information
hirbod committed Nov 23, 2023
1 parent 23a3b8e commit bb01675
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/design-system/color-scheme/provider.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,27 @@ export function ColorSchemeProvider({
} else {
document.documentElement.classList.remove("dark");
}

const themeColor = isDark ? "#000000" : "#ffffff";
// Change the content attribute
let metaThemeColor = document.querySelector("meta[name='theme-color']");
if (metaThemeColor) {
metaThemeColor.setAttribute("content", themeColor);
} else {
// If the meta tag does not exist, you can create it and append it to the <head>
metaThemeColor = document.createElement("meta");
metaThemeColor.setAttribute("name", "theme-color");
metaThemeColor.setAttribute("content", themeColor);
document.head.appendChild(metaThemeColor);
}
}, []);

useEffect(() => {
const themeChangeListener = () => {
const theme = Appearance.getColorScheme();
changeTheme(theme && !getDisabledSystemTheme() ? theme : colorScheme);
};

themeChangeListener();
const appearanceListener =
Appearance.addChangeListener(themeChangeListener);
Expand Down

0 comments on commit bb01675

Please sign in to comment.