From 1606ea00530ed7a59c7b1e0e5b8b0ff5f626ccb0 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 May 2026 03:31:38 -0400 Subject: [PATCH] fix theme and language buttons --- apps/admin/src/app/dashboard/layout.tsx | 2 +- apps/admin/src/components/I18nProvider.tsx | 154 ++++++++++++++++----- 2 files changed, 117 insertions(+), 39 deletions(-) diff --git a/apps/admin/src/app/dashboard/layout.tsx b/apps/admin/src/app/dashboard/layout.tsx index c6aa2f5..c2beb96 100644 --- a/apps/admin/src/app/dashboard/layout.tsx +++ b/apps/admin/src/app/dashboard/layout.tsx @@ -93,7 +93,7 @@ export default function AdminDashboardLayout({ children }: { children: React.Rea {dict.logout} -
+
diff --git a/apps/admin/src/components/I18nProvider.tsx b/apps/admin/src/components/I18nProvider.tsx index 9fa627e..d7f46d2 100644 --- a/apps/admin/src/components/I18nProvider.tsx +++ b/apps/admin/src/components/I18nProvider.tsx @@ -160,68 +160,146 @@ export function useAdminI18n() { } export function AdminLanguageSwitcher() { - const { language, setLanguage, dict } = useAdminI18n() + const { language, setLanguage } = useAdminI18n() + const [open, setOpen] = useState(false) const [embedded, setEmbedded] = useState(false) + const ref = useRef(null) useEffect(() => { setEmbedded(window.self !== window.top) }, []) + useEffect(() => { + if (!open) return + function onMouseDown(e: MouseEvent) { + if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false) + } + document.addEventListener('mousedown', onMouseDown) + return () => document.removeEventListener('mousedown', onMouseDown) + }, [open]) + if (embedded) return null + const current = languageMeta[language] + return ( -
- {dict.language} - {(['en', 'fr', 'ar'] as AdminLanguage[]).map((value) => { - const active = value === language - const meta = languageMeta[value] - return ( - - ) - })} +
+ + + {open && ( +
+ {(['en', 'fr', 'ar'] as AdminLanguage[]).map((value) => { + const meta = languageMeta[value] + const active = value === language + return ( + + ) + })} +
+ )}
) } export function AdminThemeSwitcher() { const { theme, setTheme, dict } = useAdminI18n() + const [open, setOpen] = useState(false) const [embedded, setEmbedded] = useState(false) + const ref = useRef(null) useEffect(() => { setEmbedded(window.self !== window.top) }, []) + useEffect(() => { + if (!open) return + function onMouseDown(e: MouseEvent) { + if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false) + } + document.addEventListener('mousedown', onMouseDown) + return () => document.removeEventListener('mousedown', onMouseDown) + }, [open]) + if (embedded) return null return ( -
- {(['light', 'dark'] as AdminTheme[]).map((value) => { - const active = value === theme - return ( - - ) - })} +
+ + + {open && ( +
+ {(['light', 'dark'] as AdminTheme[]).map((value) => { + const active = value === theme + return ( + + ) + })} +
+ )}
) }