mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
* Rename dropdown primitives to OL-prefixed components * Migrate all consumers to OL-prefixed dropdown components * Migrate subscription dropdown shells to OL components * Update pdf-preview story to OL-prefixed dropdown components * Migrate navbar and spelling dropdowns to OL components * Move dropdown primitives to ol/ol-dropdown-menu, remove BS5 import aliases * Rename dropdown prop types to OL-prefixed, clean up BS5 import aliases * Widen OLDropdownItem/Toggle/Menu props to include AriaAttributes and data-* GitOrigin-RevId: 0babce46867849b3f176bac8cf1652dc76fd34da
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import React from 'react'
|
|
import {
|
|
OLDropdown,
|
|
OLDropdownItem,
|
|
OLDropdownMenu,
|
|
OLDropdownToggle,
|
|
OLDropdownHeader,
|
|
} from './ol/ol-dropdown-menu'
|
|
import { useTranslation } from 'react-i18next'
|
|
import getMeta from '@/utils/meta'
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
|
|
function LanguagePicker({ showHeader } = { showHeader: false }) {
|
|
const { t } = useTranslation()
|
|
|
|
const currentLangCode = getMeta('ol-i18n').currentLangCode
|
|
const translatedLanguages = getMeta('ol-footer').translatedLanguages
|
|
const subdomainLang = getMeta('ol-footer').subdomainLang
|
|
const currentUrlWithQueryParams = window.location.pathname
|
|
|
|
return (
|
|
<OLDropdown drop="up">
|
|
<OLDropdownToggle
|
|
id="language-picker-toggle"
|
|
aria-label={t('select_a_language')}
|
|
data-bs-toggle="dropdown"
|
|
className="btn-inline-link"
|
|
variant="link"
|
|
>
|
|
<MaterialIcon type="translate" />
|
|
|
|
<span className="language-picker-text">
|
|
{translatedLanguages?.[currentLangCode]}
|
|
</span>
|
|
</OLDropdownToggle>
|
|
|
|
<OLDropdownMenu
|
|
className="dropdown-menu-sm-width"
|
|
aria-labelledby="language-picker-toggle"
|
|
>
|
|
{showHeader ? (
|
|
<OLDropdownHeader>{t('language')}</OLDropdownHeader>
|
|
) : null}
|
|
{subdomainLang &&
|
|
Object.entries(subdomainLang).map(([subdomain, subdomainDetails]) => {
|
|
if (
|
|
!subdomainDetails ||
|
|
!subdomainDetails.lngCode ||
|
|
subdomainDetails.hide
|
|
)
|
|
return null
|
|
const isActive = subdomainDetails.lngCode === currentLangCode
|
|
return (
|
|
<li role="none" key={subdomain} translate="no">
|
|
<OLDropdownItem
|
|
href={`${subdomainDetails.url}${currentUrlWithQueryParams}`}
|
|
active={isActive}
|
|
aria-current={isActive ? 'true' : false}
|
|
trailingIcon={isActive ? 'check' : null}
|
|
>
|
|
{translatedLanguages?.[subdomainDetails.lngCode]}
|
|
</OLDropdownItem>
|
|
</li>
|
|
)
|
|
})}
|
|
</OLDropdownMenu>
|
|
</OLDropdown>
|
|
)
|
|
}
|
|
|
|
export default LanguagePicker
|