({ navKeys, context, ...props })
| 41 | }); |
| 42 | |
| 43 | const 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 | |
| 79 | export default WithSidebar; |
nothing calls this directly
no test coverage detected