Skip to content

Commit

Permalink
Fix(design-system): issue with theme provider (#5010)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainseb authored Nov 27, 2023
1 parent e8c64eb commit 88a17d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-panthers-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/design-system': patch
---

fix: theme provider override is not working as expected
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import './ThemeProvider.scss';

export type ThemeProviderProps = PropsWithChildren<{
theme?: string;
tokensOverride?: React.CSSProperties;
tokensOverride?: Record<string, string | number>;
}>;

export const ThemeProvider = ({
Expand All @@ -33,10 +33,18 @@ export const ThemeProvider = ({
setSelectedTheme(theme);
}, [theme]);

useEffect(() => {
if (tokensOverride) {
Object.keys(tokensOverride).forEach(key => {
document.body.style.setProperty(key, tokensOverride[key].toString());
});
}
}, [tokensOverride]);

const switchTheme = (newTheme: string) => setSelectedTheme(newTheme);
return (
<ThemeContext.Provider value={context.theme ? context : { switchTheme, theme: selectedTheme }}>
{tokensOverride ? <div style={tokensOverride}>{children}</div> : children}
{children}
</ThemeContext.Provider>
);
};

0 comments on commit 88a17d7

Please sign in to comment.