- add Timestamp component with moment relative time and ISO tooltip - add Timestamp stories (JustNow, MinutesAgo, HoursAgo, DaysAgo, MonthsAgo) - add ESLint 10 with typescript-eslint, react-hooks, react-refresh, prettier - add Prettier config with singleQuote, semi, trailingComma all, printWidth 100 - add lint, lint:fix, format, test:storybook scripts to package.json - fix react-hooks/set-state-in-effect in all page components - auto-fix 113 Prettier formatting issues across src and .storybook
27 lines
726 B
TypeScript
27 lines
726 B
TypeScript
import { useState, useEffect } from 'react';
|
|
|
|
type Theme = 'light' | 'dark';
|
|
|
|
const STORAGE_KEY = 'qa-bot-theme';
|
|
|
|
function getInitialTheme(): Theme {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (stored === 'light' || stored === 'dark') return stored;
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
}
|
|
|
|
export function useTheme() {
|
|
const [theme, setTheme] = useState<Theme>(getInitialTheme);
|
|
|
|
useEffect(() => {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
localStorage.setItem(STORAGE_KEY, theme);
|
|
}, [theme]);
|
|
|
|
function toggleTheme() {
|
|
setTheme((t) => (t === 'light' ? 'dark' : 'light'));
|
|
}
|
|
|
|
return { theme, toggleTheme } as const;
|
|
}
|