From fafa8d9683cba9043d6c24ded3afc56e465adbd3 Mon Sep 17 00:00:00 2001 From: sina_sajjadi Date: Wed, 15 Jan 2025 18:41:34 +0330 Subject: [PATCH] feat: enhance mobile navigation with RTL support and modal integration --- src/components/layout/mobile-navigation.tsx | 42 ++++++++++++--------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/components/layout/mobile-navigation.tsx b/src/components/layout/mobile-navigation.tsx index 7dadae2..7eaa202 100644 --- a/src/components/layout/mobile-navigation.tsx +++ b/src/components/layout/mobile-navigation.tsx @@ -1,28 +1,28 @@ // components/MobileNavigation.tsx -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { useUI } from "../context/ui.context"; import Logo from "../ui/logo"; import { IoMdClose } from "react-icons/io"; import Link from "next/link"; import LanguageSwitcher from "../language-switcher"; -import { i18n, useTranslation } from "next-i18next"; // Import useTranslation - -const isRTL = i18n?.dir() === "rtl"; +import { i18n, useTranslation } from "next-i18next"; // Import useTranslation // Adjust sidebar variants based on RTL -const sidebarVariants = { - hidden: { x: isRTL ? "100%" : "-100%" }, // Start off-screen to the right for RTL, left for LTR - visible: { x: 0 }, // Fully visible on the screen - exit: { x: isRTL ? "100%" : "-100%" }, // Exit to the right for RTL, left for LTR -}; const MobileNavigation = () => { - const { displaySidebar, closeSidebar } = useUI(); - const { t } = useTranslation("common"); // Use the translation hook for common translations - console.log(isRTL); - + const { displaySidebar, closeSidebar, openModal } = useUI(); + const { t } = useTranslation("common"); // Use the translation hook for common translations + const [isRTL, setIsRTL] = useState(false); + const sidebarVariants = { + hidden: { x: isRTL ? "100%" : "-100%" }, // Start off-screen to the right for RTL, left for LTR + visible: { x: 0 }, // Fully visible on the screen + exit: { x: isRTL ? "100%" : "-100%" }, // Exit to the right for RTL, left for LTR + }; + useEffect(() => { + setIsRTL(i18n?.dir().trim() === "rtl"); + }, [i18n?.language]); useEffect(() => { document.body.style.overflow = displaySidebar ? "hidden" : "auto"; }, [displaySidebar]); @@ -60,17 +60,25 @@ const MobileNavigation = () => {