aboutsummaryrefslogtreecommitdiffstats
path: root/src/theme.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/theme.js')
-rw-r--r--src/theme.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/theme.js b/src/theme.js
new file mode 100644
index 0000000..7c2b9a9
--- /dev/null
+++ b/src/theme.js
@@ -0,0 +1,40 @@
+import React, { createContext, useEffect, useState } from "react";
+
+export const themes = {
+ dark: '',
+ light: 'white-context',
+};
+
+export const ThemeContext = createContext({
+ theme: themes.dark,
+ changeTheme: () => { },
+});
+
+export default function ThemeContextWrapper(props) {
+ const [theme, setTheme] = useState(themes.dark);
+
+ function changeTheme(theme) {
+ setTheme(theme);
+ }
+
+ useEffect(() => {
+ switch (theme) {
+ case themes.light:
+ document.body.classList.add('white-content');
+ break;
+ case themes.dark:
+ default:
+ document.body.classList.remove('white-content');
+ break;
+ }
+ }, [theme]);
+
+ return (
+ <ThemeContext.Provider value={{
+ theme: theme,
+ changeTheme: changeTheme,
+ }}>
+ {props.children}
+ </ThemeContext.Provider>
+ );
+}