Add 3-mode theme system (light / dark / auto by device clock) and tokenize colors

- theme.css: semantic tokens (bg, surface, ink, border, brand, tints, status, glass)
- ThemeSwitch.tsx: radiogroup with light/dark/auto, persisted in localStorage
- auto mode follows device time (06:00-18:00 light), rechecks every minute and on visibilitychange
- inline pre-paint script in layout.tsx prevents flash of wrong theme
- remapped ~250 hardcoded hex declarations across styles to tokens
- fixed --c-ink-2 contrast 4.25 -> 5.36 (WCAG AA) in light mode
- 0 contrast failures below 4.5:1 across 8 pages in both themes
- DESIGN.md: documented theme system
This commit is contained in:
Bkk1234 committed 2026-10-23 23:01:06 +07:00
1 parent 4c444b3d8d
commit 7ac7bf5878
18 files changed
+758 -361

No files matched your search

+7
View File
@@ -6,6 +6,7 @@ import SiteFooter from "@/components/SiteFooter";
import SiteHeader from "@/components/SiteHeader";
// ลำดับ CSS ต้องตรงกับ mock: shared → map → shell → responsive
import "@/styles/theme.css";
import "@/styles/_shared.css";
import "@/styles/map.css";
import "@/styles/shell.css";
@@ -61,6 +62,12 @@ export default function RootLayout({ children }: { children: React.ReactNode })
{/* theme-color / apple-touch-icon / apple-mobile-web-app-* / mobile-web-app-capable
ถูก emit อัตโนมัติจาก metadata.appleWebApp + metadata.icons + viewport.themeColor
— อย่าใส่ซ้ำที่นี่ (จะได้ meta ซ้ำ 2 ชุด) */}
{/* ตั้งธีมก่อนวาดหน้าจอ (กันจอขาววูบตอนเปิดแอปในโหมดมืด) */}
<script
dangerouslySetInnerHTML={{
__html: `(function(){try{var m=localStorage.getItem('at_theme')||'auto';var h=new Date().getHours();var r=m==='auto'?(h>=6&&h<18?'light':'dark'):m;document.documentElement.dataset.theme=r;document.documentElement.dataset.themeMode=m;document.documentElement.style.colorScheme=r;}catch(e){}})();`,
}}
/>
<script src="/vendor/leaflet/leaflet.js" defer />
</head>
<body className="main-theme-page">