Skip to content

Build your personal knowledge base with Trilium Notes

feat(website): add language selector to mobile header menu

Elian Doran51d601fff4c9
diff --git a/apps/website/src/components/Header.css b/apps/website/src/components/Header.css
index 3755e84127..645d318f37 100644
--- a/apps/website/src/components/Header.css
+++ b/apps/website/src/components/Header.css
@@ -38,6 +38,10 @@ header {
justify-content: flex-start;
gap: var(--gap);
+ .nav-links {
+ display: contents;
+ }
+
a {
text-decoration: none;
color: inherit;
@@ -63,6 +67,17 @@ header {
box-sizing: border-box;
display: flex;
+ &:has(nav.mobile-shown) {
+ height: 100vh;
+ overflow-y: auto;
+
+ .content-wrapper {
+ display: flex;
+ flex-direction: column;
+ min-height: 100%;
+ }
+ }
+
.content-wrapper {
display: block;
}
@@ -72,6 +87,7 @@ header {
align-items: center;
width: 100%;
gap: 2em;
+ flex-shrink: 0;
.banner {
flex-grow: 1;
@@ -90,9 +106,22 @@ header {
&.mobile-shown {
display: flex;
+ flex-grow: 1;
max-height: 100vh;
padding: 2em 0;
}
+
+ .nav-links {
+ display: flex;
+ flex-direction: column;
+ gap: var(--gap);
+ margin-top: 2em;
+ }
+
+ .nav-bottom {
+ flex-shrink: 0;
+ margin-top: auto;
+ }
}
}
diff --git a/apps/website/src/components/Header.tsx b/apps/website/src/components/Header.tsx
index 3aa81d005a..4442679216 100644
--- a/apps/website/src/components/Header.tsx
+++ b/apps/website/src/components/Header.tsx
@@ -48,19 +48,24 @@ export function Header() {
</div>
<nav className={`${mobileMenuShown ? "mobile-shown" : ""}`}>
- {headerLinks.map(link => {
- const linkHref = link.external ? link.url : swapLocaleInUrl(link.url, locale);
- return (<Link
- href={linkHref}
- className={url === linkHref ? "active" : ""}
- openExternally={link.external}
- onClick={() => {
- setMobileMenuShown(false);
- }}
- >{link.text}</Link>);
- })}
+ <div className="nav-links">
+ {headerLinks.map(link => {
+ const linkHref = link.external ? link.url : swapLocaleInUrl(link.url, locale);
+ return (<Link
+ href={linkHref}
+ className={url === linkHref ? "active" : ""}
+ openExternally={link.external}
+ onClick={() => {
+ setMobileMenuShown(false);
+ }}
+ >{link.text}</Link>);
+ })}
+ </div>
- <SocialButtons className="mobile-only" withText />
+ <div className="nav-bottom mobile-only">
+ <LanguageSelector inline onSelect={() => setMobileMenuShown(false)} />
+ <SocialButtons withText />
+ </div>
</nav>
<LanguageSelector className="desktop-only" />
diff --git a/apps/website/src/components/LanguageSelector.css b/apps/website/src/components/LanguageSelector.css
index 889becf644..b3c906f965 100644
--- a/apps/website/src/components/LanguageSelector.css
+++ b/apps/website/src/components/LanguageSelector.css
@@ -77,6 +77,71 @@
}
}
+.language-selector.inline {
+ position: static;
+ padding-top: 1em;
+ margin-bottom: 2em;
+
+ .language-label {
+ display: flex;
+ align-items: center;
+ gap: 0.4em;
+ opacity: 0.7;
+ text-transform: uppercase;
+ letter-spacing: 0.05em;
+ font-size: 0.85em;
+ margin-bottom: 0.75em;
+
+ .bx {
+ width: 1.15em;
+ height: 1.15em;
+
+ svg {
+ width: 100%;
+ height: 100%;
+ }
+ }
+ }
+
+ .language-menu {
+ position: static;
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.5em;
+ min-width: 0;
+ max-height: none;
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ background: transparent;
+ border: none;
+ border-radius: 0;
+ box-shadow: none;
+ animation: none;
+
+ li a {
+ display: block;
+ padding: 0.4em 0.8em;
+ border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
+ border-radius: 999px;
+ color: inherit;
+ text-decoration: none;
+ white-space: nowrap;
+
+ &:hover {
+ background: color-mix(in srgb, currentColor 10%, transparent);
+ text-decoration: none;
+ }
+
+ &.active {
+ color: var(--brand-1);
+ border-color: var(--brand-1);
+ font-weight: 600;
+ }
+ }
+ }
+}
+
@keyframes language-menu-in {
from {
opacity: 0;
diff --git a/apps/website/src/components/LanguageSelector.tsx b/apps/website/src/components/LanguageSelector.tsx
index 8a8ddb44b5..81a3eb68f1 100644
--- a/apps/website/src/components/LanguageSelector.tsx
+++ b/apps/website/src/components/LanguageSelector.tsx
@@ -2,6 +2,7 @@ import "./LanguageSelector.css";
import { useContext, useEffect, useRef, useState } from "preact/hooks";
import { useLocation } from "preact-iso";
+import { useTranslation } from "react-i18next";
import { LocaleContext } from "..";
import chevronIcon from "../assets/boxicons/bx-chevron-down.svg?raw";
@@ -10,7 +11,15 @@ import { LOCALES, swapLocaleInUrl } from "../i18n";
import { Link } from "./Button.js";
import Icon from "./Icon.js";
-export default function LanguageSelector({ className }: { className?: string }) {
+interface LanguageSelectorProps {
+ className?: string;
+ /** Render the locales inline (no dropdown) — used inside the mobile menu. */
+ inline?: boolean;
+ onSelect?: () => void;
+}
+
+export default function LanguageSelector({ className, inline, onSelect }: LanguageSelectorProps) {
+ const { t } = useTranslation();
const { url } = useLocation();
const currentLocale = useContext(LocaleContext);
const [ open, setOpen ] = useState(false);
@@ -19,6 +28,7 @@ export default function LanguageSelector({ className }: { className?: string })
const current = LOCALES.find(l => l.id === currentLocale) ?? LOCALES.find(l => l.id === "en");
useEffect(() => {
+ if (inline) return;
if (!open) return;
function onPointerDown(e: PointerEvent) {
@@ -36,7 +46,31 @@ export default function LanguageSelector({ className }: { className?: string })
document.removeEventListener("pointerdown", onPointerDown);
document.removeEventListener("keydown", onKeyDown);
};
- }, [ open ]);
+ }, [ open, inline ]);
+
+ if (inline) {
+ return (
+ <div className={`language-selector inline ${className ?? ""}`}>
+ <span className="language-label">
+ <Icon svg={globeIcon} className="globe" />
+ {t("header.language")}
+ </span>
+ <ul className="language-menu" role="listbox">
+ {LOCALES.map(locale => (
+ <li key={locale.id} role="option" aria-selected={locale.id === currentLocale}>
+ <Link
+ href={swapLocaleInUrl(url, locale.id)}
+ className={locale.id === currentLocale ? "active" : ""}
+ onClick={onSelect}
+ >
+ {locale.name}
+ </Link>
+ </li>
+ ))}
+ </ul>
+ </div>
+ );
+ }
return (
<div className={`language-selector ${className ?? ""}`} ref={ref}>
diff --git a/apps/website/src/translations/en/translation.json b/apps/website/src/translations/en/translation.json
index fb1c756ce7..a97e0e0981 100644
--- a/apps/website/src/translations/en/translation.json
+++ b/apps/website/src/translations/en/translation.json
@@ -186,7 +186,8 @@
"get-started": "Get started",
"documentation": "Documentation",
"resources": "Resources",
- "support-us": "Support us"
+ "support-us": "Support us",
+ "language": "Language"
},
"footer": {
"copyright_and_the": " and the ",