From a5c23a58b17c18c5c8d4a26b923707d2bfaef620 Mon Sep 17 00:00:00 2001 From: Brett Dorrans Date: Sat, 28 May 2022 11:38:14 +0100 Subject: [PATCH] fix: remove theme logic (#1098) --- src/components/theme-provider/index.tsx | 27 ++----------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/components/theme-provider/index.tsx b/src/components/theme-provider/index.tsx index 85c39c4b..64c333fc 100644 --- a/src/components/theme-provider/index.tsx +++ b/src/components/theme-provider/index.tsx @@ -1,11 +1,10 @@ -import React, { Context, PropsWithChildren } from 'react'; +import React, { PropsWithChildren } from 'react'; import { ThemeProvider as StyledThemeProvider, createGlobalStyle } from 'styled-components'; import { mergeThemes, Theme } from '@lapidist/styles'; import { defaultTheme } from './defaultTheme'; -import { darkTheme } from './darkTheme'; const GlobalStyle = createGlobalStyle` html, body, div, span, applet, object, iframe, @@ -51,36 +50,14 @@ export interface ThemeProviderProps extends PropsWithChildren { readonly theme?: Theme; } -export const ThemeContext: Context = - React.createContext(defaultTheme); - -export const useTheme = (): Theme => React.useContext(ThemeContext); - export const ThemeProvider: React.FC = ({ children, theme }) => { - const initialTheme: Theme = useTheme(); - const baseTheme: Theme | undefined = mergeThemes(initialTheme, theme); - - const [themeContext, setThemeContext] = React.useState( - baseTheme - ); - - React.useEffect(() => { - const prefersDarkTheme = - (window.matchMedia && - window.matchMedia('(prefers-color-scheme: dark)').matches) || - localStorage.getItem('isDarkMode') === 'true'; - setThemeContext( - prefersDarkTheme ? mergeThemes(baseTheme, darkTheme) : baseTheme - ); - }, [baseTheme, darkTheme]); - return ( <> - + {children}