* Match label with selection * defaultText is a better default Co-authored-by: Peter Bengtsson <peterbe@github.com> * No longer used * Also no longer used * No longer used in the dropdown pickers * Add translation strings for pickers * Use translated strings in picker components Co-authored-by: Peter Bengtsson <peterbe@github.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
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'
|
|
import { useTranslation } from 'components/hooks/useTranslation'
|
|
|
|
export const ProductPicker = () => {
|
|
const router = useRouter()
|
|
const { activeProducts, currentProduct } = useMainContext()
|
|
const { t } = useTranslation('picker')
|
|
|
|
return (
|
|
<Picker
|
|
variant="inline"
|
|
data-testid="product-picker"
|
|
data-current-product-path={currentProduct?.href}
|
|
defaultText={t('product_picker_default_text')}
|
|
options={activeProducts.map((product) => ({
|
|
text: product.name,
|
|
selected: product.name === currentProduct?.name,
|
|
item: (
|
|
<Link href={`${product.external ? '' : `/${router.locale}`}${product.href}`}>
|
|
{product.name}
|
|
{product.external && (
|
|
<span className="ml-1">
|
|
<LinkExternalIcon size="small" />
|
|
</span>
|
|
)}
|
|
</Link>
|
|
),
|
|
}))}
|
|
/>
|
|
)
|
|
}
|