1
0
mirror of synced 2025-12-22 19:34:15 -05:00
Files
docs/components/sidebar/SidebarHomepage.tsx
Robert Sese 74c94121be Use Primer ActionList for sidebar (#22885)
* Initial move to ActionLists nav, handle terminal links

* ActionList-ify map topic items

* Some 🎨

* ActionList-ify homepage sidebar

* More 🎨

* Resolve test failures (and 'better' markup?)

* Properties don't exist on ActionList

* Use ul + li elements for ActionLists

* Workaround for TS error with 'as='

Co-authored-by: Octomerger Bot <63058869+Octomerger@users.noreply.github.com>
2021-11-23 18:33:54 +00:00

65 lines
1.8 KiB
TypeScript

import { useRouter } from 'next/router'
import { LinkExternalIcon } from '@primer/octicons-react'
import { ActionList } from '@primer/components'
import { useVersion } from 'components/hooks/useVersion'
import { useMainContext } from 'components/context/MainContext'
import { Link } from 'components/Link'
import { AllProductsLink } from './AllProductsLink'
export const SidebarHomepage = () => {
const router = useRouter()
const { currentVersion } = useVersion()
const { activeProducts, isFPT } = useMainContext()
const navItems = []
for (let i = 0; i < activeProducts.length; i++) {
const product = activeProducts[i]
if (!isFPT && !product.versions?.includes(currentVersion) && !product.external) {
continue
}
const href = `${!product.external ? `/${router.locale}` : ''}${
product.versions?.includes(currentVersion) && !isFPT
? `/${currentVersion}/${product.id}`
: product.href
}`
navItems.push({
renderItem: () => (
<ActionList.Item
as="li"
key={product.id}
title={`${product.name}${product.external ? '(External Site)' : ''}`}
className="my-2"
sx={{ padding: 0 }}
>
<Link
href={href}
target={product.external ? '_blank' : undefined}
className="f4 pl-4 pr-5 py-2 color-fg-default no-underline width-full"
>
{product.name}
{product.external && (
<span className="ml-1">
<LinkExternalIcon size="small" />
</span>
)}
</Link>
</ActionList.Item>
),
})
}
return (
<ul data-testid="sidebar" className="mt-4">
{!isFPT && <AllProductsLink />}
<li>
<ActionList {...{ as: 'ul' }} items={navItems}></ActionList>
</li>
</ul>
)
}