forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreadcrumbs.tsx
49 lines (45 loc) · 1.32 KB
/
Breadcrumbs.tsx
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
import cx from 'classnames'
import { useRouter } from 'next/router'
import { useMainContext } from './context/MainContext'
import { Link } from 'components/Link'
export type BreadcrumbT = {
title: string
documentType?: string
href?: string
}
type Props = {
variant?: 'default' | 'large'
}
export const Breadcrumbs = ({ variant = 'default' }: Props) => {
const router = useRouter()
const pathWithLocale = `/${router.locale}${router.asPath.split('?')[0]}` // remove query string
const { breadcrumbs } = useMainContext()
return (
<nav className="breadcrumbs f5" aria-label="Breadcrumb">
{Object.values(breadcrumbs).map((breadcrumb) => {
if (!breadcrumb) {
return null
}
const title = `${breadcrumb.documentType}: ${breadcrumb.title}`
return !breadcrumb.href ? (
<span key={title} title={title}>
{breadcrumb.title}
</span>
) : (
<Link
key={title}
href={breadcrumb.href}
title={title}
className={cx(
'd-inline-block',
variant === 'large' && 'text-uppercase text-mono',
pathWithLocale === breadcrumb.href && 'color-text-tertiary'
)}
>
{breadcrumb.title}
</Link>
)
})}
</nav>
)
}