[#1] Add default theme env variable
This commit is contained in:
@@ -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>) => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user