mirror of
https://github.com/arthur-pbty/blocnote.git
synced 2026-06-03 15:07:19 +02:00
63e6c64077
- Created a new SVG for the Open Graph image (og-image.svg) with a gradient background and text elements. - Added Vercel logo SVG (vercel.svg) for deployment branding. - Introduced a window icon SVG (window.svg) for UI representation. - Initialized TypeScript configuration file (tsconfig.json) with strict settings and module resolution for a React project.
29 lines
832 B
TypeScript
29 lines
832 B
TypeScript
"use client";
|
|
|
|
import { useState, useEffect } from "react";
|
|
import { Theme } from "../types";
|
|
|
|
export function useTheme() {
|
|
const [theme, setTheme] = useState<Theme>("light");
|
|
|
|
useEffect(() => {
|
|
const saved = localStorage.getItem("blocnote-theme") as Theme | null;
|
|
if (saved) {
|
|
// Reading persisted theme must happen on client after mount.
|
|
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
setTheme(saved);
|
|
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
setTheme("dark");
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
document.documentElement.setAttribute("data-theme", theme);
|
|
localStorage.setItem("blocnote-theme", theme);
|
|
}, [theme]);
|
|
|
|
const toggleTheme = () => setTheme((t) => (t === "light" ? "dark" : "light"));
|
|
|
|
return { theme, toggleTheme };
|
|
}
|