diff --git a/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx b/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx index 270aa508a..6ec3c1bbc 100644 --- a/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx +++ b/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx @@ -1,6 +1,10 @@ import React from 'react'; import { useThemeConfig, ErrorCauseBoundary } from '@docusaurus/theme-common'; -import { splitNavbarItems, useNavbarMobileSidebar } from '@docusaurus/theme-common/internal'; +import { + splitNavbarItems, + useNavbarMobileSidebar, + useAlternatePageUtils, +} from '@docusaurus/theme-common/internal'; import NavbarItem from '@theme/NavbarItem'; import './primary-menu.scss'; import { Button } from '@deriv/ui'; @@ -8,8 +12,9 @@ import { LabelPairedGlobeCaptionRegularIcon, StandaloneChevronLeftRegularIcon, } from '@deriv/quill-icons'; - -import config from '@generated/docusaurus.config'; // Adjust the path as needed +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import { useLocation } from '@docusaurus/router'; +import classnames from 'classnames'; export function useNavbarItems() { return useThemeConfig().navbar.items; @@ -31,8 +36,44 @@ export default function CustomMobileSidebar() { setLanguageSidebarVisible(!languageSidebarVisible); }; - // Get the available locales from Docusaurus config - const { locales } = config.i18n; + const { + i18n: { currentLocale, locales, localeConfigs }, + } = useDocusaurusContext(); + const alternatePageUtils = useAlternatePageUtils(); + const { search, hash } = useLocation(); + + const localeItems = locales.map((locale) => { + const baseTo = `pathname:${alternatePageUtils.createUrl({ + locale, + fullyQualified: false, + })}`; + const to = `${baseTo}${search}${hash}`; + return { + label: localeConfigs[locale].label, + lang: localeConfigs[locale].htmlLang, + to, + target: '_self', + autoAddBaseUrl: false, + className: classnames({ 'dropdown__link--active': locale === currentLocale }), + }; + }); + + const getShortNames = (locale) => { + switch (locale) { + case 'en': + return 'EN'; + case 'es': + return 'ES'; + case 'fr': + return 'FR'; + case 'pt': + return 'PT'; + default: + return 'EN'; + } + }; + + const dropdownLabel = getShortNames(currentLocale); return ( @@ -43,8 +84,8 @@ export default function CustomMobileSidebar() { onError={(error) => new Error( `A theme navbar item failed to render. - Please double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config: - ${JSON.stringify(item, null, 2)}`, + Please double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config: + ${JSON.stringify(item, null, 2)}`, ) } > @@ -58,15 +99,22 @@ export default function CustomMobileSidebar() { ))}
- EN + {dropdownLabel}
- {locales.map((locale) => ( -
{locale}
+ {localeItems.map((localeItem) => ( + mobileSidebar.toggle()} + > + {localeItem.label} + ))}
diff --git a/src/theme/Navbar/MobileSidebar/PrimaryMenu/primary-menu.scss b/src/theme/Navbar/MobileSidebar/PrimaryMenu/primary-menu.scss index 7210c0f10..31d709462 100644 --- a/src/theme/Navbar/MobileSidebar/PrimaryMenu/primary-menu.scss +++ b/src/theme/Navbar/MobileSidebar/PrimaryMenu/primary-menu.scss @@ -5,6 +5,7 @@ padding: 16px 16px; font-size: 0.875rem; align-items: flex-start; + background-color: var(--ifm-navbar-background-color); gap: 8px; align-self: stretch; font-weight: var(--ifm-font-weight-normal); @@ -13,12 +14,6 @@ width: 100vw; } - .navbar__link { - &--active { - background-color: var(--ifm-menu-color-background-active); - } - } - .language_sidebar { position: fixed; top: 0; @@ -37,24 +32,31 @@ opacity: 1; visibility: visible; transform: translateX(0); - margin-left: 10px; } &__items { margin-top: 16px; display: flex; - height: 48px; - min-height: 48px; - max-height: 48px; padding: 0px 16px; - margin-left: 32px; - padding-right: 32px; - gap: 32px; - align-self: stretch; - height: calc(100% - var(--ifm-navbar-height)); - transform: translateZ(0); - transition: transform var(--ifm-transition-fast) ease-in-out; flex-direction: column; + gap: 24px; + align-items: flex-start; + } + + a { + overflow: hidden; + font-family: var(--ibm-font-family-base); + font-size: 16px; + font-weight: 400; + line-height: 24px; + color: rgba(0, 0, 0, 0.72) !important; + text-decoration: none; + + &:hover, + &:active, + &.dropdown__link--active { + color: var(--colors-coral500) !important; + } } } } diff --git a/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx b/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx index a0ca776df..56be54c93 100644 --- a/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +++ b/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx @@ -20,11 +20,11 @@ export default function LocaleDropdownNavbarItem({ const { search, hash } = useLocation(); const localeItems = locales.map((locale): LinkLikeNavbarItemProps => { - const baseTo = `pathname://${alternatePageUtils.createUrl({ + const baseTo = `pathname:${alternatePageUtils.createUrl({ locale, fullyQualified: false, })}`; - // preserve ?search#hash suffix on locale switches + const to = `${baseTo}${search}${hash}`; return { label: localeConfigs[locale].label,