1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/components/page-header/ProductPicker.tsx
Kevin Heis 329a8c664e Create a shared picker component (#22836)
* Unified picker component

* Add picker to storybook

* TS fixes

* Simplify "mobile" header spacing

* Fix a few testid

* Update Picker.tsx

* Update Picker.tsx

* Update Picker.tsx

* Fix unit test

* Fix rendering tests
2021-11-16 19:10:28 +00:00

35 lines
1015 B
TypeScript

import { useRouter } from 'next/router'
import { Link } from 'components/Link'
import { useMainContext } from 'components/context/MainContext'
import { LinkExternalIcon } from '@primer/octicons-react'
import { Picker } from 'components/ui/Picker'
export const ProductPicker = () => {
const router = useRouter()
const { activeProducts, currentProduct } = useMainContext()
return (
<Picker
variant="inline"
data-testid="product-picker"
data-current-product-path={currentProduct?.href}
defaultText="All products"
options={activeProducts.map((product) => ({
text: product.name,
selected: product === currentProduct,
item: (
<Link href={`${product.external ? '' : `/${router.locale}`}${product.href}`}>
{product.name}
{product.external && (
<span className="ml-1">
<LinkExternalIcon size="small" />
</span>
)}
</Link>
),
}))}
/>
)
}