From 4f1d4ebe3024e7c6301d87273ec30e4d3dff8152 Mon Sep 17 00:00:00 2001 From: "dong.nguyen" Date: Tue, 20 Oct 2026 00:33:28 +0700 Subject: [PATCH] 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 . resumeAvailable now gates the leaf components, so Hero renders plainly. --- src/components/layout/Navigation.tsx | 4 + src/components/layout/ResumeNavButton.tsx | 37 +++++++++ src/components/sections/DownloadResume.tsx | 88 +++++++--------------- src/components/sections/Hero.tsx | 33 +------- src/components/ui/ResumeDialog.tsx | 88 ++++++++++++++++++++++ src/components/ui/icons.tsx | 12 +++ src/hooks/useResumeDialog.ts | 47 ++++++++++++ src/i18n/strings.ts | 5 ++ 8 files changed, 224 insertions(+), 90 deletions(-) create mode 100644 src/components/layout/ResumeNavButton.tsx create mode 100644 src/components/ui/ResumeDialog.tsx create mode 100644 src/hooks/useResumeDialog.ts diff --git a/src/components/layout/Navigation.tsx b/src/components/layout/Navigation.tsx index d72d68d..6506147 100644 --- a/src/components/layout/Navigation.tsx +++ b/src/components/layout/Navigation.tsx @@ -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() { + {/* 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. */} +
    diff --git a/src/components/layout/ResumeNavButton.tsx b/src/components/layout/ResumeNavButton.tsx new file mode 100644 index 0000000..c2db9ac --- /dev/null +++ b/src/components/layout/ResumeNavButton.tsx @@ -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 ( +
    + + + +
    + ) +} diff --git a/src/components/sections/DownloadResume.tsx b/src/components/sections/DownloadResume.tsx index 14dad07..54514b4 100644 --- a/src/components/sections/DownloadResume.tsx +++ b/src/components/sections/DownloadResume.tsx @@ -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(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 ( -
    -
    -
    -
    -
    -
    - -
    -
    -
    - {resumeLanguages.map(lang => ( - - {resumeLanguageLabels[lang]} - - ))} +
    +
    +
    +
    +
    +
    + +
    ) } diff --git a/src/components/sections/Hero.tsx b/src/components/sections/Hero.tsx index ca8d86b..9496e09 100644 --- a/src/components/sections/Hero.tsx +++ b/src/components/sections/Hero.tsx @@ -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 ( - - {strings.common.resumeDownload[currentLang]} ({resumeLanguageLabels[lang]}) - - ) -} - - export function Hero() { const {scrollY} = useScroll() const {lang} = useLanguage() @@ -103,19 +86,7 @@ export function Hero() { - {resumeAvailable && ( - <> -
    - -
    -
    - {resumeLanguages.map(lang => ( - - ))} -
    - - )} + diff --git a/src/components/ui/ResumeDialog.tsx b/src/components/ui/ResumeDialog.tsx new file mode 100644 index 0000000..d0eaa12 --- /dev/null +++ b/src/components/ui/ResumeDialog.tsx @@ -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 + 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 as the panel unmounts. + useEffect(() => { + if (!open) return + const frame = requestAnimationFrame(() => panelRef.current?.focus()) + return () => cancelAnimationFrame(frame) + }, [open, panelRef]) + + return ( + + {open && ( + + event.stopPropagation()} + > +
    +

    {strings.common.resumeModalTitle[lang]}

    + +
    +

    {strings.common.resumeModalHint[lang]}

    +
    + {resumeLanguages.map(optionLang => ( + + {resumeLanguageLabels[optionLang]} + {resumeUrlFor(optionLang)} + + ))} +
    +
    +
    + )} +
    + ) +} diff --git a/src/components/ui/icons.tsx b/src/components/ui/icons.tsx index 3bcf7c3..d806834 100644 --- a/src/components/ui/icons.tsx +++ b/src/components/ui/icons.tsx @@ -43,3 +43,15 @@ export function TelegramIcon({ size = 20 }: IconProps) { ) } + +// 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 ( + + ) +} diff --git a/src/hooks/useResumeDialog.ts b/src/hooks/useResumeDialog.ts new file mode 100644 index 0000000..e19d387 --- /dev/null +++ b/src/hooks/useResumeDialog.ts @@ -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(null) + const triggerRef = useRef(null) + const panelRef = useRef(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 } +} diff --git a/src/i18n/strings.ts b/src/i18n/strings.ts index edc2383..d9d9330 100644 --- a/src/i18n/strings.ts +++ b/src/i18n/strings.ts @@ -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'},