mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-14 08:50:31 +00:00
linting and cleanup
This commit is contained in:
parent
7f041e8303
commit
f74e8b9d32
51 changed files with 464 additions and 349 deletions
|
@ -1,42 +0,0 @@
|
|||
import { createContext, useState, useEffect } from "react";
|
||||
|
||||
let lastColor = false;
|
||||
|
||||
const getInitialColor = () => {
|
||||
if (typeof window !== "undefined" && window.localStorage) {
|
||||
const storedPrefs = window.localStorage.getItem("theme-color");
|
||||
if (typeof storedPrefs === "string") {
|
||||
lastColor = storedPrefs;
|
||||
return storedPrefs;
|
||||
}
|
||||
}
|
||||
|
||||
return "slate"; // slate as the default color;
|
||||
};
|
||||
|
||||
export const ColorContext = createContext();
|
||||
|
||||
export const ColorProvider = ({ initialTheme, children }) => {
|
||||
const [color, setColor] = useState(getInitialColor);
|
||||
|
||||
const rawSetColor = (rawColor) => {
|
||||
const root = window.document.documentElement;
|
||||
|
||||
root.classList.remove(`theme-${lastColor}`);
|
||||
root.classList.add(`theme-${rawColor}`);
|
||||
|
||||
localStorage.setItem("theme-color", rawColor);
|
||||
|
||||
lastColor = rawColor;
|
||||
};
|
||||
|
||||
if (initialTheme) {
|
||||
rawSetColor(initialTheme);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
rawSetColor(color);
|
||||
}, [color]);
|
||||
|
||||
return <ColorContext.Provider value={{ color, setColor }}>{children}</ColorContext.Provider>;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue