-
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.
add TurnkeyThemeProvider to apply theme to all components
- Loading branch information
Showing
7 changed files
with
56 additions
and
34 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
30 changes: 30 additions & 0 deletions
30
packages/sdk-react/src/components/auth/TurnkeyThemeProvider.tsx
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,30 @@ | ||
import React, { createContext, useContext, useEffect } from "react"; | ||
|
||
const ThemeContext = createContext<Record<string, string> | null>(null); | ||
|
||
interface ThemeProviderProps { | ||
children: React.ReactNode; | ||
theme?: Record<string, string>; | ||
} | ||
|
||
export const TurnkeyThemeProvider: React.FC<ThemeProviderProps> = ({ | ||
children, | ||
theme, | ||
}) => { | ||
useEffect(() => { | ||
if (theme) { | ||
const root = document.documentElement.style; | ||
Object.entries(theme).forEach(([key, value]) => { | ||
root.setProperty(key, value); | ||
}); | ||
} | ||
}, [theme]); | ||
|
||
return ( | ||
<ThemeContext.Provider value={theme || null}> | ||
{children} | ||
</ThemeContext.Provider> | ||
); | ||
}; | ||
|
||
export const useTheme = () => useContext(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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as Auth } from "./Auth"; | ||
export { default as OtpVerification } from "./OtpVerification"; | ||
export { TurnkeyThemeProvider } from "./TurnkeyThemeProvider"; |
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