mirror of
https://github.com/karpathy/nanochat.git
synced 2026-05-10 18:00:17 +00:00
LandingNav was max-w-3xl which forced "How it works" and "Try samosaChaat" to wrap on two lines. Bumps the pill to 1100px, tightens the link padding, demotes the @ handle to lg+, and adds whitespace-nowrap to every chip so nothing wraps again. Default theme is now dark — the no-flash init script adds .dark unless the user has explicitly stored 'light', and the useTheme hook seeds from the same logic. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
39 lines
937 B
TypeScript
39 lines
937 B
TypeScript
'use client';
|
|
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
|
|
type Theme = 'light' | 'dark';
|
|
|
|
function readTheme(): Theme {
|
|
if (typeof window === 'undefined') return 'dark';
|
|
const stored = localStorage.getItem('theme');
|
|
if (stored === 'dark' || stored === 'light') return stored;
|
|
return 'dark';
|
|
}
|
|
|
|
export function useTheme() {
|
|
const [theme, setThemeState] = useState<Theme>('dark');
|
|
|
|
useEffect(() => {
|
|
setThemeState(readTheme());
|
|
}, []);
|
|
|
|
const setTheme = useCallback((next: Theme) => {
|
|
setThemeState(next);
|
|
try {
|
|
localStorage.setItem('theme', next);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
const root = document.documentElement;
|
|
if (next === 'dark') root.classList.add('dark');
|
|
else root.classList.remove('dark');
|
|
}, []);
|
|
|
|
const toggle = useCallback(() => {
|
|
setTheme(theme === 'dark' ? 'light' : 'dark');
|
|
}, [theme, setTheme]);
|
|
|
|
return { theme, setTheme, toggle };
|
|
}
|