-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4234 from iotaledger/tooling-epic/explorer-darkmo…
…de-support feat(explorer): add darkmode support
- Loading branch information
Showing
40 changed files
with
289 additions
and
138 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
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,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
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
Oops, something went wrong.