@@ -5,6 +5,7 @@ import { motion } from 'framer-motion';
55import React from 'react' ;
66
77import { type ClassValue , tcls } from '@/lib/tailwind' ;
8+ import { findSectionInGroup } from '@/lib/utils' ;
89import { useToggleAnimation } from '../hooks' ;
910import { Link } from '../primitives' ;
1011import { ScrollContainer } from '../primitives/ScrollContainer' ;
@@ -15,7 +16,7 @@ import type {
1516 ClientSiteSections ,
1617} from './encodeClientSiteSections' ;
1718
18- const MAX_ITEMS = 5 ; // If there are more sections than this, they'll be shown below the fold in a scrollview.
19+ const MAX_ITEMS = 6 ; // If there are more sections than this, they'll be shown below the fold in a scrollview.
1920
2021/**
2122 * A list of items representing site sections for multi-section sites
@@ -72,8 +73,9 @@ export function SiteSectionListItem(props: {
7273 section : ClientSiteSection ;
7374 isActive : boolean ;
7475 className ?: string ;
76+ style ?: React . CSSProperties ;
7577} ) {
76- const { section, isActive, className, ...otherProps } = props ;
78+ const { section, isActive, className, style , ...otherProps } = props ;
7779
7880 return (
7981 < Link
@@ -101,6 +103,7 @@ export function SiteSectionListItem(props: {
101103 : null ,
102104 className
103105 ) }
106+ style = { style }
104107 { ...otherProps }
105108 >
106109 < div
@@ -127,11 +130,12 @@ export function SiteSectionListItem(props: {
127130export function SiteSectionGroupItem ( props : {
128131 group : ClientSiteSectionGroup ;
129132 currentSection : ClientSiteSection ;
133+ level ?: number ;
130134} ) {
131- const { group, currentSection } = props ;
135+ const { group, currentSection, level = 0 } = props ;
132136
133- const hasDescendants = group . sections . length > 0 ;
134- const isActiveGroup = group . sections . some ( ( section ) => section . id === currentSection . id ) ;
137+ const hasDescendants = group . children . length > 0 ;
138+ const isActiveGroup = Boolean ( findSectionInGroup ( group , currentSection . id ) ) ;
135139 const shouldOpen = hasDescendants && isActiveGroup ;
136140 const [ isOpen , setIsOpen ] = React . useState ( shouldOpen ) ;
137141
@@ -161,7 +165,7 @@ export function SiteSectionGroupItem(props: {
161165 className = { tcls (
162166 'flex size-8 shrink-0 items-center justify-center rounded-md straight-corners:rounded-none bg-tint-subtle text-lg text-tint leading-none shadow-tint shadow-xs ring-1 ring-tint-subtle transition-transform group-hover/section-link:scale-110 group-hover/section-link:ring-tint-hover group-active/section-link:scale-90 group-active/section-link:shadow-none contrast-more:text-tint-strong dark:shadow-none' ,
163167 isActiveGroup
164- ? 'bg-primary tint:bg-primary-solid text-primary tint:text-contrast-primary-solid shadow-md shadow-primary ring-primary group-hover/section-link:ring-primary-hover, contrast-more:text-primary-strong contrast-more:ring-2 contrast-more:ring-primary'
168+ ? 'bg-primary text-primary shadow-md shadow-primary ring-primary group-hover/section-link:ring-primary-hover, contrast-more:text-primary-strong contrast-more:ring-2 contrast-more:ring-primary'
165169 : null
166170 ) }
167171 >
@@ -216,14 +220,26 @@ export function SiteSectionGroupItem(props: {
216220 </ button >
217221 { hasDescendants ? (
218222 < Descendants isVisible = { isOpen } >
219- { group . sections . map ( ( section ) => (
220- < SiteSectionListItem
221- section = { section }
222- isActive = { section . id === currentSection . id }
223- key = { section . id }
224- className = "pl-5"
225- />
226- ) ) }
223+ { group . children . map ( ( child ) => {
224+ if ( child . object === 'site-section' ) {
225+ return (
226+ < SiteSectionListItem
227+ section = { child }
228+ isActive = { child . id === currentSection . id }
229+ key = { child . id }
230+ />
231+ ) ;
232+ }
233+
234+ return (
235+ < SiteSectionGroupItem
236+ group = { child }
237+ currentSection = { currentSection }
238+ key = { child . id }
239+ level = { level + 1 }
240+ />
241+ ) ;
242+ } ) }
227243 </ Descendants >
228244 ) : null }
229245 </ >
@@ -239,7 +255,7 @@ function Descendants(props: {
239255 return (
240256 < motion . div
241257 ref = { scope }
242- className = { isVisible ? undefined : '[&_ul>li]:opacity-1' }
258+ className = { isVisible ? 'pl-3' : 'pl-3 [&_ul>li]:opacity-1' }
243259 initial = { isVisible ? show : hide }
244260 >
245261 { children }
0 commit comments