MCPcopy Create free account
hub / github.com/github/docs / SidebarNav

Function SidebarNav

components/sidebar/SidebarNav.tsx:14–63  ·  view source on GitHub ↗
({ variant = 'full' }: Props)

Source from the content-addressed store, hash-verified

12}
13
14export const SidebarNav = ({ variant = 'full' }: Props) => {
15 const { error, currentProduct, currentProductTree } = useMainContext()
16 const isRestPage = currentProduct && currentProduct.id === 'rest'
17 const productTitle = currentProductTree?.shortTitle || currentProductTree?.title
18 // we need to roughly account for the site header height plus the height of
19 // the side nav header (which is taller when we show the API version picker)
20 // so we don't cut off the bottom of the sidebar
21 const sidebarPaddingBottom = isRestPage ? '250px' : '185px'
22
23 return (
24 <div
25 className={cx(variant === 'full' ? 'position-sticky d-none border-right d-xl-block' : '')}
26 style={{ width: 326, height: 'calc(100vh - 65px)', top: '65px' }}
27 >
28 {variant === 'full' && currentProductTree && (
29 <div className={cx('d-none px-4 pb-3 border-bottom d-xl-block')}>
30 <AllProductsLink />
31 {currentProduct && (
32 <div className="mt-3">
33 <Link
34 data-testid="sidebar-product-xl"
35 href={currentProductTree.href}
36 className="d-block pl-1 mb-2 h3 color-fg-default no-underline"
37 >
38 {productTitle}
39 </Link>
40 </div>
41 )}
42 {variant === 'full' && isRestPage && <ApiVersionPicker />}
43 </div>
44 )}
45 <div
46 className={cx(
47 variant === 'overlay' ? 'd-xl-none' : 'border-right d-none d-xl-block',
48 'bg-primary overflow-y-auto flex-shrink-0'
49 )}
50 style={{ width: 326, height: '100vh', paddingBottom: sidebarPaddingBottom }}
51 role="banner"
52 >
53 <nav>
54 {error === '404' || !currentProduct || currentProduct.id === 'search' ? (
55 <SidebarHomepage />
56 ) : (
57 <SidebarProduct />
58 )}
59 </nav>
60 </div>
61 </div>
62 )
63}

Callers

nothing calls this directly

Calls 1

useMainContextFunction · 0.90

Tested by

no test coverage detected