1
0
mirror of synced 2025-12-23 03:44:00 -05:00
Files
docs/components/page-header/ProductPicker.tsx
Grace Park baa53b778f Picker refactor (#33113)
Co-authored-by: Peter Bengtsson <peterbe@github.com>
2022-12-07 23:17:06 +00:00

43 lines
1.2 KiB
TypeScript

import { useRouter } from 'next/router'
import { LinkExternalIcon } from '@primer/octicons-react'
import { useMainContext } from 'components/context/MainContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { Picker } from 'components/ui/Picker'
export const ProductPicker = () => {
const router = useRouter()
const { activeProducts, currentProduct } = useMainContext()
const { t } = useTranslation('picker')
return (
<div data-testid="product-picker">
<Picker
variant="inline"
defaultText={t('product_picker_default_text')}
items={activeProducts.map((product) => ({
text: product.name,
selected: product.name === currentProduct?.name,
href: `${product.external ? '' : `/${router.locale}`}${product.href}`,
extra: {
external: product.external,
},
}))}
alignment="end"
dataTestId="field"
ariaLabel="Select field type"
renderItem={(item) => {
return item.extra?.external ? (
<>
{item.text}
<LinkExternalIcon size="small" className="ml-1" />
</>
) : (
item.text
)
}}
/>
</div>
)
}