MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / WithSidebar

Function WithSidebar

apps/site/components/withSidebar.tsx:43–77  ·  view source on GitHub ↗
({ navKeys, context, ...props })

Source from the content-addressed store, hash-verified

41});
42
43const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
44 const { getSideNavigation } = useSiteNavigation();
45 const pathname = usePathname()!;
46 const t = useTranslations();
47 const { push } = useRouter();
48 const { frontmatter } = useClientContext();
49 const sidebarRef = useRef<HTMLElement>(null);
50 const sideNavigation = getSideNavigation(navKeys, context);
51
52 // Preserve sidebar scroll position across navigations
53 useScrollToElement('sidebar', sidebarRef);
54
55 const mappedSidebarItems =
56 // If there's only a single navigation key, use its sub-items
57 // as our navigation.
58 (navKeys.length === 1 ? sideNavigation[0][1].items : sideNavigation).map(
59 ([, { label, items }]: [string, MappedItem]) => ({
60 groupName: label,
61 items: items ? items.map(mapItem) : [],
62 })
63 );
64
65 return (
66 <Sidebar
67 ref={sidebarRef}
68 groups={mappedSidebarItems}
69 pathname={pathname}
70 title={t('components.common.sidebar.title')}
71 placeholder={frontmatter?.title}
72 onSelect={push}
73 as={Link}
74 {...props}
75 />
76 );
77};
78
79export default WithSidebar;

Callers

nothing calls this directly

Calls 3

useSiteNavigationFunction · 0.85
getSideNavigationFunction · 0.85
useScrollToElementFunction · 0.85

Tested by

no test coverage detected