[#1] Add default theme env variable

This commit is contained in:
Ahmed Al-Taiar
2024-10-24 18:38:07 -04:00
parent 284a4c5520
commit 03717113f4
9 changed files with 34 additions and 2 deletions

View File

@@ -8,7 +8,10 @@ const DARK_THEME = 'dark'
const ThemeToggle = () => {
const [theme, setTheme] = useState(
localStorage.getItem('theme') ?? LIGHT_THEME
localStorage.getItem('theme') ||
([LIGHT_THEME, DARK_THEME].includes(process.env.DEFAULT_THEME)
? process.env.DEFAULT_THEME
: LIGHT_THEME)
)
const handleToggle = (e: React.ChangeEvent<HTMLInputElement>) => {

View File

@@ -8,6 +8,11 @@ import App from 'src/App'
* rather than replacing it.
* https://react.dev/reference/react-dom/client/hydrateRoot
*/
enum Theme {
light = 'light',
dark = 'dark',
}
const redwoodAppElement = document.getElementById('redwood-app')
if (!redwoodAppElement)
@@ -21,6 +26,11 @@ if (!hasFlag(process.env.COUNTRY))
'Invalid COUNTRY environment variable, please select a valid ISO-3166-1 alpha-2 country code\n See https://en.wikipedia.org/wiki/ISO_3166-1#Codes'
)
if (!(process.env.DEFAULT_THEME.toLowerCase() in Theme))
throw new Error(
'Invalid DEFAULT_THEME environment variable, please select either light or dark'
)
if (redwoodAppElement.children?.length > 0)
hydrateRoot(redwoodAppElement, <App />)
else {