Refactor layout and navigation components to remove unused motion props (#494)

- Replaced motion.header with a standard header in Layout component.
- Removed layout props from motion elements in NavigationAPI and NavigationDocs components for improved performance and clarity.
- Updated AnnouncementBannerProvider to make the banner always visible, removing scroll-based hiding logic.
This commit is contained in:
Brandon Hopkins
2025-11-25 11:03:25 -08:00
committed by GitHub
parent fb4b060710
commit cc0b4cd01b
4 changed files with 25 additions and 25 deletions

View File

@@ -178,8 +178,8 @@ export function Layout({ children, title, tableOfContents }) {
className="relative mx-auto flex max-w-8xl sm:px-2 lg:px-8 xl:px-12 lg:ml-72 xl:ml-80" className="relative mx-auto flex max-w-8xl sm:px-2 lg:px-8 xl:px-12 lg:ml-72 xl:ml-80"
style={{ paddingTop: bannerHeight }} style={{ paddingTop: bannerHeight }}
> >
<motion.header <header
layoutScroll // layoutScroll
className="contents lg:pointer-events-none lg:fixed lg:inset-0 lg:z-40 lg:flex" className="contents lg:pointer-events-none lg:fixed lg:inset-0 lg:z-40 lg:flex"
style={{ top: bannerHeight }} style={{ top: bannerHeight }}
> >
@@ -192,7 +192,7 @@ export function Layout({ children, title, tableOfContents }) {
<Header /> <Header />
{router.route.startsWith("/ipa") ? <NavigationAPI className="hidden lg:mt-10 lg:block" tableOfContents={tableOfContents} /> : <NavigationDocs className="hidden lg:mt-10 lg:block" />} {router.route.startsWith("/ipa") ? <NavigationAPI className="hidden lg:mt-10 lg:block" tableOfContents={tableOfContents} /> : <NavigationDocs className="hidden lg:mt-10 lg:block" />}
</div> </div>
</motion.header> </header>
<div className="min-w-0 max-w-2xl flex-auto px-4 py-16 lg:max-w-none lg:pl-8 lg:pr-0 xl:px-5"> <div className="min-w-0 max-w-2xl flex-auto px-4 py-16 lg:max-w-none lg:pl-8 lg:pr-0 xl:px-5">
<main className="py-16"> <main className="py-16">
<Prose as="article">{children}</Prose> <Prose as="article">{children}</Prose>

View File

@@ -110,7 +110,7 @@ export function NavLink({ href, tag, active, isAnchorLink = false, children, lin
{links && {links &&
<ul role="list"> <ul role="list">
{links.map((link,index) => ( {links.map((link,index) => (
<motion.li key={index} layout="position" className="relative"> <motion.li key={index} className="relative">
<NavLink href={link.href} active={link.href === router.pathname} isChildren={true}> <NavLink href={link.href} active={link.href === router.pathname} isChildren={true}>
{link.title} {link.title}
</NavLink> </NavLink>
@@ -146,7 +146,7 @@ export function VisibleSectionHighlight() {
return activeIndex >= 0 && ( return activeIndex >= 0 && (
<motion.div <motion.div
layout // layout
initial={{ opacity: 0 }} initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { delay: 0.2 } }} animate={{ opacity: 1, transition: { delay: 0.2 } }}
exit={{ opacity: 0 }} exit={{ opacity: 0 }}
@@ -169,7 +169,7 @@ export function ActivePageMarker() {
return activeIndex >= 0 && ( return activeIndex >= 0 && (
<motion.div <motion.div
layout // layout
className="absolute left-2 h-6 w-px bg-orange-500" className="absolute left-2 h-6 w-px bg-orange-500"
initial={{ opacity: 0 }} initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { delay: 0.2 } }} animate={{ opacity: 1, transition: { delay: 0.2 } }}
@@ -187,7 +187,7 @@ function NavigationGroup({ group, className, tableOfContents }) {
return ( return (
<li className={clsx('relative mt-6', className)}> <li className={clsx('relative mt-6', className)}>
<motion.h2 <motion.h2
layout="position" // layout="position"
data-nb-link={group.title} data-nb-link={group.title}
className="text-xs font-semibold text-zinc-900 dark:text-white" className="text-xs font-semibold text-zinc-900 dark:text-white"
> >
@@ -200,7 +200,7 @@ function NavigationGroup({ group, className, tableOfContents }) {
)} )}
</AnimatePresence> </AnimatePresence>
<motion.div <motion.div
layout // layout
className="absolute inset-y-0 left-2 w-px bg-zinc-900/10 dark:bg-white/5" className="absolute inset-y-0 left-2 w-px bg-zinc-900/10 dark:bg-white/5"
/> />
<AnimatePresence initial={false}> <AnimatePresence initial={false}>
@@ -210,7 +210,7 @@ function NavigationGroup({ group, className, tableOfContents }) {
</AnimatePresence> </AnimatePresence>
<ul role="list" className="border-l border-transparent"> <ul role="list" className="border-l border-transparent">
{group.links.map((link) => ( {group.links.map((link) => (
<motion.li key={link.href} layout="position" className="relative"> <motion.li key={link.href} className="relative">
<NavLink href={link.href} active={link.href === router.pathname.replace("ipa", "api")}> <NavLink href={link.href} active={link.href === router.pathname.replace("ipa", "api")}>
{link.title} {link.title}
</NavLink> </NavLink>

View File

@@ -371,7 +371,7 @@ export const docsNavigation = [
return ( return (
<li className={clsx('relative', className, hasChildren ? "" : "mt-6")}> <li className={clsx('relative', className, hasChildren ? "" : "mt-6")}>
<motion.h2 <motion.h2
layout={"size"} // layout={"size"}
className={clsx( className={clsx(
"flex justify-between items-center gap-2 group", "flex justify-between items-center gap-2 group",
hasChildren ? "text-zinc-700 select-none py-1 pr-3 hover:text-zinc-900 dark:text-zinc-300 font-medium dark:hover:text-white text-sm cursor-pointer" : "text-xs font-semibold text-zinc-900 dark:text-white" hasChildren ? "text-zinc-700 select-none py-1 pr-3 hover:text-zinc-900 dark:text-zinc-300 font-medium dark:hover:text-white text-sm cursor-pointer" : "text-xs font-semibold text-zinc-900 dark:text-white"
@@ -400,7 +400,7 @@ export const docsNavigation = [
)} )}
</AnimatePresence> </AnimatePresence>
<motion.div <motion.div
layout // layout
className="absolute inset-y-0 left-2 w-px bg-zinc-900/10 dark:bg-white/5" className="absolute inset-y-0 left-2 w-px bg-zinc-900/10 dark:bg-white/5"
/> />
<AnimatePresence initial={false}> <AnimatePresence initial={false}>
@@ -427,7 +427,7 @@ export const docsNavigation = [
className="border-l border-transparent"> className="border-l border-transparent">
{group.links.map((link) => { {group.links.map((link) => {
return link.href ? return link.href ?
<motion.li key={link.href} layout={"position"} className="relative"> <motion.li key={link.href} className="relative">
<NavLink href={link.href} active={link.href === router.pathname} links={link.links}> <NavLink href={link.href} active={link.href === router.pathname} links={link.links}>
{link.title} {link.title}
</NavLink> </NavLink>

View File

@@ -35,7 +35,6 @@ export function AnnouncementBannerProvider({ children }) {
undefined undefined
) )
let announcementId = announcement.text let announcementId = announcement.text
let [isHiddenByScroll, setIsHiddenByScroll] = useState(false)
let [bannerHeight, setBannerHeight] = useState(0) let [bannerHeight, setBannerHeight] = useState(0)
let close = () => { let close = () => {
@@ -48,7 +47,7 @@ export function AnnouncementBannerProvider({ children }) {
return closedAnnouncement !== announcementId return closedAnnouncement !== announcementId
}, [announcementId, closedAnnouncement, mounted]) }, [announcementId, closedAnnouncement, mounted])
let isVisible = isActive && !isHiddenByScroll let isVisible = isActive // Always visible when active, regardless of scroll
let reportHeight = useCallback((height) => { let reportHeight = useCallback((height) => {
setBannerHeight(height) setBannerHeight(height)
@@ -59,19 +58,20 @@ export function AnnouncementBannerProvider({ children }) {
return () => setMounted(false) return () => setMounted(false)
}, []) }, [])
useEffect(() => { // Removed scroll-based hiding to make banner always sticky
if (typeof window === 'undefined') { // useEffect(() => {
return // if (typeof window === 'undefined') {
} // return
// }
function handleScroll() { // function handleScroll() {
setIsHiddenByScroll(window.scrollY > 30) // setIsHiddenByScroll(window.scrollY > 30)
} // }
handleScroll() // handleScroll()
window.addEventListener('scroll', handleScroll, { passive: true }) // window.addEventListener('scroll', handleScroll, { passive: true })
return () => window.removeEventListener('scroll', handleScroll) // return () => window.removeEventListener('scroll', handleScroll)
}, []) // }, [])
useEffect(() => { useEffect(() => {
if (!isVisible && bannerHeight !== 0) { if (!isVisible && bannerHeight !== 0) {