Files
cv/src/components/layout/ThemePaletteMenu.tsx
T
dong.nguyen e6b4d83084 refactor(i18n): split content into structure JSON and per-language dictionaries
Phase 1 of spec-v4-live-edit: data/i18n foundation, no visible feature.

- src/data/{profile,skills,experience,projects}.json: language-neutral
  structure documents with thin typed loaders; all prose moved to
  src/i18n/locales/{vi,en}/content.json; chrome strings to ui.json
- src/i18n/: dict-types, cross-document validator (runs at module load and
  via pnpm validate:content), loader joining structure+text once (UI/CONTENT),
  I18nProvider/useI18n mounted in App under LanguageProvider
- all 22 consumers read joined records via useI18n(); field.ts and
  strings.ts deleted; *En field pairs removed from the domain types
- hero tagline renders as plain-text segments (D9); philosophy quotes as
  paragraph arrays; footer display name now localizes per language (D6)
- resume generator consumes UI/CONTENT; generated resume HTML verified
  byte-identical (EN+VI) before/after the migration
- AGENTS.md and v3/v3-i18n + v4 specs updated; deploy.yml concurrency group
2026-10-22 07:29:06 +07:00

74 lines
2.9 KiB
TypeScript

import { motion } from 'motion/react'
import { useCallback, useRef, useState } from 'react'
import { useTheme } from '@/hooks/useTheme'
import { useLanguage } from '@/hooks/useLanguage'
import { useClickOutside } from '@/hooks/useClickOutside'
import { paletteIds, paletteMeta } from '@/data/palettes'
import { useI18n } from '@/i18n/provider'
export function ThemePaletteMenu() {
const { palette, setPalette } = useTheme()
const { lang } = useLanguage()
const { ui: s } = useI18n()
const [open, setOpen] = useState(false)
const containerRef = useRef<HTMLDivElement>(null)
const triggerRef = useRef<HTMLButtonElement>(null)
const close = useCallback(() => setOpen(false), [])
useClickOutside(containerRef, close)
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
// Only while the submenu is open: React's synthetic stopPropagation() stops the native
// event too, so an unconditional call would also swallow a host's own Escape handling.
if (event.key !== 'Escape' || !open) return
event.stopPropagation()
close()
triggerRef.current?.focus()
}
return (
<div ref={containerRef} className="nav-palette" onKeyDown={handleKeyDown}>
<button
ref={triggerRef}
type="button"
className={`nav-control nav-palette-trigger ${open ? 'open' : ''}`}
aria-expanded={open}
aria-controls="palette-menu"
aria-label={`${s.nav.palette}: ${paletteMeta[palette].label[lang]}`}
title={s.nav.paletteAria}
onClick={() => setOpen((prev) => !prev)}
>
{/* Rotation tracks the submenu: 90° while it is open, back to 0° on selection, Escape or
a pointer-down outside. Reduced motion is handled globally by
`motion.config.reducedMotion = 'user'` (src/main.tsx:7-9) — the angle changes without
animating. No CSS transition on `.nav-palette-swatch`: motion owns the transform. */}
<motion.span
className="nav-palette-swatch"
aria-hidden="true"
animate={{ rotate: open ? 90 : 0 }}
transition={{ duration: 0.15, ease: 'easeOut' }}
/>
</button>
<div id="palette-menu" className={`nav-palette-panel ${open ? 'open' : ''}`}>
{paletteIds.map((id) => (
<button
key={id}
type="button"
className={`nav-palette-option ${id === palette ? 'active' : ''}`}
aria-current={id === palette ? 'true' : undefined}
onClick={() => {
setPalette(id)
setOpen(false)
}}
>
<span className="nav-palette-preview" data-preview={id} aria-hidden="true" />
<span className="nav-palette-name">{paletteMeta[id].label[lang]}</span>
<span className="nav-palette-hint">{paletteMeta[id].hint[lang]}</span>
</button>
))}
</div>
</div>
)
}