feature(public,docs): new public website and docs

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-11-13 21:15:46 +01:00
parent fc2a019e1d
commit a022cb4831
234 changed files with 9341 additions and 6154 deletions

View File

@@ -0,0 +1,37 @@
import { useEffect, useState } from 'react';
export function useIsDarkMode() {
const [isDarkMode, setIsDarkMode] = useState(() => {
if (typeof window === 'undefined') return false;
// Check localStorage first
const savedTheme = window.localStorage.getItem('theme');
if (savedTheme !== null) {
return savedTheme === 'dark';
}
// Fall back to system preference
return window.matchMedia('(prefers-color-scheme: dark)').matches;
});
useEffect(() => {
// Check if user prefers dark mode
const htmlElement = document.documentElement;
setIsDarkMode(htmlElement.classList.contains('dark'));
// Create observer to watch for class changes
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.attributeName === 'class') {
setIsDarkMode(htmlElement.classList.contains('dark'));
}
});
});
// Start observing class changes on html element
observer.observe(htmlElement, { attributes: true });
return () => observer.disconnect();
}, []);
return isDarkMode;
}