2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
|
|
|
|
|
interface IThemeContextProps {
|
|
|
|
theme: string;
|
2021-10-20 16:42:44 +00:00
|
|
|
themePreferences?: {
|
2021-09-13 20:41:05 +00:00
|
|
|
currentTheme: 'automatic' | 'light';
|
|
|
|
darkLevel: string;
|
|
|
|
};
|
2021-10-20 16:42:44 +00:00
|
|
|
setTheme?: (newTheme?: {}) => void;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 16:42:44 +00:00
|
|
|
export const ThemeContext = React.createContext<IThemeContextProps>({ theme: 'light' });
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
export function withTheme(Component: any): any {
|
2021-09-13 20:41:05 +00:00
|
|
|
const ThemedComponent = (props: any) => (
|
|
|
|
<ThemeContext.Consumer>{contexts => <Component {...props} {...contexts} />}</ThemeContext.Consumer>
|
|
|
|
);
|
|
|
|
hoistNonReactStatics(ThemedComponent, Component);
|
|
|
|
return ThemedComponent;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useTheme = () => React.useContext(ThemeContext);
|