1
0
mirror of synced 2025-12-22 19:34:15 -05:00
Files
docs/components/Breadcrumbs.tsx
Mike Surowiec e26a3446a7 SubLanding page filter (#19918)
* sub-landing: implement filtering in react, other cleanup
2021-06-15 18:16:24 +00:00

50 lines
1.3 KiB
TypeScript

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>
)
}