-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect theme mode for embedded applications
- Loading branch information
1 parent
2d2187d
commit bb6124d
Showing
4 changed files
with
20 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const LOCAL_STORAGE_EMBED = "embed" | ||
export const LOCAL_STORAGE_CHAKRA_COLOR_MODE = "chakra-ui-color-mode" |
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,16 @@ | ||
import { useEffect } from "react" | ||
import { LOCAL_STORAGE_CHAKRA_COLOR_MODE } from "../constants" | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function useDetectThemeMode(): string | null { | ||
const params = new URLSearchParams(window.location.search) | ||
const themeMode = params.get("theme") | ||
|
||
useEffect(() => { | ||
// For the ledger live app, we should clear the localStorage and set the theme mode again. | ||
// As a result, we will detect an update when a user's settings change in the live ledger. | ||
if (themeMode) localStorage.removeItem(LOCAL_STORAGE_CHAKRA_COLOR_MODE) | ||
}, [themeMode]) | ||
|
||
return themeMode | ||
} |
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,2 +1,3 @@ | ||
export * from "./dom-hooks" | ||
export * from "./feature-hooks" | ||
export * from "./helpers-hooks" |