1
0
mirror of synced 2026-01-29 21:01:19 -05:00
Files
docs/components/landing/TableOfContents.tsx
Mike Surowiec e0d9a061a3 React category / sub-landing page (#19635)
Re-work routes to use GlobalPage, implements TocLanding, bundle of minor cleanup / fixes
2021-06-02 16:28:39 +00:00

45 lines
1.3 KiB
TypeScript

import { useRouter } from 'next/router'
import Link from 'next/link'
import cx from 'classnames'
import type { TocItem } from '../context/ProductLandingContext'
type Props = {
items: Array<TocItem>
variant?: 'compact' | 'expanded'
}
export const TableOfContents = (props: Props) => {
const { items, variant = 'expanded' } = props
const router = useRouter()
return (
<ul className={cx(variant === 'compact' ? 'list-style-inside pl-2' : 'list-style-none')}>
{(items || []).map((item) => {
if (!item) {
return null
}
const { fullPath: href, title, intro } = item
const isActive = router.pathname === href
return variant === 'compact' ? (
<li key={href} className="f4 my-1">
<Link href={href}>{title}</Link>
</li>
) : (
<li key={href} className={cx('mb-5', isActive && 'color-auto-gray-4')}>
<Link href={href}>
<a className="Bump-link--hover no-underline d-block py-1 border-bottom color-border-primary">
<h4>
{title}
<span className="Bump-link-symbol"></span>
</h4>
</a>
</Link>
{intro && <p className="f4 mt-3" dangerouslySetInnerHTML={{ __html: intro }} />}
</li>
)
})}
</ul>
)
}