feat(theme): red/blue palette switch with a nav + mobile-sheet color menu

Second axis on <html>: data-palette (Portfolio type Palette = 'red' | 'blue',
localStorage key portfolio-palette, default red so existing visitors see no
change). Both attributes are written before paint by the index.html init
script and re-written during render in useTheme.

- src/types/index.ts, src/data/palettes.ts: Palette + paletteIds/paletteMeta
  (Record<Language, string>, indexed inline - no lookup helper)
- src/hooks/useTheme.tsx: palette state, data-palette write during render,
  persistence, setPalette; no cyclePalette
- src/components/layout/ThemePaletteMenu.tsx: disclosure semantics
  (aria-expanded/aria-controls, aria-current), variant nav|sheet, panel ids
  derived from variant, Escape closes and refocuses the trigger
- src/components/layout/Navigation.tsx: nav instance in .nav-actions, sheet
  instance after the mobile link list, remounted closed via key
- src/index.css: blue dark/light blocks (0,3,0 selectors) + preview tokens;
  red --accent-soft/--accent-glow re-derived from the accent in force
- src/App.css: .nav-palette* block (token-only), nav hidden at 1024px,
  sheet options inline
- specs: palette-switch spec v0.3.0 with the implementation record; corrected
  the false AA claim in spec-v3-theme-colors.md (3.90:1, not ~4.8), the
  composite values in spec-v3-theme-palette-gasatrya.md, the Footer consumer
  claim in spec-v3-theme-switch.md; AGENTS.md Theming section documents the
  palette axis

Verified: tsc exit 0; vite build green (CSS 31.80 kB); oxlint unchanged at
11 errors / 9 warnings; hex gate over src/App.css 0 matches; inline type
styles 0; contrast minima 4.96 / 4.63 / 4.81 / 4.64 with zero AA failures.
This commit is contained in:
dong.nguyen committed 2026-10-17 00:32:49 +07:00
1 parent 5b4b301ef1
commit f2c920d6ad
14 files changed
+1033 -34

No files matched your search

+11 -8
View File
@@ -49,11 +49,14 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
## Theming
- `src/hooks/useTheme.tsx` — `ThemeProvider` + `useTheme` hook
- Simple toggle: `'dark'` ↔ `'light'` (no `system` variant)
- `resolvedTheme` — runtime resolved value (always `'dark'` or `'light'`)
- `data-theme` attribute set on `<html>` during render (before paint)
- Stored in `localStorage` key `portfolio-theme`
- Two independent axes on `<html>`: lightness (`Theme`) and color (`Palette`), both written during render before paint
- `src/hooks/useTheme.tsx` — `ThemeProvider` + `useTheme` hook, carries both axes
- Simple toggle: `'dark'` ↔ `'light'` (no `system` variant); `resolvedTheme` — runtime resolved value (always `'dark'` or `'light'`)
- `data-theme` attribute + `localStorage` key `portfolio-theme`
- `type Palette = 'red' | 'blue'` (`src/types/index.ts`), labels/hints in `src/data/palettes.ts` (`paletteIds`, `paletteMeta`); default `red`
- `data-palette` attribute + `localStorage` key `portfolio-palette`; `index.html`'s init script writes both attributes before paint
- Palette overrides in `src/index.css` are `:root[data-theme='dark'][data-palette='blue']` / `:root[data-theme='light'][data-palette='blue']` (specificity 0,3,0 — they beat the base blocks regardless of order); no blue variant exists in the `prefers-color-scheme` bridge, because the init script always writes `data-palette`
- Picker: `src/components/layout/ThemePaletteMenu.tsx`, mounted twice in `Navigation.tsx` — `variant="nav"` in `.nav-actions` (>1024px) and `variant="sheet"` inside `.mobile-menu` (≤1024px, remounted closed via `key={location.pathname}`)
## Data Layer
@@ -68,11 +71,11 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
```
src/
components/
layout/ — Layout.tsx, Navigation.tsx, Footer.tsx
layout/ — Layout.tsx, Navigation.tsx, Footer.tsx, ThemePaletteMenu.tsx
sections/ — Hero, About, Expertise, Experience, Projects, Contact, HeroParticles, DownloadResume
ui/ — Badge, Button, SectionHeading, SocialLinks, Tag, Typewriter, AnimatedSection, InView, RollingTextLink, BackToTop
index.ts — barrel export
data/ — profile, skills, experience, projects, resume (TS modules)
data/ — profile, skills, experience, projects, resume, palettes (TS modules)
hooks/ — useTheme.tsx, useClickOutside.ts
pages/ — HomePage, AboutPage, ExperiencePage, ProjectsListPage, ProjectDetailPage, PhilosophyPage, ContactPage, index.ts
types/ — shared TypeScript interfaces
@@ -148,7 +151,7 @@ All specification documents are in `docs/design/`:
| `spec-v2.md` | v2 index — overview, implementation order, feature list |
| `specs/ui/spec-ui-*.md` | UI specs per section (hero, about, expertise, etc.) |
| `specs/v2/spec-v2-*.md` | v2 feature specs (resume, seo, blog, analytics, testing, cicd) |
| `specs/v3/spec-v3-*.md` | v3 feature specs (theme colors, theme switch, UI enhancements) |
| `specs/v3/spec-v3-*.md` | v3 feature specs (theme colors, theme switch, theme palette switch, UI enhancements) |
Read `spec.md` first for product context. Read `spec-v2.md` for current feature scope.