Preserve header state during page transitions

This commit is contained in:
Akira Tempaku 2025-05-03 15:11:31 +09:00
parent e09e544c31
commit 68264c4655
Signed by: paku
GPG key ID: 5B4E8402BCC50607

View file

@ -13,7 +13,11 @@
(defcomp ~pc-header () (defcomp ~pc-header ()
(hsx (hsx
(nav :class "hidden md:flex items-end" (header :class "hidden md:flex justify-between py-4 border-b-1 top-0 bg-white"
(h1 :class "z-20 text-3xl font-bold"
(a :href "/"
"skyizwhite")))
(nav :class "flex items-end"
(ul :preload "mouseover" :class "flex gap-4 text-xl font-medium" (ul :preload "mouseover" :class "flex gap-4 text-xl font-medium"
(loop (loop
:for (href label) :in *nav-menu* :collect :for (href label) :in *nav-menu* :collect
@ -25,53 +29,49 @@
(defcomp ~sp-header () (defcomp ~sp-header ()
(hsx (hsx
(div :class "block md:hidden" :x-data "{ open: false }" (header
(button :id "sp-header" :x-data "{ open: false }" :hx-preserve t
:class "z-20 size-8 flex flex-col justify-center cursor-pointer relative" :class "flex md:hidden justify-between py-2 border-b-1 top-0 bg-white"
:type "button" (h1 :class "z-20 text-2xl font-bold"
:@click "open = !open" (a :href "/" :@click "open = false"
(div :class "grid justify-items-center gap-1.5" "skyizwhite"))
(span (div
:class "h-1 w-8 rounded-full bg-black transition duration-400" (button
:|:class| "open && 'rotate-45 translate-y-2.5'") :class "z-20 size-8 flex flex-col justify-center cursor-pointer relative"
(span :type "button"
:class "h-1 w-8 rounded-full bg-black transition duration-400" :@click "open = !open"
:|:class| "open && 'scale-x-0'") (div :class "grid justify-items-center gap-1.5"
(span (span
:class "h-1 w-8 rounded-full bg-black transition duration-400" :class "h-1 w-8 rounded-full bg-black transition duration-400"
:|:class| "open && '-rotate-45 -translate-y-2.5'"))) :|:class| "open && 'rotate-45 translate-y-2.5'")
(nav (span
:class (<> :class "h-1 w-8 rounded-full bg-black transition duration-400"
"fixed flex flex-col items-center justify-center " :|:class| "open && 'scale-x-0'")
"z-10 top-0 right-0 w-full h-full gap-16 bg-gray-200") (span
:x-show "open" :class "h-1 w-8 rounded-full bg-black transition duration-400"
:|x-transition:enter| "transition ease-out duration-400" :|:class| "open && '-rotate-45 -translate-y-2.5'")))
:|x-transition:enter-start| "translate-x-full" (nav
:|x-transition:enter-end| "translate-x-0" :class (<>
:|x-transition:leave| "transition ease-in duration-400" "fixed flex flex-col items-center justify-center "
:|x-transition:leave-start| "translate-x-0" "z-10 top-0 right-0 w-full h-full gap-16 bg-gray-200")
:|x-transition:leave-end| "translate-x-full" :x-show "open"
(h2 :class "text-5xl font-bold" :|x-transition:enter| "transition ease-out duration-400"
"Menu") :|x-transition:enter-start| "translate-x-full"
(ul :|x-transition:enter-end| "translate-x-0"
:preload "mousedown" :|x-transition:leave| "transition ease-in duration-400"
:class "flex flex-col h-fit gap-8 text-3xl font-medium" :|x-transition:leave-start| "translate-x-0"
(loop :|x-transition:leave-end| "translate-x-full"
:for (href label) :in *nav-menu* :collect (h2 :class "text-5xl font-bold"
(if (search href (request-uri jingle:*request*)) "Menu")
(hsx (li :class "text-pink-500" (ul
label)) :preload "mousedown"
(hsx (li (a :class "flex flex-col h-fit gap-8 text-3xl font-medium"
:href href (loop
:class "hover:text-pink-500" :for (href label) :in (append '(("/" "home")) *nav-menu*) :collect
:@click "open = false" (hsx (li (a :href href :@click "open = false" label))))))))))
label))))))))))
(defcomp ~header () (defcomp ~header ()
(hsx (hsx
(header :class "flex justify-between py-2 md:py-4 border-b-1 top-0 bg-white" (<>
(h1 :class "z-20 text-2xl md:text-3xl font-bold"
(a :href "/"
"skyizwhite"))
(~pc-header) (~pc-header)
(~sp-header)))) (~sp-header))))