Skip to content

Commit 44e7b53

Browse files
committed
use theme toggle from thorin
1 parent 5696528 commit 44e7b53

File tree

5 files changed

+30
-152
lines changed

5 files changed

+30
-152
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@ensdomains/ens-contracts": "1.4.0-beta.2",
5252
"@ensdomains/ens-test-env": "0.6.0",
5353
"@ensdomains/ensjs": "4.0.3-alpha.12",
54-
"@ensdomains/thorin": "1.0.0-beta.24",
54+
"@ensdomains/thorin": "1.0.0-beta.25",
5555
"@metamask/post-message-stream": "^6.1.2",
5656
"@metamask/providers": "^14.0.2",
5757
"@noble/hashes": "^1.3.2",

pnpm-lock.yaml

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/@molecules/Hamburger/LanguageMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const LanguageMenu = ({
164164
<Heading onClick={() => setCurrentView('main')}>
165165
<LeftArrowSVG width={16} height={16} />
166166
<InnerHeading>
167-
<LanguageSVG />
167+
<LanguageSVG height={16} width={16} />
168168
<Typography weight="bold">{t('navigation.language')}</Typography>
169169
</InnerHeading>
170170
</Heading>

src/components/@molecules/Hamburger/MainMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import styled, { css } from 'styled-components'
55
import {
66
CurrencyToggle,
77
LanguageSVG,
8-
MoonSVG,
98
RightChevronSVG,
109
Spinner,
10+
ThemeSVG,
1111
Typography,
1212
WalletSVG,
1313
} from '@ensdomains/thorin'
@@ -273,7 +273,7 @@ const MainMenu = ({ setCurrentView }: { setCurrentView: (view: HamburgerView) =>
273273
</HoverableSettingsItem>
274274
<HoverableSettingsItem onClick={() => setCurrentView('theme')}>
275275
<div>
276-
<MoonSVG height={16} width={16} />
276+
<ThemeSVG height={16} width={16} />
277277
<Typography weight="bold">{t('navigation.theme')}</Typography>
278278
</div>
279279
</HoverableSettingsItem>
Lines changed: 9 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
import { useEffect } from 'react'
21
import { useTranslation } from 'react-i18next'
32
import styled, { css } from 'styled-components'
43

5-
import {
6-
CheckCircleSVG,
7-
LanguageSVG,
8-
LeftArrowSVG,
9-
MoonSVG,
10-
SunSVG,
11-
Typography,
12-
useTheme,
13-
} from '@ensdomains/thorin'
14-
15-
import { useLocalStorage } from '@app/hooks/useLocalStorage'
4+
import { LeftArrowSVG, ThemeSVG, ThemeToggle, Typography } from '@ensdomains/thorin'
165

176
import type { HamburgerView } from './Hamburger'
187

@@ -92,142 +81,31 @@ const InnerHeading = styled.div(
9281
`,
9382
)
9483

95-
const LanguagesContainer = styled.div(
96-
({ theme }) => css`
97-
display: flex;
98-
flex-direction: column-reverse;
99-
align-items: stretch;
100-
justify-content: flex-start;
101-
gap: ${theme.space['2']};
102-
@media (min-width: ${theme.breakpoints.sm}px) {
103-
flex-direction: column;
104-
padding: ${theme.space['2']};
105-
gap: 0;
106-
}
107-
`,
108-
)
109-
110-
const LanguageItem = styled.div(
111-
({ theme }) => css`
112-
display: flex;
113-
flex-direction: row;
114-
align-items: center;
115-
justify-content: space-between;
116-
117-
padding: ${theme.space['4']};
118-
border-radius: ${theme.radii.large};
119-
border: 1px solid ${theme.colors.border};
120-
121-
transition: all 0.1s ease-in-out;
122-
cursor: pointer;
123-
124-
&:hover {
125-
background-color: ${theme.colors.greySurface};
126-
}
127-
128-
& > div {
129-
display: flex;
130-
flex-direction: row;
131-
align-items: center;
132-
justify-content: flex-start;
133-
gap: ${theme.space['2']};
134-
}
135-
@media (min-width: ${theme.breakpoints.sm}px) {
136-
border: none;
137-
}
138-
`,
139-
)
140-
141-
const CheckIcon = styled.svg(
142-
({ theme }) => css`
143-
width: 1rem;
144-
height: 1rem;
145-
146-
display: block;
147-
color: ${theme.colors.green};
148-
`,
149-
)
150-
15184
export const ThemeMenu = ({
15285
setCurrentView,
15386
}: {
15487
setCurrentView: (view: HamburgerView) => void
15588
}) => {
156-
const { setMode, mode } = useTheme()
15789
const { t } = useTranslation()
158-
const [usingSystemTheme, setUsingSystemTheme] = useLocalStorage('usingSystemTheme', false)
159-
160-
useEffect(() => {
161-
if (usingSystemTheme) {
162-
const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')
163-
document.documentElement.setAttribute('data-theme', darkQuery.matches ? 'dark' : 'light')
164-
const listener = (event: MediaQueryListEvent) => {
165-
document.documentElement.setAttribute('data-theme', event.matches ? 'dark' : 'light')
166-
}
167-
darkQuery.addEventListener('change', listener)
168-
return () => darkQuery.removeEventListener('change', listener)
169-
}
170-
}, [usingSystemTheme])
17190

17291
return (
17392
<Container>
17493
<HeadingWrapper>
17594
<Heading onClick={() => setCurrentView('main')}>
17695
<LeftArrowSVG width={16} height={16} />
17796
<InnerHeading>
178-
<LanguageSVG />
97+
<ThemeSVG height={16} width={16} />
17998
<Typography weight="bold">{t('navigation.theme')}</Typography>
18099
</InnerHeading>
181100
</Heading>
182101
</HeadingWrapper>
183-
<LanguagesContainer>
184-
<LanguageItem
185-
onClick={() => {
186-
setMode('light')
187-
188-
setUsingSystemTheme(false)
189-
}}
190-
>
191-
<div>
192-
<CheckIcon
193-
as={CheckCircleSVG}
194-
style={{ display: mode === 'light' && !usingSystemTheme ? 'block' : 'none' }}
195-
/>
196-
<Typography>{t('navigation.mode.light')}</Typography>
197-
</div>
198-
<SunSVG height={16} width={16} />
199-
</LanguageItem>
200-
<LanguageItem
201-
onClick={() => {
202-
setMode('dark')
203-
204-
setUsingSystemTheme(false)
205-
}}
206-
>
207-
<div>
208-
<CheckIcon
209-
as={CheckCircleSVG}
210-
style={{ display: mode === 'dark' && !usingSystemTheme ? 'block' : 'none' }}
211-
/>
212-
<Typography>{t('navigation.mode.dark')}</Typography>
213-
</div>
214-
<MoonSVG height={16} width={16} />
215-
</LanguageItem>
216-
<LanguageItem
217-
onClick={() => {
218-
setUsingSystemTheme(true)
219-
}}
220-
>
221-
<div>
222-
<CheckIcon
223-
style={{ display: usingSystemTheme ? 'block' : 'none' }}
224-
as={CheckCircleSVG}
225-
/>
226-
<Typography>{t('navigation.mode.system')}</Typography>
227-
</div>
228-
<MoonSVG height={16} width={16} />
229-
</LanguageItem>
230-
</LanguagesContainer>
102+
<ThemeToggle
103+
labels={{
104+
light: t('navigation.mode.light'),
105+
dark: t('navigation.mode.dark'),
106+
system: t('navigation.mode.system'),
107+
}}
108+
/>
231109
</Container>
232110
)
233111
}

0 commit comments

Comments
 (0)