mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-22 16:10:40 +07:00
replace language text by icon
This commit is contained in:
1 parent
c95f7b09d1
commit
df65f4c774
11 files changed
+126
-65
No files matched your search
+10
-14
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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]}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
@@ -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'},
|
||||
|
||||
Reference in new issue
Block a user