Skip to content

Commit

Permalink
fix: data theme id attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-tailor committed Jan 11, 2024
1 parent 95b14da commit 7ccbf8f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/styled/react/src/StyledProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export const StyledProvider: React.FC<{

const { themes } = useTheme();
const styledContext = useStyled();
const isParentProviderExist = styledContext?.config ? true : false;
const isParentProviderExist =
Object.keys(styledContext?.config).length > 0 ? true : false;

const themeContextValue = React.useMemo(() => {
if (colorMode) {
Expand Down Expand Up @@ -139,7 +140,9 @@ export const StyledProvider: React.FC<{

if (currentColorMode) {
if (!isParentProviderExist) {
document.body.setAttribute('data-theme-id', currentColorMode);
documentElement
.querySelector('body')
?.setAttribute('data-theme-id', currentColorMode);
documentElement.classList.add(`gs-${currentColorMode}`);
}
} else {
Expand All @@ -158,14 +161,18 @@ export const StyledProvider: React.FC<{
if (currentColor) {
if (currentColor === 'dark') {
if (!isParentProviderExist) {
document.body.setAttribute('data-theme-id', 'dark');
documentElement
.querySelector('body')
?.setAttribute('data-theme-id', 'dark');
documentElement.classList.remove(`gs-light`);
}
documentElement.classList.remove(`gs-light`);
} else {
if (!isParentProviderExist) {
document.body.setAttribute('data-theme-id', 'light');
documentElement
.querySelector('body')
?.setAttribute('data-theme-id', 'light');
documentElement.classList.remove(`gs-dark`);
}
documentElement.classList.remove(`gs-dark`);
}
if (!isParentProviderExist) {
documentElement.classList.add(`gs-${currentColor}`);
Expand Down

0 comments on commit 7ccbf8f

Please sign in to comment.