forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductPicker.tsx
49 lines (46 loc) · 1.82 KB
/
ProductPicker.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 { useRouter } from 'next/router'
import cx from 'classnames'
import { Link } from 'components/Link'
import { useMainContext } from 'components/context/MainContext'
import { ChevronDownIcon, LinkExternalIcon } from '@primer/octicons-react'
import { Details, useDetails } from '@primer/components'
export const ProductPicker = () => {
const router = useRouter()
const { activeProducts, currentProduct } = useMainContext()
const { getDetailsProps } = useDetails({})
return (
<Details {...getDetailsProps()} className="details-reset">
<summary className="color-text-link" role="button" aria-label="Toggle products list">
<div id="current-product" className="d-flex flex-items-center flex-justify-between py-2">
{/* <!-- Product switcher - GitHub.com, Enterprise Server, etc -->
<!-- 404 and 500 error layouts are not real pages so we need to hardcode the name for those --> */}
<span>{currentProduct?.name || 'All Products'}</span>
<ChevronDownIcon size={24} className="arrow ml-md-1" />
</div>
</summary>
<div id="homepages" style={{ zIndex: 6 }}>
{activeProducts.map((product) => {
return (
<Link
key={product.id}
href={`${product.external ? '' : `/${router.locale}`}${product.href}`}
className={cx(
'd-block py-2',
product.id === currentProduct?.id
? 'color-text-link text-underline active'
: 'Link--primary no-underline'
)}
>
{product.name}
{product.external && (
<span className="ml-1">
<LinkExternalIcon size="small" />
</span>
)}
</Link>
)
})}
</div>
</Details>
)
}