replace language text by icon

This commit is contained in:
dong.nguyen committed 2026-10-17 23:59:58 +07:00
1 parent c95f7b09d1
commit df65f4c774
11 files changed
+126 -65

No files matched your search

+5 -4
View File
@@ -57,9 +57,10 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
- `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`
- Accent has two tiers: `--accent` / `--accent-hover` / `--accent-active` are the bright signal colours (links, underlines, borders, glows) and the fill of the pale accent surfaces (palette-option hover, `.tag-accent`, `.back-to-top`, resume summary bar); `--accent-solid` / `-hover` / `-active` plus `--text-on-accent-solid` are the deeper fill and light text used by `.btn-primary` and `.badge-accent`, which is what lets a dark-mode button carry light text. The solid family is declared in all five blocks of `src/index.css` (dark red, light red, dark blue, light blue, the `prefers-color-scheme` bridge); the two light blocks duplicate the plain accent values verbatim, so light mode does not move. Spec: `docs/design/specs/v3/spec-v3-nav-cta-enhancements.md`
- Picker, two renderings, both present at every width: the bar uses `src/components/layout/ThemePaletteMenu.tsx` — icon-only trigger (`nav-control nav-palette-trigger`, a 20px half-circle swatch: active palette's accent on the left, `--swatch-empty` on the right; no text, no chevron; the name lives in `aria-label`, the hint in `title`) opening the `#palette-menu` panel. The sheet renders its own Theme color row inside `MobileMenu.tsx` from `paletteIds` + `paletteMeta` as `.mobile-menu-swatch-option` buttons — the same segmented shape as the Mode/Language rows, options drawn as colour icons via `.nav-palette-preview`. `ThemePaletteMenu` has no `variant` prop and is never mounted in the sheet
- Picker, two renderings, both present at every width: the bar uses `src/components/layout/ThemePaletteMenu.tsx` — icon-only trigger (`nav-control nav-palette-trigger`, a 20px half-circle swatch: active palette's accent on the left, `--swatch-empty` on the right; no text, no chevron; the name lives in `aria-label`, the hint in `title`) opening the `#palette-menu` panel. The sheet renders its own Theme color row inside `MobileMenu.tsx` from `paletteIds` + `paletteMeta` as `.mobile-menu-icon-option` buttons — the 44px icon-only square the Language row shares; the Mode row keeps `.mobile-menu-segment-option`, because its options are words. `ThemePaletteMenu` has no `variant` prop and is never mounted in the sheet
- Preview chips are theme-aware: `--preview-red-accent` / `--preview-blue-accent` are declared per theme — `:root` dark pair, `:root[data-theme='light']` light pair, repeated in the `prefers-color-scheme` bridge — and mirror that block's `--accent`, so a submenu dot and the bar swatch's accent half are the same colour in the same theme. Each chip names its own palette through `data-preview`, so the two `[data-palette='blue']` blocks declare no preview token; `--swatch-empty` stays one constant. Spec: `docs/design/specs/v3/spec-v3-nav-swatch-and-hamburger.md`
- Bar controls share one chrome: `.nav-control` covers the language toggle, the mode toggle and the palette trigger (44px bordered box, accent border + text on hover/open, one `:focus-visible`). The hamburger leads the bar at every width it appears: `.nav-brand` (`display: flex; gap: 12px`) holds it first and the brand home icon right after, at the bar's left edge — `.nav-logo` is a 24px stroke house in a 44px target, a `<Link to="/">` named by the translated `strings.nav.home` label with the svg `aria-hidden`, so it carries its own `:focus-visible` ring. `.nav-actions` then carries the three appearance controls in that order (language, mode, theme color) at the right end. The sheet's Appearance group follows the same order (Language row, Mode row, Theme color row). `@media (max-width: 420px)` tightens the container padding and the action gap so the row fits a 320px viewport (40 + 12 + 44 + 44×3 + 12×2 = 252px inside 288px)
- Bar controls share one chrome: `.nav-control` covers the language toggle, the mode toggle and the palette trigger (44px bordered box, accent border + icon on hover/open, one `:focus-visible`). The hamburger leads the bar at every width it appears: `.nav-brand` (`display: flex; gap: 12px`) holds it first and the brand home icon right after, at the bar's left edge — `.nav-logo` is a 24px stroke house in a 44px target, a `<Link to="/">` named by the translated `strings.nav.home` label with the svg `aria-hidden`, so it carries its own `:focus-visible` ring. `.nav-actions` then carries the three appearance controls in that order (language, mode, theme color) at the right end. The sheet's Appearance group follows the same order (Language row, Mode row, Theme color row). `@media (max-width: 420px)` tightens the container padding and the action gap so the row fits a 320px viewport (40 + 12 + 44 + 44×3 + 12×2 = 252px inside 288px)
- Language control is icon-only in both renderings — `src/components/ui/LanguageIcon.tsx` draws both languages as line art in the bar's stroke language (`currentColor`, no fills): English a 20px globe (circle r=10 + equator + meridian ellipse, 2px round joins, so it follows the control's hover accent), Tiếng Việt a flag outline (21×17.5 band `rx=2` at 1.5/3.25 — drawn 23×19.5 against the globe's 22×22; width is already at the limit, so the size step came from height, which drags the constitutional 2:3 to 1.2 — with a centred five-point mullet at r=3.6, deliberately smaller than the flag's own 0.6 × height construction, stroked 1.5px round joins so its interior stays open). The bar's `nav-control lang-toggle` shows the language it switches TO (`lang === 'en' ? 'vi' : 'en'`): translated action in `aria-label`, the target's own-language name in `title`. `.lang-toggle` now carries no CSS rules of its own — it marks the button in the DOM and nothing else. The sheet's Language row uses `.mobile-menu-icon-option` squares with `aria-pressed` and the own-language `aria-label` / `title`. Spec: `docs/design/specs/v3/spec-v3-i18n.md`
## Data Layer
@@ -70,7 +71,7 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
- `src/data/resume.ts` — resume availability, supported languages, URL generation
- `src/data/navigation.ts` — `navPaths` (bar + sheet order: Home, About, Experience, Projects, Contact, Philosophy), `footerPaths`
- `src/data/social.ts` — social tiles as `{id, href, external}`; `email` is a `mailto:` link with `external: false`, so it renders no `target`/`rel`
- `src/i18n/strings.ts` — every chrome string as `{en, vi}`; the sheet's group labels, Mode/Language options and the social `aria-label`s live in `strings.nav` / `strings.social`
- `src/i18n/strings.ts` — every chrome string as `{en, vi}`; the sheet's group labels, the Mode options, the language names (`langEn` / `langVi`, each named in its own language) and the language action labels (`langSwitch`, `switchTo`) live in `strings.nav`, the social `aria-label`s in `strings.social`
## Component Structure
@@ -79,7 +80,7 @@ src/
components/
layout/ — Layout.tsx, Navigation.tsx, MobileMenu.tsx, Footer.tsx, ThemePaletteMenu.tsx
sections/ — Hero, About, Expertise, Experience, Projects, Contact, HeroParticles, DownloadResume
ui/ — Badge, Button, SectionHeading, SocialLinks, Tag, Typewriter, InView, RollingTextLink, BackToTop
ui/ — Badge, Button, LanguageIcon, SectionHeading, SocialLinks, Tag, Typewriter, InView, RollingTextLink, BackToTop
index.ts — barrel export
data/ — profile, skills, experience, projects, resume, palettes, navigation, social (TS modules)
hooks/ — useTheme.tsx, useLanguage.tsx, useClickOutside.ts
+3 -3
View File
@@ -101,9 +101,9 @@ App
| Property | Value |
|---|---|
| Location | Navigation bar (right side, the last of the three appearance controls — after the mode toggle) at **every** width — the control is not hidden at ≤1024px (Q14) — plus the Theme color row, the last of three rows in the mobile sheet's Appearance group (Language → Mode → Theme color), while the sheet is open |
| Control | Bar: `ThemePaletteMenu` (`src/components/layout/ThemePaletteMenu.tsx`), icon-only trigger — a 20px half-circle swatch (active palette's accent left, `--swatch-empty` right), no text and no chevron, name in `aria-label`, hint in `title` — opening the `#palette-menu` panel. Sheet: rendered by `MobileMenu.tsx` from `paletteIds` + `paletteMeta` as `.mobile-menu-swatch-option` buttons — the Mode/Language segmented-row shape, options drawn as colour icons |
| Control | Bar: `ThemePaletteMenu` (`src/components/layout/ThemePaletteMenu.tsx`), icon-only trigger — a 20px half-circle swatch (active palette's accent left, `--swatch-empty` right), no text and no chevron, name in `aria-label`, hint in `title` — opening the `#palette-menu` panel. Sheet: rendered by `MobileMenu.tsx` from `paletteIds` + `paletteMeta` as `.mobile-menu-icon-option` buttons — the 44px icon-only square the Language row shares, options drawn as colour icons |
| Options | `red` (default) / `blue` — `src/data/palettes.ts` (`paletteIds`, `paletteMeta.label`/`hint`), written to `data-palette` on `<html>`; the sheet lists both, one colour icon each |
| Chrome | The bar's three appearance controls share `.nav-control` (44px bordered box, accent border + text on hover/open, one `:focus-visible`) and sit in `.nav-actions` at the bar's right end in the order language → mode → theme color; the hamburger leads the bar inside `.nav-brand`, left of the logo (Q17 of `specs/v3/spec-v3-nav-swatch-and-hamburger.md`, superseding that spec's Q16 hamburger-last clause), with a `@media (max-width: 420px)` guard so the row fits 320px |
| Chrome | The bar's three appearance controls share `.nav-control` (44px bordered box, accent border + icon on hover/open, one `:focus-visible`) and sit in `.nav-actions` at the bar's right end in the order language → mode → theme color; the hamburger leads the bar inside `.nav-brand`, left of the logo (Q17 of `specs/v3/spec-v3-nav-swatch-and-hamburger.md`, superseding that spec's Q16 hamburger-last clause), with a `@media (max-width: 420px)` guard so the row fits 320px |
Spec: `specs/v3/spec-v3-theme-palette-switch.md`.
@@ -112,7 +112,7 @@ Spec: `specs/v3/spec-v3-theme-palette-switch.md`.
| Property | Value |
|---|---|
| Trigger | Hamburger button at the bar's **left edge**, immediately left of the brand home icon (`.nav-logo`, a `<Link to="/">`), ≤1024px (Q17) |
| Groups | Menu (6 routes) → Appearance (Language, Mode, Theme color) → Connect (GitHub, LinkedIn, email) |
| Groups | Menu (6 routes) → Appearance (Language — icon-only globe / flag-outline options, Mode, Theme color) → Connect (GitHub, LinkedIn, email) |
| Behaviour | `role="dialog"` + `aria-modal="true"` + `tabIndex={-1}`: focus lands on the panel itself on open — never on a link, because focusing a link fires its rolling-text animation — Escape closes from any focus position, `#main-content` / `.footer` / `.back-to-top` are `inert` while open, body scroll locked |
Spec: `specs/v3/spec-v3-mobile-navigation.md`.
+34 -33
View File
@@ -42,13 +42,14 @@ Add full English/Vietnamese bilingual support to the portfolio. Users can toggle
| 18 | Update `ContactPage.tsx` (heading, labels) | 1 | ✅ Completed |
| 19 | Update `profile.ts` (fix tagline to VI) | 1 | ✅ Completed |
| 20 | Update `skills.ts` (add `titleEn` to skillGroups) | 1 | ✅ Completed |
| 21 | Add `.lang-toggle` CSS styles | 1 | ✅ Completed |
| 21 | Add `.lang-toggle` CSS styles | 1 | ✅ Completed — superseded 2026-10-17 by row 28 |
| 22 | **Phase 1 Complete** | | ✅ Completed |
| 23 | Create `src/i18n/useLocaleData.ts` (API fetch + fallback) | 2 | ⬜ Pending |
| 24 | Update all components to use `useLocaleData()` | 2 | ⬜ Pending |
| 25 | Remove `src/i18n/strings.ts` | 2 | ⬜ Pending |
| 26 | Remove `src/i18n/useField.ts` | 2 | ⬜ Pending |
| 27 | **Phase 2 Complete** | | ⬜ Pending |
| 28 | Language control → icon-only wireframe (globe / flag outline), `.lang-toggle` CSS deleted — 2026-10-17 | 1 | ✅ Completed |
## Current State Analysis
@@ -412,43 +413,42 @@ export function useLocaleData() {
---
## CSS
## Language Control — icon rendering (2026-10-17)
### Language Toggle Button
Supersedes the text-glyph design this spec first specified — `{lang === 'en' ? 'VI' : 'EN'}` in
`nav-control lang-toggle`, plus the `.lang-toggle` block that moved to `src/App.css` and is now
deleted. Both renderings are icon-only.
```css
/* src/index.css */
.lang-toggle {
display: flex;
align-items: center;
gap: 4px;
padding: 6px 10px;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--bg-surface);
color: var(--text-primary);
cursor: pointer;
font-size: 13px;
font-weight: 500;
transition: all 0.2s ease;
}
Both icons are line drawings. The filled first pass (red `#da251d` field, `#ff0` star, scaled from
the Wikimedia flag SVG) was redrawn as a wireframe the same day on the owner's request, then re-cut
twice more the same day: band 21×14 → 21×16 → 21×17.5 to follow the globe's footprint, mullet r=4.2
at 2px → r=3.6 at 1.5px.
.lang-toggle:hover {
border-color: var(--accent);
color: var(--accent);
}
`src/components/ui/LanguageIcon.tsx` draws one 20×20 icon per language:
.lang-toggle .lang-label {
text-transform: uppercase;
letter-spacing: 0.5px;
}
| Language | Drawing | Stroke |
|---|---|---|
| `en` | globe: circle r=10, equator `M2 12h20`, meridian ellipse rx=4 ry=10 | `currentColor`, 2px, round joins — follows `.nav-control:hover`'s accent, like the mode toggle |
| `vi` | flag outline: 21×17.5 band (`rx=2`) at 1.5/3.25 — drawn 23×19.5 against the globe's 22×22; the width is already at the limit (the globe's own stroke spans 1..23), so every further size step has to come from height, and height drags the constitutional 2:3 to 1.2; the mullet centred at (12, 12) stays under the flag's own 0.6 × band-height construction — radius 3.6, drawn ≈ 8.3 units ≈ 36% × 41% of the band — traced as its concave decagon rather than a self-crossing pentagram | `currentColor`, no fills: band 2px round joins; star 1.5px round joins. 2px ink at r=3.6 closes the inner pentagon into a blob (the gap is 2(0.309·R − strokeWidth/2)), and miter joins throw a spike 3.24 × strokeWidth/2 past each 36° tip, drawing the star larger than its own radius |
.lang-toggle .lang-icon {
width: 16px;
height: 16px;
opacity: 0.7;
}
```
**Bar** (`src/components/layout/Navigation.tsx`): `nav-control lang-toggle` shows the language it
switches TO — the same contract the old glyph had.
| Attribute | Source |
|---|---|
| `aria-label` | `strings.nav.langSwitch[lang]` — `Switch language` / `Đổi ngôn ngữ` |
| `title` | `strings.nav.switchTo[lang]` + the target's `langEn` / `langVi` — `Switch to Tiếng Việt` / `Chuyển sang English` |
| Content | `<LanguageIcon lang={targetLang} />`, `aria-hidden="true"` + `focusable="false"` |
| CSS | `.nav-control` chrome only; `.lang-toggle` carries no rules of its own — it marks the button in the DOM |
**Sheet** (`src/components/layout/MobileMenu.tsx`): the Language row's two options are
`.mobile-menu-icon-option` — the 44px icon-only square the Theme color row uses. The Mode row keeps
`.mobile-menu-segment-option`, because its options are words. Each option carries `aria-pressed` and
its own-language name in `aria-label` and `title`: an icon alone cannot say which language it is.
`langEn` / `langVi` stay flat `{en, vi}` records. A nested `langName: { en: …, vi: … }` record inside
`strings.nav` was tried and rejected: `strings.nav[navKey][lang]`, the lookup both components use for
nav labels, would then carry an object in its value union and `tsc` rejects it as a `ReactNode`.
---
@@ -459,6 +459,7 @@ export function useLocaleData() {
- [ ] Testing: Verify all strings render correctly in both languages
- [ ] Testing: Verify language toggle persists across page navigation
- [ ] Testing: Verify language preference persists across sessions (localStorage)
- [x] Testing: 2026-10-17 icon swap — throwaway SSR render of `Navigation` + `MobileMenu` at `lang=en` and `lang=vi`: bar icon equals the target language's icon, `aria-label`/`title` translated, sheet options icon-only with `aria-pressed`, Mode row still word-based — 24/24 PASS, script deleted after the run. Visual pass left to the owner's browser (repo rule §5).
---
@@ -327,7 +327,7 @@ langEn: {en: 'English', vi: 'English'},
langVi: {en: 'Tiếng Việt', vi: 'Tiếng Việt'},
```
`langEn` / `langVi` carry the same value in both locales on purpose: a language option is named in its own language, so a reader who cannot read English can still find "Tiếng Việt". The bar keeps the short `VI` / `EN` codes (`Navigation.tsx:84`); the sheet uses full names because it has the width.
`langEn` / `langVi` carry the same value in both locales on purpose: a language option is named in its own language, so a reader who cannot read English can still find "Tiếng Việt". The bar keeps the short `VI` / `EN` codes (`Navigation.tsx:84`); the sheet uses full names because it has the width. **Superseded 2026-10-17:** both renderings are icons now — the bar shows the target language's globe/flag, the sheet's Language row shows both — and the own-language names moved into `aria-label` / `title`. See `spec-v3-i18n.md` §Language Control.
New block, replacing `strings.common.socialAriaLabels` (`strings.ts:106-110`), which is **deleted** — it already holds these three values and is consumed by nothing today:
@@ -228,7 +228,7 @@ No new state, no new handler, no `initial` prop (the component mounts closed, so
### Step 5 — nothing else
`Navigation.tsx`, `MobileMenu.tsx`, `strings.ts`, `useClickOutside.ts`, `palettes.ts` and the language control are not touched. No CSS class is added or removed; `.lang-toggle` (`src/App.css:119-123`) stays live.
`Navigation.tsx`, `MobileMenu.tsx`, `strings.ts`, `useClickOutside.ts`, `palettes.ts` and the language control are not touched. No CSS class is added or removed; `.lang-toggle` (`src/App.css:119-123`) stays live. **Superseded 2026-10-17:** the language control became icon-only line art (globe / flag outline, `src/components/ui/LanguageIcon.tsx`) and its `.lang-toggle` rules were deleted, so the bar's three controls are all icon-only; §2.1 facts 1–3 describe the pre-change baseline. See `spec-v3-i18n.md` §Language Control.
---
+1 -1
View File
@@ -48,7 +48,7 @@ Reading bands used: 45-75 characters (Bringhurst), 38-80 (Butterick). Before: 11
1. **Font: admit `system-ui`.** `--sans` becomes `system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif`. No webfont is loaded; the Source Sans 3 woff2 files stay in `public/fonts/` because `scripts/generate-resume.ts` reads them from disk for the PDF. (User's call: keep the current look rather than restyle the whole site.)
2. **Scale tokens** in `:root`: `--text-body: 18px`, `--text-lede: 20px`, `--text-meta: 15px`, `--leading-body: 1.65`, `--measure-prose: 600px`, `--measure-page: 680px` (added in the second pass, §3.10). They live in `:root` only — sizes do not differ between dark and light, so they are not duplicated in the light block or the media bridge.
3. **Reuse `.prose`** (`App.css`, previously defined and never rendered by any component) as the prose system instead of inventing a second convention.
4. **Role sizes.** Body copy 18px/1.65 everywhere a paragraph is the main content; lead paragraphs 20px/1.55; dense secondary copy (timeline bullets, achievement context and impact, expertise skill lists, card summaries, contact sub-labels) 15px/1.65. Literal 12-14px stays reserved for chrome: `.tag`, `.badge`, `.achievement-metric`, `.footer-text`, `.footer-link`, `.timeline-duration`, `.project-card-cta`, `.lang-toggle`, `pre`.
4. **Role sizes.** Body copy 18px/1.65 everywhere a paragraph is the main content; lead paragraphs 20px/1.55; dense secondary copy (timeline bullets, achievement context and impact, expertise skill lists, card summaries, contact sub-labels) 15px/1.65. Literal 12-14px stays reserved for chrome: `.tag`, `.badge`, `.achievement-metric`, `.footer-text`, `.footer-link`, `.timeline-duration`, `.project-card-cta`, `pre`. (`.lang-toggle` was on that list until 2026-10-17, when the language control became an icon and its glyph step was deleted.)
5. **Heading sizes**: `h3` 24 → **21px**, and `h4` 18 / `h5` 16 / `h6` 15 made explicit (they previously fell back to 16px). `h1`/`h2` clamps and the global `h1-h6 { line-height: 1.2 }` are untouched.
6. **Paragraph rhythm lives only inside `.prose`** (`.prose p { margin-bottom: 1em }`, `:last-child` 0). The global `p` keeps `margin: 0` from the reset, so hero, cards, section subtitles and contact tiles are unaffected.
7. **Headings carry their own top margin** (`.subheading { margin-top: 32px }`, `.prose h3 { margin-top: 1.5em }`, `.philosophy-quote h3 { margin-top: 0 }`); lead paragraphs carry no bottom margin. Sibling margins collapse, so each gap is a single value rather than a sum.
+10 -14
View File
@@ -96,7 +96,9 @@
}
/* One chrome for the three bar controls — mode, theme color, language: a bordered 44px box,
accent border + text on hover/open. Per-control rules add only what is specific to them. */
accent border + icon on hover/open. The language control is icon-only like the other two, so it
carries no rules of its own any more: `.lang-toggle` marks the button in the DOM and nothing
else. */
.nav-control {
display: flex;
align-items: center;
@@ -124,13 +126,6 @@
outline-offset: 2px;
}
/* The language control's glyph is chrome: 13px/600 is its own scale step. */
.lang-toggle {
font-size: 13px;
font-weight: 600;
letter-spacing: 0.5px;
}
.mobile-menu-btn {
display: none;
background: none;
@@ -276,9 +271,10 @@
outline-offset: 2px;
}
/* The palette options use the Mode/Language segmented row's shape — same 44px target, border
and radius — drawn as colour icons via the existing .nav-palette-preview dot. */
.mobile-menu-swatch-option {
/* Icon-only options in the sheet share this shape — the segmented row's 44px target, border and
radius — for the Theme color dots (.nav-palette-preview) and the Language globe/flag. The Mode
row keeps .mobile-menu-segment-option, because its options are words. */
.mobile-menu-icon-option {
display: flex;
align-items: center;
justify-content: center;
@@ -292,16 +288,16 @@
transition: background var(--transition-fast), border-color var(--transition-fast);
}
.mobile-menu-swatch-option:hover {
.mobile-menu-icon-option:hover {
background: var(--bg-elevated);
}
.mobile-menu-swatch-option.active {
.mobile-menu-icon-option.active {
border-color: var(--accent);
background: var(--bg-elevated);
}
.mobile-menu-swatch-option:focus-visible {
.mobile-menu-icon-option:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
+13 -5
View File
@@ -8,6 +8,7 @@ import { useLanguage } from '@/hooks/useLanguage'
import { strings } from '@/i18n/strings'
import { RollingTextLink } from '@/components/ui/RollingTextLink'
import { SocialLinks } from '@/components/ui/SocialLinks'
import { LanguageIcon } from '@/components/ui/LanguageIcon'
interface MobileMenuProps {
open: boolean
@@ -72,21 +73,28 @@ export function MobileMenu({ open, onClose }: MobileMenuProps) {
<div className="mobile-menu-segment">
<span className="mobile-menu-segment-label">{strings.nav.langGroup[lang]}</span>
<div className="mobile-menu-segment-options" role="group" aria-label={strings.nav.langGroup[lang]}>
{/* Icons, not words — globe for English, red flag for Tiếng Việt — in the same
44px icon-only shape as the Theme color row. An icon cannot say which language
it is, so each option carries its own-language name in aria-label and title. */}
<button
type="button"
className={lang === 'en' ? 'mobile-menu-segment-option active' : 'mobile-menu-segment-option'}
className={lang === 'en' ? 'mobile-menu-icon-option active' : 'mobile-menu-icon-option'}
aria-pressed={lang === 'en'}
aria-label={strings.nav.langEn[lang]}
title={strings.nav.langEn[lang]}
onClick={() => setLang('en')}
>
{strings.nav.langEn[lang]}
<LanguageIcon lang="en" />
</button>
<button
type="button"
className={lang === 'vi' ? 'mobile-menu-segment-option active' : 'mobile-menu-segment-option'}
className={lang === 'vi' ? 'mobile-menu-icon-option active' : 'mobile-menu-icon-option'}
aria-pressed={lang === 'vi'}
aria-label={strings.nav.langVi[lang]}
title={strings.nav.langVi[lang]}
onClick={() => setLang('vi')}
>
{strings.nav.langVi[lang]}
<LanguageIcon lang="vi" />
</button>
</div>
</div>
@@ -120,7 +128,7 @@ export function MobileMenu({ open, onClose }: MobileMenuProps) {
<button
key={id}
type="button"
className={palette === id ? 'mobile-menu-swatch-option active' : 'mobile-menu-swatch-option'}
className={palette === id ? 'mobile-menu-icon-option active' : 'mobile-menu-icon-option'}
aria-pressed={palette === id}
aria-label={paletteMeta[id].label[lang]}
title={paletteMeta[id].hint[lang]}
+9 -3
View File
@@ -7,11 +7,14 @@ import { strings } from '@/i18n/strings'
import { navPaths } from '@/data/navigation'
import { RollingTextLink } from '@/components/ui/RollingTextLink'
import { ThemePaletteMenu } from '@/components/layout/ThemePaletteMenu'
import { LanguageIcon } from '@/components/ui/LanguageIcon'
import { MobileMenu } from '@/components/layout/MobileMenu'
export function Navigation() {
const { cycleTheme, resolvedTheme } = useTheme()
const { lang, toggleLang } = useLanguage()
const targetLang = lang === 'en' ? 'vi' : 'en'
const targetLabel = targetLang === 'en' ? strings.nav.langEn[lang] : strings.nav.langVi[lang]
const [mobileOpen, setMobileOpen] = useState(false)
const location = useLocation()
const triggerRef = useRef<HTMLButtonElement>(null)
@@ -125,13 +128,16 @@ export function Navigation() {
</ul>
<div className="nav-actions">
{/* The control names the language it switches TO — the same contract the old VI/EN
glyph had, now drawn: globe for English, red flag for Tiếng Việt. The icon is
decorative; the accessible name is the translated action, the target is the title. */}
<button
className="nav-control lang-toggle"
onClick={toggleLang}
aria-label="Switch language"
title={`Switch to ${lang === 'en' ? 'Tiếng Việt' : 'English'}`}
aria-label={strings.nav.langSwitch[lang]}
title={`${strings.nav.switchTo[lang]} ${targetLabel}`}
>
{lang === 'en' ? 'VI' : 'EN'}
<LanguageIcon lang={targetLang} />
</button>
<button
+47
View File
@@ -0,0 +1,47 @@
import type { Language } from '@/types'
/* Both icons are line drawings in the bar's stroke language — currentColor, no fills — so the
language control sits beside the house, the sun/moon and the palette swatch without importing a
colour the palette has to argue with.
Flag: a 21×17.5 band at 1.5/3.25 — drawn 23×19.5 with the 2px stroke, against the globe's 22×22.
Width is already at the limit (the globe's own stroke spans 1..23), so every further size step has
to come from height, and height is what drags it off the constitutional 2:3 (1.5 → 1.2). The star
is deliberately under the flag's own construction (0.6 × band height): radius 3.6, drawn ≈ 8.3
units ≈ 36% × 41% of the band.
The star's stroke is 1.5, not 2: an outline star at this size only keeps a visible interior if
the ink is thin — the gap across its inner pentagon is 2(0.309·R − strokeWidth/2), so 2px ink at
R=3.6 would close the middle into a blob. Round joins, not miter: a 36° tip throws a miter spike
3.24 × strokeWidth/2 past the vertex, which would draw the star bigger than its own radius. */
const FLAG_STAR = '12,8.4 12.81,10.89 15.42,10.89 13.31,12.42 14.12,14.91 12,13.38 9.88,14.91 10.69,12.42 8.58,10.89 11.19,10.89'
export function LanguageIcon({ lang }: { lang: Language }) {
if (lang === 'vi') {
return (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true" focusable="false">
<rect x="1.5" y="3.25" width="21" height="17.5" rx="2" />
<polygon points={FLAG_STAR} strokeWidth="1.5" strokeLinejoin="round" />
</svg>
)
}
return (
<svg
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="12" cy="12" r="10" />
<path d="M2 12h20" />
<ellipse cx="12" cy="12" rx="4" ry="10" />
</svg>
)
}
+2
View File
@@ -19,6 +19,8 @@ export const strings = {
langGroup: {en: 'Language', vi: 'Ngôn ngữ'},
langEn: {en: 'English', vi: 'English'},
langVi: {en: 'Tiếng Việt', vi: 'Tiếng Việt'},
langSwitch: {en: 'Switch language', vi: 'Đổi ngôn ngữ'},
switchTo: {en: 'Switch to', vi: 'Chuyển sang'},
},
social: {
heading: {en: 'Connect', vi: 'Kết nối'},