generated from abelflopes/lerna-monorepo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: share inverted state through theme provider
- Loading branch information
1 parent
d3635af
commit 87cb022
Showing
4 changed files
with
53 additions
and
8 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 |
---|---|---|
|
@@ -89,3 +89,7 @@ | |
text-decoration: underline; | ||
} | ||
} | ||
|
||
.inverted { | ||
@include define-css-var(text, color, #fff); | ||
} |
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,7 +1,39 @@ | ||
import React, { useContext } from "react"; | ||
import React, { useContext, useMemo } from "react"; | ||
import type { Theme } from "./types"; | ||
import { defaultTheme } from "./themes/default"; | ||
|
||
export const ThemeContext = React.createContext<Theme>(defaultTheme); | ||
export interface ThemeContextProps { | ||
inverted: boolean; | ||
theme: Theme; | ||
} | ||
|
||
export const useThemeContext = (): Theme => useContext(ThemeContext); | ||
export const themeContextDefaults: ThemeContextProps = { | ||
inverted: false, | ||
theme: defaultTheme, | ||
}; | ||
|
||
export interface ThemeContextProviderProps { | ||
value?: Partial<ThemeContextProps>; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const ThemeContext = React.createContext<ThemeContextProps>(themeContextDefaults); | ||
|
||
export const useThemeContext = (): ThemeContextProps => useContext(ThemeContext); | ||
|
||
export const ThemeContextProvider = ({ | ||
value, | ||
children, | ||
}: Readonly<ThemeContextProviderProps>): React.ReactElement => { | ||
const parentContext = useThemeContext(); | ||
|
||
const computedValue = useMemo( | ||
() => ({ | ||
...parentContext, | ||
...value, | ||
}), | ||
[value, parentContext], | ||
); | ||
|
||
return <ThemeContext.Provider value={computedValue}>{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