fix and format
This commit is contained in:
parent
818f984f7b
commit
f9b77511d2
17 changed files with 206 additions and 202 deletions
|
|
@ -1,45 +1,45 @@
|
|||
"use client";
|
||||
'use client'
|
||||
|
||||
import * as React from "react";
|
||||
import { createContext, useEffect, useState } from "react";
|
||||
import * as React from 'react'
|
||||
import { createContext, useEffect, useState } from 'react'
|
||||
|
||||
export const cachedDarkKey = "chora-web-dark";
|
||||
export const cachedDarkKey = 'chora-web-dark'
|
||||
|
||||
const initDarkTheme = () => {
|
||||
let initDarkTheme = false;
|
||||
let initDarkTheme = false
|
||||
|
||||
if (
|
||||
typeof localStorage !== "undefined" &&
|
||||
typeof localStorage !== 'undefined' &&
|
||||
localStorage.getItem(cachedDarkKey)
|
||||
) {
|
||||
initDarkTheme = localStorage.getItem(cachedDarkKey) === "true";
|
||||
} else if (typeof window !== "undefined") {
|
||||
initDarkTheme = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
initDarkTheme = localStorage.getItem(cachedDarkKey) === 'true'
|
||||
} else if (typeof window !== 'undefined') {
|
||||
initDarkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
}
|
||||
|
||||
return initDarkTheme;
|
||||
};
|
||||
return initDarkTheme
|
||||
}
|
||||
|
||||
const ThemeContext = createContext<any>({});
|
||||
const ThemeContext = createContext<any>({})
|
||||
|
||||
const ThemeContextProvider = (props: any) => {
|
||||
const [darkTheme, setDarkTheme] = useState<boolean>(initDarkTheme());
|
||||
const [darkTheme, setDarkTheme] = useState<boolean>(initDarkTheme())
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
||||
const root = window.document.documentElement;
|
||||
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
|
||||
const root = window.document.documentElement
|
||||
|
||||
if (darkTheme) {
|
||||
root.classList.add("dark-theme");
|
||||
root.style.backgroundColor = "#161616"; // --background-secondary (dark-theme)
|
||||
root.classList.add('dark-theme')
|
||||
root.style.backgroundColor = '#161616' // --background-secondary (dark-theme)
|
||||
} else {
|
||||
root.classList.remove("dark-theme");
|
||||
root.style.backgroundColor = "#FAFAFA"; // --background-secondary (light-theme)
|
||||
root.classList.remove('dark-theme')
|
||||
root.style.backgroundColor = '#FAFAFA' // --background-secondary (light-theme)
|
||||
}
|
||||
|
||||
localStorage.setItem(cachedDarkKey, darkTheme ? "true" : "false");
|
||||
localStorage.setItem(cachedDarkKey, darkTheme ? 'true' : 'false')
|
||||
}
|
||||
}, [darkTheme]);
|
||||
}, [darkTheme])
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider
|
||||
|
|
@ -50,7 +50,7 @@ const ThemeContextProvider = (props: any) => {
|
|||
>
|
||||
{props.children}
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
|
||||
export { ThemeContext, ThemeContextProvider };
|
||||
export { ThemeContext, ThemeContextProvider }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue