@@ -47,7 +47,7 @@ function Container({
4747 return (
4848 < nav
4949 className = { twMerge (
50- "bg-surface text-text-subtle relative flex size-full flex-col overflow-hidden truncate py-4 " ,
50+ "bg-surface text-text-subtle relative flex size-full flex-col overflow-hidden truncate" ,
5151 className ,
5252 ) }
5353 role = { role }
@@ -66,12 +66,10 @@ function Content({
6666 children,
6767 className,
6868 style,
69- storeIdent = "side-nav-store" ,
7069} : {
7170 children : React . ReactNode
7271 className ?: string
7372 style ?: React . CSSProperties
74- storeIdent ?: string
7573} ) {
7674 const ref = useRef < HTMLDivElement > ( null )
7775
@@ -455,6 +453,7 @@ type _NestingItemProps = {
455453 style ?: React . CSSProperties
456454 title : string // title is used to identify the item and as a key
457455 sideNavStoreIdent ?: string
456+ id : string
458457}
459458
460459function NestingItem ( {
@@ -464,6 +463,7 @@ function NestingItem({
464463 sideNavStoreIdent = "default" ,
465464 title,
466465 _isOpen,
466+ id,
467467} : _NestingItemProps & { _isOpen ?: boolean } ) {
468468 const {
469469 getCurrentPathElement,
@@ -488,7 +488,7 @@ function NestingItem({
488488 return (
489489 < ButtonItem
490490 onClick = { ( ) => {
491- pushPathElement ( title )
491+ pushPathElement ( id )
492492 setTransitioning ( true )
493493 window . setTimeout ( ( ) => setTransitioning ( null ) , animTime * 1000 )
494494 } }
@@ -498,6 +498,7 @@ function NestingItem({
498498 className = "rounded-full p-1 box-border bg-neutral-full size-5.5 text-text-inverse"
499499 />
500500 }
501+ id = { id }
501502 >
502503 { title }
503504 </ ButtonItem >
@@ -510,24 +511,26 @@ type _NestableNavigationContentProps = {
510511 className ?: string
511512 style ?: React . CSSProperties
512513 sideNavStoreIdent ?: string
514+ onAnimationStart ?: ( ) => void
515+ onAnimationComplete ?: ( ) => void
513516}
514517
515518function searchChild (
516519 children : React . ReactNode ,
517- currentOpenedTitle : string | undefined ,
520+ currentOpenedId : string | undefined ,
518521) {
519522 let renderChild : React . ReactElement < _NestingItemProps > | null = null
520523 React . Children . forEach ( children , ( child ) => {
521524 if ( renderChild ) return
522525 if (
523526 React . isValidElement < _NestingItemProps > ( child ) &&
524- child . props . title === currentOpenedTitle
527+ child . props . id === currentOpenedId
525528 ) {
526529 renderChild = child
527530 return
528531 }
529532 if ( React . isValidElement ( child ) ) {
530- const ret = searchChild ( child . props . children , currentOpenedTitle )
533+ const ret = searchChild ( child . props . children , currentOpenedId )
531534 if ( ret ) renderChild = ret
532535 }
533536 } )
@@ -542,14 +545,16 @@ function NestableNavigationContent({
542545 sideNavStoreIdent = "default" ,
543546 className,
544547 style,
548+ onAnimationStart,
549+ onAnimationComplete,
545550} : _NestableNavigationContentProps ) {
546- const { popPathElement, getCurrentPathElement, setTransitioning } =
551+ const { popPathElement, getCurrentPathElement, setTransitioning, path } =
547552 useSideNavigationStore ( sideNavStoreIdent )
548553
549- const currentOpenedTitle = getCurrentPathElement ( )
554+ const currentOpenedId = getCurrentPathElement ( )
550555
551- const renderChild = currentOpenedTitle
552- ? searchChild ( children , currentOpenedTitle )
556+ const renderChild = currentOpenedId
557+ ? searchChild ( children , currentOpenedId )
553558 : null
554559
555560 const [ isBack , setIsBack ] = useState ( false )
@@ -561,7 +566,7 @@ function NestableNavigationContent({
561566 >
562567 < AnimatePresence initial = { false } mode = "popLayout" >
563568 { /* root level elements */ }
564- { ! renderChild && (
569+ { ! currentOpenedId && (
565570 < motion . div
566571 key = "outside"
567572 //layout
@@ -574,13 +579,19 @@ function NestableNavigationContent({
574579 duration : animTime ,
575580 ease : "easeInOut" ,
576581 } }
582+ onAnimationStart = { ( ) => {
583+ onAnimationStart ?.( )
584+ } }
585+ onAnimationComplete = { ( ) => {
586+ onAnimationComplete ?.( )
587+ } }
577588 >
578589 { children }
579590 </ motion . div >
580591 ) }
581592 </ AnimatePresence >
582593 < AnimatePresence initial = { false } mode = "popLayout" >
583- { renderChild && (
594+ { currentOpenedId && (
584595 < motion . div
585596 key = "go-back-btn"
586597 initial = { { x : "100%" } }
@@ -615,12 +626,14 @@ function NestableNavigationContent({
615626 < AnimatePresence
616627 initial = { false }
617628 mode = "popLayout"
618- onExitComplete = { ( ) => setIsBack ( false ) }
629+ onExitComplete = { ( ) => {
630+ setIsBack ( false )
631+ } }
619632 >
620633 { /* followed by the lower level elements */ }
621- { renderChild && (
634+ { renderChild != null && (
622635 < motion . div
623- key = { `inside-${ currentOpenedTitle } ` }
636+ key = { `inside-${ currentOpenedId } ` }
624637 initial = { {
625638 x : isBack ? "-100%" : "100%" ,
626639 } }
@@ -635,7 +648,13 @@ function NestableNavigationContent({
635648 ease : "easeInOut" ,
636649 //delay: animTime * 0.5,
637650 } }
638- className = "border-b-border-separator border-t-border-separator box-border flex size-full border-b-2 border-t-2 border-solid py-2"
651+ className = "border-b-border-separator border-t-border-separator box-border flex size-full border-b-2 border-t-2 border-solid"
652+ onAnimationStart = { ( ) => {
653+ onAnimationStart ?.( )
654+ } }
655+ onAnimationComplete = { ( ) => {
656+ onAnimationComplete ?.( )
657+ } }
639658 >
640659 { React . cloneElement ( renderChild , { _isOpen : true } ) }
641660 </ motion . div >
0 commit comments