* close Language and ArticleVersion pickers after click * cleanup ArticleGridLayout due to VersionPicker changes * fix tsc errors resulting from primer upgrade * fix / update tests * cleanup mobile pickers visual consistency * use btn-sm on VersionPicker * update translation and close on click for enterprise releases Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { SelectMenu, Button, Dropdown } from '@primer/components'
|
|
import { Link } from 'components/Link'
|
|
import { useRouter } from 'next/router'
|
|
import { usePlaygroundContext } from 'components/context/PlaygroundContext'
|
|
|
|
type Props = {
|
|
variant?: 'tabs' | 'dropdown'
|
|
}
|
|
export const CodeLanguagePicker = ({ variant }: Props) => {
|
|
const router = useRouter()
|
|
const { codeLanguages, currentLanguage } = usePlaygroundContext()
|
|
const routePath = router.asPath.split('?')[0]
|
|
|
|
if (variant === 'tabs') {
|
|
return (
|
|
<nav aria-label="Programming Language">
|
|
{codeLanguages.map((language) => {
|
|
return (
|
|
<Link
|
|
key={language.id}
|
|
className="subnav-item"
|
|
href={`${routePath}?langId=${language.id}`}
|
|
aria-current={language.id === currentLanguage.id ? 'page' : undefined}
|
|
>
|
|
{language.label}
|
|
</Link>
|
|
)
|
|
})}
|
|
</nav>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<SelectMenu className="position-relative">
|
|
<Button as="summary">
|
|
{currentLanguage.label} <Dropdown.Caret />
|
|
</Button>
|
|
<SelectMenu.Modal style={{ minWidth: 300 }} align="right">
|
|
<SelectMenu.Header>Programming Language</SelectMenu.Header>
|
|
<SelectMenu.List>
|
|
{codeLanguages.map((language) => (
|
|
<SelectMenu.Item
|
|
key={language.id}
|
|
as="a"
|
|
href={`${routePath}?langId=${language.id}`}
|
|
selected={language.id === currentLanguage.id}
|
|
>
|
|
{language.label}
|
|
</SelectMenu.Item>
|
|
))}
|
|
</SelectMenu.List>
|
|
</SelectMenu.Modal>
|
|
</SelectMenu>
|
|
)
|
|
}
|