From c62a0afdf6844aa02f5b8f6ca40a2e89f80c2545 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Wed, 14 Aug 2024 16:09:07 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7(frontend)=20theme=20from=20env=20v?= =?UTF-8?q?ar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/frontend/apps/impress/.env | 1 + src/frontend/apps/impress/.env.test | 1 + .../src/cunningham/__tests__/useCunninghamTheme.spec.tsx | 9 +++++++++ .../apps/impress/src/cunningham/useCunninghamTheme.tsx | 2 +- src/frontend/apps/impress/src/custom-next.d.ts | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/frontend/apps/impress/.env create mode 100644 src/frontend/apps/impress/src/cunningham/__tests__/useCunninghamTheme.spec.tsx diff --git a/src/frontend/apps/impress/.env b/src/frontend/apps/impress/.env new file mode 100644 index 00000000..6c2936d2 --- /dev/null +++ b/src/frontend/apps/impress/.env @@ -0,0 +1 @@ +NEXT_PUBLIC_THEME=dsfr diff --git a/src/frontend/apps/impress/.env.test b/src/frontend/apps/impress/.env.test index 9a4d5142..6d5094f8 100644 --- a/src/frontend/apps/impress/.env.test +++ b/src/frontend/apps/impress/.env.test @@ -1 +1,2 @@ NEXT_PUBLIC_API_ORIGIN=http://test.jest +NEXT_PUBLIC_THEME=test-theme diff --git a/src/frontend/apps/impress/src/cunningham/__tests__/useCunninghamTheme.spec.tsx b/src/frontend/apps/impress/src/cunningham/__tests__/useCunninghamTheme.spec.tsx new file mode 100644 index 00000000..1d8fc26e --- /dev/null +++ b/src/frontend/apps/impress/src/cunningham/__tests__/useCunninghamTheme.spec.tsx @@ -0,0 +1,9 @@ +import useCunninghamTheme from '../useCunninghamTheme'; + +describe('', () => { + it('has the theme from NEXT_PUBLIC_THEME', () => { + const { theme } = useCunninghamTheme.getState(); + + expect(theme).toBe('test-theme'); + }); +}); diff --git a/src/frontend/apps/impress/src/cunningham/useCunninghamTheme.tsx b/src/frontend/apps/impress/src/cunningham/useCunninghamTheme.tsx index e858286f..26feaf8c 100644 --- a/src/frontend/apps/impress/src/cunningham/useCunninghamTheme.tsx +++ b/src/frontend/apps/impress/src/cunningham/useCunninghamTheme.tsx @@ -20,7 +20,7 @@ const useCunninghamTheme = create((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) => { diff --git a/src/frontend/apps/impress/src/custom-next.d.ts b/src/frontend/apps/impress/src/custom-next.d.ts index 4f84b79c..b8bbf9bf 100644 --- a/src/frontend/apps/impress/src/custom-next.d.ts +++ b/src/frontend/apps/impress/src/custom-next.d.ts @@ -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; } }