Files
cv/src/components/ui/ResumeDialog.tsx
T
dong.nguyen 4f1d4ebe30 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.
2026-10-20 00:33:28 +07:00

89 lines
3.3 KiB
TypeScript

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>
)
}