forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSidebarHomepage.tsx
55 lines (51 loc) · 1.88 KB
/
SidebarHomepage.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
50
51
52
53
54
55
import { useRouter } from 'next/router'
import { LinkExternalIcon } from '@primer/octicons-react'
import { ActionList } from '@primer/react'
import { useVersion } from 'components/hooks/useVersion'
import { useMainContext } from 'components/context/MainContext'
import { Link } from 'components/Link'
export const SidebarHomepage = () => {
const router = useRouter()
const { currentVersion } = useVersion()
const { activeProducts, isFPT } = useMainContext()
return (
<ul data-testid="sidebar" className="mt-4">
<li>
<ActionList variant="full">
{activeProducts
.filter(
(product) => isFPT || product.versions?.includes(currentVersion) || product.external
)
.map((product) => {
const href = `${!product.external ? `/${router.locale}` : ''}${
product.versions?.includes(currentVersion) && !isFPT
? `/${currentVersion}/${product.id}`
: product.href
}`
return (
<ActionList.Item
key={product.id}
title={`${product.name}${product.external ? '(External Site)' : ''}`}
className="width-full my-2"
sx={{ padding: 0 }}
>
<Link
href={href}
target={product.external ? '_blank' : undefined}
className="d-block 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>
)
})}
</ActionList>
</li>
</ul>
)
}