-
Notifications
You must be signed in to change notification settings - Fork 68k
Expand file tree
/
Copy pathDocsSecondaryBar.tsx
More file actions
69 lines (63 loc) · 3.11 KB
/
Copy pathDocsSecondaryBar.tsx
File metadata and controls
69 lines (63 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import cx from 'classnames'
import { useRouter } from 'next/router'
import { IconButton } from '@primer/react'
import { SidebarCollapseIcon, SidebarExpandIcon } from '@primer/octicons-react'
import { useMainContext } from '@/frame/components/context/MainContext'
import { useTranslation } from '@/languages/components/useTranslation'
import { useSidebarCollapsed } from '@/frame/components/sidebar/SidebarCollapseContext'
import { BreadcrumbsScroller } from './BreadcrumbsScroller'
import styles from './DocsSecondaryBar.module.scss'
// The Docs 2026 secondary bar: sits below the main header, above the doc-tree
// rail + article content. Holds the nav trigger and the breadcrumb trail. The
// same sidebar collapse/expand icon is used on both desktop (collapses the rail)
// and mobile (expands the nav inline).
export const DocsSecondaryBar = () => {
const router = useRouter()
const { isHomepageVersion, currentProduct } = useMainContext()
const { t } = useTranslation('header')
const { collapsed, toggleCollapsed, mobileNavOpen, toggleMobileNav } = useSidebarCollapsed()
const isSearchResultsPage = router.route === '/search'
const isEarlyAccessPage = currentProduct && currentProduct.id === 'early-access'
// Mirror the visibility rule of the header subnav this replaces.
if (isHomepageVersion || isSearchResultsPage) {
return null
}
return (
<div data-container="secondary-nav" data-testid="docs-secondary-bar" className={styles.bar}>
<div className={cx(styles.leftSegment, collapsed && styles.leftSegmentExpanded)}>
{!isEarlyAccessPage && (
<div className={styles.toggleCell}>
{/* Desktop: collapse/expand the whole rail. */}
<IconButton
data-testid="sidebar-collapse-toggle"
className={cx(styles.desktopOnly, 'color-fg-muted')}
variant="invisible"
size="small"
icon={collapsed ? SidebarCollapseIcon : SidebarExpandIcon}
aria-label={collapsed ? t('expand_sidebar') : t('collapse_sidebar')}
aria-expanded={!collapsed}
onClick={toggleCollapsed}
/>
{/* Mobile: expand/collapse the inline nav, using the same icon. */}
<IconButton
data-testid="sidebar-mobile-toggle"
className={cx(styles.mobileOnly, 'color-fg-muted')}
variant="invisible"
size="small"
icon={mobileNavOpen ? SidebarExpandIcon : SidebarCollapseIcon}
aria-label={mobileNavOpen ? t('collapse_sidebar') : t('expand_sidebar')}
aria-expanded={mobileNavOpen}
onClick={toggleMobileNav}
/>
</div>
)}
{/* Remount per route so the scroller re-anchors to the new trail's end.
Its anchor effect only fires on mount + outer-width change; a
client-side nav to a longer trail grows the inner scroll width
without changing the outer width, so without this the stale
scrollLeft would leave the new current page off-screen. */}
<BreadcrumbsScroller key={router.asPath} />
</div>
</div>
)
}