feat(header): replace flat language links with globe-icon dropdown

Rewrites LanguageSwitcher to match the live site: a trigger showing the
active language code and a Bootstrap Icons globe SVG reveals a hover/
focus-within dropdown with full language names (English, Español, عربي).
Fixes hover gap by moving visual spacing into menu padding-top so the
hover zone is continuous from trigger to menu items.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 17:10:20 -07:00
parent 626f1b7f37
commit 796bc223af
2 changed files with 39 additions and 10 deletions
+28 -6
View File
@@ -18,14 +18,36 @@ for (const entry of posts) {
const prefix = entry.data.lang === 'en' ? '' : `/${entry.data.lang}`; const prefix = entry.data.lang === 'en' ? '' : `/${entry.data.lang}`;
available.add(`${prefix}/library/${entry.data.slug}`); available.add(`${prefix}/library/${entry.data.slug}`);
} }
const langMeta: Record<string, { short: string; full: string }> = {
en: { short: 'EN', full: 'English' },
es: { short: 'ES', full: 'Español' },
ar: { short: 'ع', full: 'عربي' },
};
const choices = [ const choices = [
{ code: 'en', label: 'EN', href: bare }, { code: 'en', href: bare },
{ code: 'es', label: 'ES', href: `/es${bare === '/' ? '' : bare}` }, { code: 'es', href: `/es${bare === '/' ? '' : bare}` },
{ code: 'ar', label: 'ع', href: `/ar${bare === '/' ? '' : bare}` } { code: 'ar', href: `/ar${bare === '/' ? '' : bare}` },
].filter(({ href }) => available.has(href)); ].filter(({ href }) => available.has(href));
const activeCode = pathname.startsWith('/ar') ? 'ar' : pathname.startsWith('/es') ? 'es' : 'en';
const activeShort = langMeta[activeCode]?.short ?? 'EN';
--- ---
<nav class="language-switcher" aria-label="Language"> <nav class="lang-switcher" aria-label="Language">
{choices.map(({ code, label, href }) => ( <div class="lang-switcher__trigger" tabindex="0" aria-haspopup="listbox" aria-label={`Language: ${activeCode.toUpperCase()}`}>
<a href={href} lang={code} aria-current={pathname === href || (href === '/' && pathname === '/') ? 'page' : undefined}>{label}</a> <span class="lang-switcher__label">{activeShort}</span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16" aria-hidden="true">
<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855A7.97 7.97 0 0 0 5.145 4H7.5V1.077zM4.09 4a9.267 9.267 0 0 1 .64-1.539 6.7 6.7 0 0 1 .597-.933A7.025 7.025 0 0 0 2.255 4H4.09zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a6.958 6.958 0 0 0-.656 2.5h2.49zM4.847 5a12.5 12.5 0 0 0-.338 2.5H7.5V5H4.847zM8.5 5v2.5h2.99a12.495 12.495 0 0 0-.337-2.5H8.5zM4.51 8.5a12.5 12.5 0 0 0 .337 2.5H7.5V8.5H4.51zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5H8.5zM5.145 12c.138.386.295.744.468 1.068.552 1.035 1.218 1.65 1.887 1.855V12H5.145zm.182 2.472a6.696 6.696 0 0 1-.597-.933A9.268 9.268 0 0 1 4.09 12H2.255a7.024 7.024 0 0 0 3.072 2.472zM3.82 11a13.652 13.652 0 0 1-.312-2.5h-2.49c.062.89.291 1.733.656 2.5H3.82zm6.853 3.472A7.024 7.024 0 0 0 13.745 12H11.91a9.27 9.27 0 0 1-.64 1.539 6.688 6.688 0 0 1-.597.933zM8.5 12v2.923c.67-.204 1.335-.82 1.887-1.855.173-.324.33-.682.468-1.068H8.5zm3.68-1h2.146c.365-.767.594-1.61.656-2.5h-2.49a13.65 13.65 0 0 1-.312 2.5zm2.802-3.5a6.959 6.959 0 0 0-.656-2.5H12.18c.174.782.282 1.623.312 2.5h2.49zM11.27 2.461c.247.464.462.98.64 1.539h1.835a7.024 7.024 0 0 0-3.072-2.472c.218.284.418.598.597.933zM10.855 4a7.966 7.966 0 0 0-.468-1.068C9.835 1.897 9.17 1.282 8.5 1.077V4h2.355z" />
</svg>
</div>
<ul class="lang-switcher__menu" role="listbox">
{choices.map(({ code, href }) => (
<li>
<a href={href} lang={code} aria-current={pathname === href || (href === '/' && pathname === '/') ? 'page' : undefined}>
{langMeta[code]?.full}
</a>
</li>
))} ))}
</ul>
</nav> </nav>
+10 -3
View File
@@ -1,8 +1,15 @@
.utility-bar { background: var(--color-primary); color: white; font-size: .85rem; } .utility-bar { background: var(--color-primary); color: white; font-size: .85rem; }
.utility-inner { align-items: center; display: flex; gap: var(--space-md); justify-content: flex-end; min-height: 38px; } .utility-inner { align-items: center; display: flex; gap: var(--space-md); justify-content: flex-end; min-height: 38px; }
.utility-bar a { color: white; text-decoration: none; } .utility-bar a { color: white; text-decoration: none; }
.language-switcher { display: flex; gap: .6rem; } .lang-switcher { position: relative; }
.language-switcher [aria-current="page"] { color: var(--color-accent); } .lang-switcher__trigger { align-items: center; color: var(--color-primary); cursor: pointer; display: flex; font-size: .85rem; font-weight: 700; gap: .35rem; }
.lang-switcher__trigger svg { flex-shrink: 0; }
.lang-switcher__menu { background: white; box-shadow: var(--shadow-md); display: none; left: 50%; list-style: none; margin: 0; min-width: 110px; padding: .5rem 0 .4rem; position: absolute; top: 100%; transform: translateX(-50%); z-index: 10; }
.lang-switcher__menu a { color: rgb(83 83 91); display: block; font-size: .85rem; padding: .4rem .9rem; text-decoration: none; white-space: nowrap; }
.lang-switcher__menu a:hover { background: var(--color-primary); color: white; }
.lang-switcher__menu a[aria-current="page"] { color: var(--color-accent); font-weight: 700; }
.lang-switcher:hover .lang-switcher__menu,
.lang-switcher:focus-within .lang-switcher__menu { display: block; }
.site-header { background: white; box-shadow: var(--shadow-sm); position: relative; z-index: 5; } .site-header { background: white; box-shadow: var(--shadow-sm); position: relative; z-index: 5; }
.header-inner { align-items: center; display: flex; gap: 1.4rem; min-height: 110px; } .header-inner { align-items: center; display: flex; gap: 1.4rem; min-height: 110px; }
.brand { margin-right: auto; } .brand { margin-right: auto; }
@@ -120,7 +127,7 @@
@media (max-width: 760px) { @media (max-width: 760px) {
.utility-inner { justify-content: center; } .utility-inner { justify-content: center; }
.header-inner { min-height: 88px; } .header-inner { min-height: 88px; }
.header-inner .language-switcher { margin-left: auto; } .header-inner .lang-switcher { margin-left: auto; }
.process-grid { grid-template-columns: 1fr 1fr; } .process-grid { grid-template-columns: 1fr 1fr; }
.footer-bottom { align-items: flex-start; flex-direction: column; } .footer-bottom { align-items: flex-start; flex-direction: column; }
.library-layout { grid-template-columns: 1fr; } .library-layout { grid-template-columns: 1fr; }