-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): add theme switcher (#4041)
* feat(explorer): add theme switcher * fix: add missing style to the icon * fix: lint * refactor: remove theme context from explorer * feat(explorer): add background to search suggestions (#4162) * feat(explorer): add backgrounds to the search suggestions * refactor: add styles to search ui kit * revert changes * fix: remove unnecessary backdrop-blur * fix: remove map * feat(explorer): add darkmode support to epoch page (#4160) * feat: polish darkmode * fix format * feat: update imports * feat(explorer): improve darkmode colors for transaction page (#4158) * feat(explorer): improve darkmode colors for transaction page * feat: add button to the split panes --------- Co-authored-by: evavirseda <[email protected]>
- Loading branch information
1 parent
15f6ea6
commit 3ed9c13
Showing
24 changed files
with
147 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IotaLogoWeb } from '@iota/ui-icons'; | ||
|
||
export function ThemedIotaLogo(): React.JSX.Element { | ||
return <IotaLogoWeb className="text-neutral-10 dark:text-neutral-92" width={137} height={36} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Button, ButtonType } from '@iota/apps-ui-kit'; | ||
import { DarkMode, LightMode } from '@iota/ui-icons'; | ||
import { useEffect, useLayoutEffect } from 'react'; | ||
import { useTheme, Theme } from '@iota/core'; | ||
|
||
export function ThemeSwitcher(): React.JSX.Element { | ||
const { theme, setTheme } = useTheme(); | ||
|
||
const ThemeIcon = theme === Theme.Dark ? DarkMode : LightMode; | ||
|
||
function handleOnClick(): void { | ||
const newTheme = theme === Theme.Light ? Theme.Dark : Theme.Light; | ||
setTheme(newTheme); | ||
saveThemeToLocalStorage(newTheme); | ||
} | ||
|
||
function saveThemeToLocalStorage(newTheme: Theme): void { | ||
localStorage.setItem('theme', newTheme); | ||
} | ||
|
||
function updateDocumentClass(theme: Theme): void { | ||
document.documentElement.classList.toggle('dark', theme === Theme.Dark); | ||
} | ||
|
||
useLayoutEffect(() => { | ||
const storedTheme = localStorage.getItem('theme') as Theme | null; | ||
if (storedTheme) { | ||
setTheme(storedTheme); | ||
updateDocumentClass(storedTheme); | ||
} else { | ||
const prefersDarkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
const preferredTheme = prefersDarkTheme ? Theme.Dark : Theme.Light; | ||
|
||
setTheme(preferredTheme); | ||
updateDocumentClass(preferredTheme); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
updateDocumentClass(theme); | ||
}, [theme]); | ||
|
||
return ( | ||
<Button | ||
type={ButtonType.Ghost} | ||
onClick={handleOnClick} | ||
icon={<ThemeIcon className="h-5 w-5" />} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './Header'; | ||
export * from './ThemeSwitcher'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.