diff --git a/src/components/@molecules/Hamburger/MainMenu.tsx b/src/components/@molecules/Hamburger/MainMenu.tsx index 3ada72a5b..e9bd75cd7 100644 --- a/src/components/@molecules/Hamburger/MainMenu.tsx +++ b/src/components/@molecules/Hamburger/MainMenu.tsx @@ -7,7 +7,9 @@ import { LanguageSVG, RightChevronSVG, Spinner, + ThemeToggle, Typography, + useTheme, WalletSVG, } from '@ensdomains/thorin' @@ -213,6 +215,16 @@ const NetworkSectionRow = styled.div( `, ) +const DarkModeItem = styled.div( + ({ theme }) => css` + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + gap: ${theme.space['2']}; + `, +) + const NetworkSection = () => { const { t } = useTranslation('common') const graphOutOfSync = useGraphOutOfSync() @@ -253,20 +265,21 @@ const MainMenu = ({ setCurrentView }: { setCurrentView: (view: 'main' | 'languag const { t, i18n } = useTranslation('common') const language = i18n.resolvedLanguage || 'en' const { userConfig, setCurrency } = useUserConfig() + const { setMode, mode } = useTheme() return ( setCurrentView('language')}>
- + {t('navigation.language')}
{ISO6391.getNativeName(language)} ({language.toLocaleUpperCase()}) - +
@@ -283,6 +296,18 @@ const MainMenu = ({ setCurrentView }: { setCurrentView: (view: 'main' | 'languag /> + + NEW! + { + const newValue = e.target.checked ? 'light' : 'dark' + if (newValue !== mode) { + setMode(newValue) + } + }} + /> +
{disconnectedRoutes.map((route) => ( diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index ffb963d48..f7ed932a8 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import { lightTheme, RainbowKitProvider, Theme } from '@rainbow-me/rainbowkit' import '@rainbow-me/rainbowkit/styles.css' @@ -12,6 +13,7 @@ import { IntercomProvider } from 'react-use-intercom' import { createGlobalStyle, keyframes, ThemeProvider } from 'styled-components' import { + Mode, lightTheme as thorinLightTheme, ThemeProvider as ThorinThemeProvider, } from '@ensdomains/thorin' @@ -143,6 +145,14 @@ type AppPropsWithLayout = AppProps & { setupAnalytics() +declare global { + interface Window { + __theme: Mode + __setPreferredTheme: (theme: Mode) => void + __onThemeChange: (theme: Mode) => void + } +} + function MyApp({ Component, pageProps }: AppPropsWithLayout) { const getLayout = Component.getLayout ?? ((page) => page) @@ -153,7 +163,10 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) { - + window.__setPreferredTheme(mode)} + defaultMode={typeof window !== 'undefined' ? window.__theme : 'light'} + > diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 23e542702..ddad79b2d 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react/no-danger */ import { AppPropsType, AppType } from 'next/dist/shared/lib/utils' import Document, { DocumentContext, Head, Html, Main, NextScript } from 'next/document' import { ServerStyleSheet, StyleSheetManager } from 'styled-components' @@ -80,8 +81,38 @@ export default class MyDocument extends Document { content="worker-src 'self'; script-src 'self' 'sha256-UyYcl+sKCF/ROFZPHBlozJrndwfNiC5KT5ZZfup/pPc=' plausible.io static.cloudflareinsights.com *.ens-app-v3.pages.dev https://app.intercom.io https://widget.intercom.io https://js.intercomcdn.com 'wasm-unsafe-eval';" /> )} - {/* eslint-disable-next-line react/no-danger */}