-
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.
feat(wallet): add darkmode/lightmode theme selection logic (#4053)
* feat: move themecontext to core * feat: fix styles after using shared context * feat: add theme to wallet * feat: clenaup * feat: add device preferences theme * fix cleanup * feat: add darmode video welcome page
- Loading branch information
1 parent
75e54d0
commit a6277f7
Showing
19 changed files
with
145 additions
and
76 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './KioskClientProvider'; | ||
export * from './QR'; | ||
|
||
export * from './providers'; |
File renamed without changes.
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,44 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { PropsWithChildren, useState, useEffect } from 'react'; | ||
import { Theme } from '../../enums'; | ||
import { ThemeContext } from '../../contexts'; | ||
|
||
interface ThemeProviderProps { | ||
appId: string; | ||
} | ||
|
||
export function ThemeProvider({ children, appId }: PropsWithChildren<ThemeProviderProps>) { | ||
const storageKey = `theme_${appId}`; | ||
const [theme, setTheme] = useState<Theme>(() => { | ||
if (typeof window !== 'undefined') { | ||
const storedTheme = localStorage.getItem(storageKey); | ||
if (storedTheme) { | ||
return storedTheme as Theme; | ||
} else { | ||
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
return prefersDarkScheme ? Theme.Dark : Theme.Light; | ||
} | ||
} | ||
return Theme.Light; | ||
}); | ||
|
||
useEffect(() => { | ||
if (typeof window !== 'undefined') { | ||
localStorage.setItem(storageKey, theme); | ||
} | ||
document.documentElement.classList.toggle(Theme.Dark, theme === Theme.Dark); | ||
}, [theme, storageKey]); | ||
|
||
return ( | ||
<ThemeContext.Provider | ||
value={{ | ||
theme, | ||
setTheme, | ||
}} | ||
> | ||
{children} | ||
</ThemeContext.Provider> | ||
); | ||
} |
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,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './KioskClientProvider'; | ||
export * from './ThemeProvider'; |
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,15 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { createContext } from 'react'; | ||
import { Theme } from '../enums'; | ||
|
||
export interface ThemeContextType { | ||
theme: Theme; | ||
setTheme: (theme: Theme) => void; | ||
} | ||
|
||
export const ThemeContext = createContext<ThemeContextType>({ | ||
theme: Theme.Light, | ||
setTheme: () => {}, | ||
}); |
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,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './ThemeContext'; |
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,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './theme.enums'; |
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,7 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export enum Theme { | ||
Light = 'light', | ||
Dark = 'dark', | ||
} |
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,12 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { useContext } from 'react'; | ||
import { ThemeContext, ThemeContextType } from '../contexts'; | ||
|
||
export const useTheme = (): ThemeContextType => { | ||
const context = useContext(ThemeContext); | ||
if (!context) { | ||
throw new Error('useTheme must be used within a ThemeProvider'); | ||
} | ||
return context; | ||
}; |
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 was deleted.
Oops, something went wrong.
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,4 +2,3 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './PopupContext'; | ||
export * from './ThemeContext'; |
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