🔧(frontend) theme from env var

We want to be able to brand our website (theme and logo)
at build time, we use the dsfr theme but
the german will use their own theme with their
own logo.
We will use a env var to set the theme,
depend the environment we will be able to
use different theme at build time.
This commit is contained in:
Anthony LC
2024-08-14 16:09:07 +02:00
committed by Anthony LC
parent d73e42b20b
commit c62a0afdf6
5 changed files with 13 additions and 1 deletions

View File

@@ -0,0 +1 @@
NEXT_PUBLIC_THEME=dsfr

View File

@@ -1 +1,2 @@
NEXT_PUBLIC_API_ORIGIN=http://test.jest
NEXT_PUBLIC_THEME=test-theme

View File

@@ -0,0 +1,9 @@
import useCunninghamTheme from '../useCunninghamTheme';
describe('<useCunninghamTheme />', () => {
it('has the theme from NEXT_PUBLIC_THEME', () => {
const { theme } = useCunninghamTheme.getState();
expect(theme).toBe('test-theme');
});
});

View File

@@ -20,7 +20,7 @@ const useCunninghamTheme = create<AuthStore>((set, get) => {
merge(tokens.themes['default'], tokens.themes[get().theme]) as Tokens;
return {
theme: 'dsfr',
theme: (process.env.NEXT_PUBLIC_THEME as Theme) || 'dsfr',
colorsTokens: () => currentTheme().theme.colors,
componentTokens: () => currentTheme().components,
setTheme: (theme: Theme) => {

View File

@@ -22,5 +22,6 @@ namespace NodeJS {
NEXT_PUBLIC_API_ORIGIN?: string;
NEXT_PUBLIC_SIGNALING_URL?: string;
NEXT_PUBLIC_SW_DEACTIVATED?: string;
NEXT_PUBLIC_THEME?: string;
}
}