2021-07-15 13:54:47 +00:00
|
|
|
import React from 'react';
|
|
|
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
|
|
|
|
|
interface IThemeContextProps {
|
|
|
|
theme: string,
|
|
|
|
themePreferences: {
|
|
|
|
currentTheme: 'automatic' | 'light',
|
|
|
|
darkLevel: string
|
|
|
|
},
|
|
|
|
setTheme: (newTheme?: {}) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ThemeContext = React.createContext<Partial<IThemeContextProps>>({ theme: 'light' });
|
|
|
|
|
|
|
|
export function withTheme(Component: any) {
|
|
|
|
const ThemedComponent = (props: any) => (
|
|
|
|
<ThemeContext.Consumer>
|
2021-08-20 00:01:17 +00:00
|
|
|
{(contexts) => <Component {...props} {...contexts} />}
|
2021-07-15 13:54:47 +00:00
|
|
|
</ThemeContext.Consumer>
|
|
|
|
);
|
|
|
|
hoistNonReactStatics(ThemedComponent, Component);
|
|
|
|
return ThemedComponent;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useTheme = () => React.useContext(ThemeContext);
|