Skip to content

Commit 87309f4

Browse files
committed
made nested side nav better to use and make infinite nesting showcase example
1 parent cc98c39 commit 87309f4

File tree

6 files changed

+199
-102
lines changed

6 files changed

+199
-102
lines changed

library/src/components/sidenavigation/SideNavigation.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -464,7 +462,8 @@ function NestingItem({
464462
sideNavStoreIdent = "default",
465463
title,
466464
_isOpen,
467-
}: _NestingItemProps & { _isOpen?: boolean }) {
465+
id,
466+
}: _NestingItemProps & { _isOpen?: boolean; id?: string }) {
468467
const {
469468
getCurrentPathElement,
470469
pushPathElement,
@@ -498,6 +497,7 @@ function NestingItem({
498497
className="rounded-full p-1 box-border bg-neutral-full size-5.5 text-text-inverse"
499498
/>
500499
}
500+
id={id}
501501
>
502502
{title}
503503
</ButtonItem>
@@ -543,7 +543,7 @@ function NestableNavigationContent({
543543
className,
544544
style,
545545
}: _NestableNavigationContentProps) {
546-
const { popPathElement, getCurrentPathElement, setTransitioning } =
546+
const { popPathElement, getCurrentPathElement, setTransitioning, path } =
547547
useSideNavigationStore(sideNavStoreIdent)
548548

549549
const currentOpenedTitle = getCurrentPathElement()
@@ -552,6 +552,8 @@ function NestableNavigationContent({
552552
? searchChild(children, currentOpenedTitle)
553553
: null
554554

555+
console.log("currentOpenedTitle", currentOpenedTitle, path, renderChild)
556+
555557
const [isBack, setIsBack] = useState(false)
556558

557559
return (
@@ -561,7 +563,7 @@ function NestableNavigationContent({
561563
>
562564
<AnimatePresence initial={false} mode="popLayout">
563565
{/* root level elements */}
564-
{!renderChild && (
566+
{!currentOpenedTitle && (
565567
<motion.div
566568
key="outside"
567569
//layout
@@ -580,7 +582,7 @@ function NestableNavigationContent({
580582
)}
581583
</AnimatePresence>
582584
<AnimatePresence initial={false} mode="popLayout">
583-
{renderChild && (
585+
{currentOpenedTitle && (
584586
<motion.div
585587
key="go-back-btn"
586588
initial={{ x: "100%" }}

library/src/components/sidenavigation/SideNavigationStore.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ export function useSideNavigationStore(sideNavStoreIdent: string) {
1717
}
1818

1919
const path = useSnapshot(store[sideNavStoreIdent])
20-
console.info(
21-
"SideNavigationStore -",
22-
sideNavStoreIdent,
23-
path.path.map((e) => e),
24-
)
25-
2620
const setPath = useCallback(
2721
(path: string[]) =>
2822
store[sideNavStoreIdent].path.splice(0, path.length, ...path),

0 commit comments

Comments
 (0)