feat(nav): resume entry in the bar with a shared language dialog

ResumeNavButton is the third item in .nav-brand, right after the home icon: a 44px icon target named by strings.nav.resume, aria-haspopup=dialog on its own #resume-modal-nav, gated on resumeAvailable.

The picker markup is no longer duplicated. ResumeDialog owns the overlay, panel and resumeLanguages options and takes a dialogId, so the hero keeps #resume-modal and the bar gets #resume-modal-nav. useResumeDialog holds the state both triggers share: open flag, container/trigger/panel refs, click-outside (close guarded on openRef, because the listener is live while closed and otherwise steals focus on every page click), Escape, body-overflow lock and focus return. Panel focus moved from onAnimationComplete to a one-frame effect: AnimatePresence keeps open=true on the exiting copy, so the old handler refired at the end of the exit and stranded focus on <body>. resumeAvailable now gates the leaf components, so Hero renders <DownloadResume /> plainly.
This commit is contained in:
dong.nguyen committed 2026-10-20 00:33:28 +07:00
1 parent 25b0ead76a
commit 4f1d4ebe30
8 files changed
+212 -78

No files matched your search

+4
View File
@@ -9,6 +9,7 @@ import { RollingTextLink } from '@/components/ui/RollingTextLink'
import { ThemePaletteMenu } from '@/components/layout/ThemePaletteMenu'
import { LanguageIcon } from '@/components/ui/LanguageIcon'
import { MobileMenu } from '@/components/layout/MobileMenu'
import { ResumeNavButton } from '@/components/layout/ResumeNavButton'
export function Navigation() {
const { cycleTheme, resolvedTheme } = useTheme()
@@ -107,6 +108,9 @@ export function Navigation() {
<polyline points="9 22 9 12 15 12 15 22" />
</svg>
</Link>
{/* Resume lives next to home: it is a site-wide action, not an appearance control, so
it belongs in the brand group and stays put when the sheet takes over the bar. */}
<ResumeNavButton />
</div>
<ul className="nav-menu">
+37
View File
@@ -0,0 +1,37 @@
import { resumeAvailable } from '@/data/resume'
import { useLanguage } from '@/hooks/useLanguage'
import { useResumeDialog } from '@/hooks/useResumeDialog'
import { ResumeDialog } from '@/components/ui/ResumeDialog'
import { ResumeIcon } from '@/components/ui/icons'
import { strings } from '@/i18n/strings'
/**
* Bar entry for the resume: an icon-only `.nav-control` in the brand group, right after the home
* icon, opening the same language dialog the hero CTA opens. The icon is decorative — the
* accessible name is the translated action in `aria-label`, the hint is the `title`.
*/
export function ResumeNavButton() {
const { lang } = useLanguage()
const { open, openDialog, close, containerRef, triggerRef, panelRef } = useResumeDialog()
if (!resumeAvailable) return null
return (
<div ref={containerRef} className="nav-resume">
<button
ref={triggerRef}
type="button"
className={`nav-control nav-resume-trigger ${open ? 'open' : ''}`}
aria-haspopup="dialog"
aria-expanded={open}
aria-controls="resume-modal-nav"
aria-label={strings.nav.resume[lang]}
title={strings.common.resumeModalHint[lang]}
onClick={openDialog}
>
<ResumeIcon />
</button>
<ResumeDialog open={open} close={close} panelRef={panelRef} dialogId="resume-modal-nav" />
</div>
)
}
+17 -47
View File
@@ -1,71 +1,41 @@
import { resumeUrlFor, resumeLanguages, resumeLanguageLabels } from '@/data/resume'
import { useState, useRef, useEffect } from 'react'
import { resumeAvailable } from '@/data/resume'
import { useLanguage } from '@/hooks/useLanguage'
import { useResumeDialog } from '@/hooks/useResumeDialog'
import { ResumeDialog } from '@/components/ui/ResumeDialog'
import { strings } from '@/i18n/strings'
interface DownloadResumeDropdownProps {
className?: string
wrapperClassName?: string
targetBlank?: boolean
}
export function DownloadResumeDropdown({ className, wrapperClassName, targetBlank = false }: DownloadResumeDropdownProps) {
export function DownloadResume() {
const { lang } = useLanguage()
const [open, setOpen] = useState(false)
const ref = useRef<HTMLDivElement>(null)
const { open, openDialog, close, containerRef, triggerRef, panelRef } = useResumeDialog()
useEffect(() => {
if (!open) return
const listener = (e: MouseEvent | TouchEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) {
setOpen(false)
}
}
document.addEventListener('mousedown', listener)
document.addEventListener('touchstart', listener)
return () => {
document.removeEventListener('mousedown', listener)
document.removeEventListener('touchstart', listener)
}
}, [open])
if (!resumeAvailable) return null
return (
<div ref={ref} className={`download-resume-dropdown ${className ?? ''}`}>
<div className="download-resume-shared-wrapper">
<div ref={containerRef} className="download-resume">
<div className="download-resume-lazer-wrapper">
<div className="download-resume-lazer-border" />
<div className="download-resume-lazer-glow" />
<div className="download-resume-lazer-inner">
<button
className={`download-resume-summary ${wrapperClassName ?? ''} ${open ? 'open' : ''}`}
onClick={() => setOpen(!open)}
ref={triggerRef}
type="button"
className={`download-resume-summary ${open ? 'open' : ''}`}
aria-haspopup="dialog"
aria-expanded={open}
aria-controls="resume-modal"
title={strings.common.resumeModalHint[lang]}
onClick={openDialog}
>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="20" height="20">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="20" height="20" aria-hidden="true">
<path d="M12 3v10m0 0l-3-3m3 3l3-3" />
<path d="M3 17h18" />
</svg>
<span>{strings.common.resumeDownload[lang]}</span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="16" height="16" className="chevron">
<polyline points="6 9 12 15 18 9" />
</svg>
</button>
</div>
</div>
<div className={`download-resume-options ${open ? 'open' : ''}`}>
{resumeLanguages.map(lang => (
<a
key={lang}
href={resumeUrlFor(lang)}
download
target={targetBlank ? '_blank' : undefined}
className="download-resume-option"
>
{resumeLanguageLabels[lang]}
</a>
))}
</div>
</div>
<ResumeDialog open={open} close={close} panelRef={panelRef} dialogId="resume-modal" />
</div>
)
}
+2 -31
View File
@@ -1,11 +1,9 @@
import {motion, useScroll, useTransform} from "motion/react"
import {InView} from "@/components/ui/InView"
import {resumeAvailable, resumeLanguages, resumeUrlFor, resumeLanguageLabels} from "@/data/resume"
import type {Language} from '@/types'
import {useLanguage} from '@/hooks/useLanguage'
import {strings} from '@/i18n/strings'
import { field } from '@/i18n/field'
import {DownloadResumeDropdown} from '@/components/sections/DownloadResume'
import {DownloadResume} from '@/components/sections/DownloadResume'
import {Button} from "@/components/ui/Button"
@@ -14,21 +12,6 @@ import {HeroParticles} from '@/components/sections/HeroParticles'
import {SocialLinks} from "@/components/ui/SocialLinks"
import {profile} from "@/data/profile"
function HeroDownloadButton({lang}: { lang: Language }) {
const {lang: currentLang} = useLanguage()
return (
<a
href={resumeUrlFor(lang)}
download
target="_blank"
className="btn btn-primary hero-download-mobile-btn"
>
{strings.common.resumeDownload[currentLang]} ({resumeLanguageLabels[lang]})
</a>
)
}
export function Hero() {
const {scrollY} = useScroll()
const {lang} = useLanguage()
@@ -103,19 +86,7 @@ export function Hero() {
<Button href="/contact" variant="primary">
{strings.hero.ctaContact[lang]}
</Button>
{resumeAvailable && (
<>
<div className="hero-download-desktop">
<DownloadResumeDropdown className="hero-download-dropdown"
wrapperClassName="hero-download-summary" targetBlank/>
</div>
<div className="hero-download-mobile">
{resumeLanguages.map(lang => (
<HeroDownloadButton key={lang} lang={lang} />
))}
</div>
</>
)}
<DownloadResume />
<SocialLinks />
</motion.div>
+88
View File
@@ -0,0 +1,88 @@
import { AnimatePresence, motion } from 'motion/react'
import { useEffect } from 'react'
import { resumeUrlFor, resumeLanguages, resumeLanguageLabels } from '@/data/resume'
import { useLanguage } from '@/hooks/useLanguage'
import { strings } from '@/i18n/strings'
type ResumeDialogProps = {
open: boolean
close: () => void
panelRef: React.RefObject<HTMLDivElement | null>
dialogId: string
}
/**
* The language picker. Mounted by every trigger with its own `dialogId` so `aria-controls` never
* points at a duplicated id when two triggers are on the same page.
*/
export function ResumeDialog({ open, close, panelRef, dialogId }: ResumeDialogProps) {
const { lang } = useLanguage()
// Enter only, one frame late so the panel is on screen before it takes focus. AnimatePresence
// keeps the open=true props on its exiting copy, so an onAnimationComplete handler fires again
// when the exit animation ends and strands focus on <body> as the panel unmounts.
useEffect(() => {
if (!open) return
const frame = requestAnimationFrame(() => panelRef.current?.focus())
return () => cancelAnimationFrame(frame)
}, [open, panelRef])
return (
<AnimatePresence>
{open && (
<motion.div
className="resume-modal-overlay"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.18, ease: 'easeOut' }}
onClick={close}
>
<motion.div
ref={panelRef}
id={dialogId}
className="resume-modal"
role="dialog"
aria-modal="true"
aria-label={strings.common.resumeModalAria[lang]}
tabIndex={-1}
initial={{ opacity: 0, y: 12, scale: 0.98 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
exit={{ opacity: 0, y: 12, scale: 0.98 }}
transition={{ duration: 0.18, ease: [0.25, 0.1, 0.25, 1] }}
onClick={event => event.stopPropagation()}
>
<div className="resume-modal-head">
<h3>{strings.common.resumeModalTitle[lang]}</h3>
<button
type="button"
className="resume-modal-close"
aria-label={strings.common.resumeModalClose[lang]}
onClick={close}
>
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true">
<path d="M18 6 6 18M6 6l12 12" />
</svg>
</button>
</div>
<p className="resume-modal-hint">{strings.common.resumeModalHint[lang]}</p>
<div className="resume-modal-options">
{resumeLanguages.map(optionLang => (
<a
key={optionLang}
className="resume-modal-option"
href={resumeUrlFor(optionLang)}
download
onClick={close}
>
<span className="resume-modal-option-label">{resumeLanguageLabels[optionLang]}</span>
<span className="resume-modal-option-file">{resumeUrlFor(optionLang)}</span>
</a>
))}
</div>
</motion.div>
</motion.div>
)}
</AnimatePresence>
)
}
+12
View File
@@ -43,3 +43,15 @@ export function TelegramIcon({ size = 20 }: IconProps) {
</svg>
)
}
// CV lettering, same 2px stroke language as the bar's other glyphs: a C arc open to the right and
// a V, sized to fill the 24 grid. A document outline with small lettering inside was rasterized
// first and merged into mush at the bar's 20px, so the letters carry the meaning alone.
export function ResumeIcon({ size = 20 }: IconProps) {
return (
<svg viewBox="0 0 24 24" width={size} height={size} aria-hidden="true" {...strokeProps}>
<path d="M13.5 7.8A6.5 6.5 0 1 0 13.5 16.2" />
<path d="M15 6l3.5 12L22 6" />
</svg>
)
}
+47
View File
@@ -0,0 +1,47 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { useClickOutside } from '@/hooks/useClickOutside'
/**
* Open/close state for the resume language dialog. Two triggers mount their own instance — the
* hero CTA and the navigation bar icon — so each keeps its own refs and focus returns to the
* control that opened the dialog.
*/
export function useResumeDialog() {
const [open, setOpen] = useState(false)
const openRef = useRef(false)
const containerRef = useRef<HTMLDivElement>(null)
const triggerRef = useRef<HTMLButtonElement>(null)
const panelRef = useRef<HTMLDivElement>(null)
useEffect(() => {
openRef.current = open
}, [open])
// The click-outside listener is live whether or not the dialog is open, so closing has to be
// guarded: an outside click while closed must not pull focus to the trigger.
const close = useCallback(() => {
if (!openRef.current) return
openRef.current = false
setOpen(false)
triggerRef.current?.focus()
}, [])
const openDialog = useCallback(() => setOpen(true), [])
useClickOutside(containerRef, close)
useEffect(() => {
if (!open) return
document.body.style.overflow = 'hidden'
const handleKey = (event: KeyboardEvent) => {
if (event.key === 'Escape') close()
}
document.addEventListener('keydown', handleKey)
return () => {
document.body.style.overflow = ''
document.removeEventListener('keydown', handleKey)
}
}, [open, close])
return { open, openDialog, close, containerRef, triggerRef, panelRef }
}
+5
View File
@@ -1,6 +1,7 @@
export const strings = {
nav: {
home: {en: 'Home', vi: 'Trang chủ'},
resume: {en: 'Get resume', vi: 'Tải CV'},
about: {en: 'About', vi: 'Giới thiệu'},
experience: {en: 'Experience', vi: 'Kinh nghiệm'},
projects: {en: 'Projects', vi: 'Dự án'},
@@ -118,6 +119,10 @@ export const strings = {
},
common: {
resumeDownload: {en: 'Get Resume', vi: 'Tải CV'},
resumeModalTitle: {en: 'Get Resume', vi: 'Tải CV'},
resumeModalAria: {en: 'Choose resume language', vi: 'Chọn ngôn ngữ CV'},
resumeModalHint: {en: 'Choose a language — the PDF downloads to your device.', vi: 'Chọn ngôn ngữ — PDF sẽ tải về máy của bạn.'},
resumeModalClose: {en: 'Close resume options', vi: 'Đóng tùy chọn tải CV'},
backToTop: {en: 'Scroll to top', vi: 'Cuộn lên đầu trang'},
contactTag: {en: 'Contact', vi: 'Liên hệ'},
experienceTag: {en: 'Experience', vi: 'Kinh nghiệm'},