-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from sitcon-tw/fix/sidebar-layout-broken
fix: apply postion sticky to sidebar
- Loading branch information
Showing
5 changed files
with
1,076 additions
and
998 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
app/cfp/(submission)/_components/table-of-content-mobile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"use client"; | ||
import Link from "next/link"; | ||
import { useState, useEffect } from "react"; | ||
import { AnimatePresence, motion } from "framer-motion"; | ||
import { useNavbar } from "@/app/cfp/_components/navbar-context"; | ||
|
||
export default function TableOfContentMobile({ | ||
theme = "light", | ||
sections = [], | ||
submitUrl, | ||
}: { | ||
theme: "red" | "light"; | ||
sections: { id: string; title: string }[]; | ||
submitUrl: string; | ||
}) { | ||
const [showDropdown, setShowDropdown] = useState(false); | ||
const { isNavbarExpanded } = useNavbar(); | ||
|
||
useEffect(() => { | ||
const observer = new IntersectionObserver((entries) => { | ||
for (const entry of entries) { | ||
if (entry.isIntersecting) { | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
for (const section of sections) { | ||
const targetElement = document.querySelector(`#${section.id}`); | ||
if (!targetElement) continue; | ||
observer.observe(targetElement); | ||
} | ||
}, [sections]); | ||
|
||
return ( | ||
<> | ||
<nav className="relative md:hidden"> | ||
<AnimatePresence> | ||
{!isNavbarExpanded && ( | ||
<motion.a | ||
key="submit" | ||
href={submitUrl} | ||
target="_blank" | ||
initial={{ scale: 0.95, opacity: 0, filter: "blur(0.5em)" }} | ||
animate={{ scale: 1, opacity: 1, filter: "blur(0)" }} | ||
exit={{ scale: 0.95, opacity: 0, filter: "blur(0.5em)" }} | ||
transition={{ duration: 0.25 }} | ||
whileTap={{ scale: 0.95 }} | ||
className={`fixed bottom-2 left-2 right-2 z-30 rounded-md bg-background-light p-3 text-center text-lg shadow-2xl shadow-black brightness-150`} | ||
> | ||
立刻投稿 | ||
</motion.a> | ||
)} | ||
</AnimatePresence> | ||
<div | ||
onClick={() => setShowDropdown((prev) => !prev)} | ||
className={`${theme === "light" ? "bg-background-light" : "bg-foreground"} flex h-[40px] items-center justify-between rounded-xl px-4 transition active:scale-95`} | ||
> | ||
<h2 | ||
className={`font-bold ${theme === "light" ? "text-foreground" : "text-red"}`} | ||
> | ||
本頁目錄 | ||
</h2> | ||
<span | ||
className={`material-symbols-outlined ${theme === "light" ? "text-foreground" : "text-red"} `} | ||
> | ||
{showDropdown ? "keyboard_arrow_up" : "keyboard_arrow_down"} | ||
</span> | ||
</div> | ||
{/* dropDown */} | ||
{showDropdown && ( | ||
<div | ||
className={`absolute top-[50px] z-10 w-full rounded-lg ${theme === "light" ? "bg-background-light" : "bg-background-light"} p-2 shadow-lg`} | ||
> | ||
{sections.map((section, index) => ( | ||
<motion.div | ||
key={section.id} | ||
initial={{ opacity: 0, y: -20, backgroundColor: "#D3C4B7" }} | ||
animate={{ opacity: 1, y: 0, backgroundColor: "#000000" }} | ||
transition={{ | ||
duration: 0.1, | ||
delay: index * 0.03, | ||
ease: "easeInOut", | ||
}} // 動畫時間 | ||
> | ||
<Link | ||
href={`#${section.id}`} | ||
className={`flex w-full justify-center border-b border-foreground/30 p-0 py-4 transition duration-300 ${theme === "light" ? "bg-background-light text-foreground" : "bg-background-light text-red"}`} | ||
onClick={() => setShowDropdown(false)} | ||
> | ||
<div className=" ">{section.title}</div> | ||
</Link> | ||
</motion.div> | ||
))} | ||
</div> | ||
)} | ||
</nav> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.