forked from Transparency/kgroad-frontend2
		
	made language in menu
This commit is contained in:
		
							parent
							
								
									36896b1fad
								
							
						
					
					
						commit
						45650996c3
					
				| @ -1,7 +1,7 @@ | |||||||
| import { createSharedPathnamesNavigation } from "next-intl/navigation"; | import { createSharedPathnamesNavigation } from "next-intl/navigation"; | ||||||
| 
 | 
 | ||||||
| export const locales = ["en", "ru", "kg"] as const; | export const locales = ["en", "ru", "kg"] as const; | ||||||
| export const localePrefix = "always"; // Default
 | export const localePrefix = "always"; | ||||||
| 
 | 
 | ||||||
| export const { Link, redirect, usePathname, useRouter } = | export const { Link, redirect, usePathname, useRouter } = | ||||||
|   createSharedPathnamesNavigation({ locales, localePrefix }); |   createSharedPathnamesNavigation({ locales, localePrefix }); | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ | |||||||
|   padding: 48px 30px 30px 30px; |   padding: 48px 30px 30px 30px; | ||||||
|   width: 100%; |   width: 100%; | ||||||
|   height: 100vh; |   height: 100vh; | ||||||
|   min-height: 500px; |   min-height: 600px; | ||||||
|   position: fixed; |   position: fixed; | ||||||
|   top: 72px; |   top: 72px; | ||||||
|   left: 0; |   left: 0; | ||||||
| @ -12,8 +12,10 @@ | |||||||
|   flex-direction: column; |   flex-direction: column; | ||||||
|   gap: 26px; |   gap: 26px; | ||||||
|   background-color: white; |   background-color: white; | ||||||
|  |   overflow: scroll; | ||||||
| 
 | 
 | ||||||
|   a { |   a, | ||||||
|  |   button { | ||||||
|     justify-content: flex-start; |     justify-content: flex-start; | ||||||
|     font-size: 24px; |     font-size: 24px; | ||||||
|     font-weight: 500; |     font-weight: 500; | ||||||
| @ -22,4 +24,31 @@ | |||||||
|   &__link_active { |   &__link_active { | ||||||
|     color: $light-blue; |     color: $light-blue; | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   &__language { | ||||||
|  |     button { | ||||||
|  |       margin-bottom: 20px; | ||||||
|  |       display: flex; | ||||||
|  |       align-items: center; | ||||||
|  |       gap: 4px; | ||||||
|  |       color: #66727f; | ||||||
|  |       img { | ||||||
|  |         width: 18px; | ||||||
|  |         height: 18px; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     &-wrapper { | ||||||
|  |       display: flex; | ||||||
|  |       flex-direction: column; | ||||||
|  |       gap: 10px; | ||||||
|  |       a { | ||||||
|  |         color: #66727f; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     &_active { | ||||||
|  |       color: black !important; | ||||||
|  |       font-weight: 700 !important; | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,6 +2,10 @@ import { LINKS } from "@/shared/variables/links"; | |||||||
| import "./NavMenu.scss"; | import "./NavMenu.scss"; | ||||||
| import NavAuth from "../NavAuth/NavAuth"; | import NavAuth from "../NavAuth/NavAuth"; | ||||||
| import { Link, usePathname } from "@/shared/config/navigation"; | import { Link, usePathname } from "@/shared/config/navigation"; | ||||||
|  | import { useEffect, useState, useTransition } from "react"; | ||||||
|  | import { useParams, useRouter } from "next/navigation"; | ||||||
|  | import chevron_down from "./icons/chevron_down.svg"; | ||||||
|  | import Image from "next/image"; | ||||||
| 
 | 
 | ||||||
| interface INavMenuProps { | interface INavMenuProps { | ||||||
|   setOpenMenu: (boolean: boolean) => void; |   setOpenMenu: (boolean: boolean) => void; | ||||||
| @ -10,7 +14,37 @@ interface INavMenuProps { | |||||||
| const NavMenu: React.FC<INavMenuProps> = ({ | const NavMenu: React.FC<INavMenuProps> = ({ | ||||||
|   setOpenMenu, |   setOpenMenu, | ||||||
| }: INavMenuProps) => { | }: INavMenuProps) => { | ||||||
|  |   const [openMenuLanguage, setOpenMenuLanguage] = | ||||||
|  |     useState<boolean>(false); | ||||||
|  |   const router = useRouter(); | ||||||
|   const pathname = usePathname(); |   const pathname = usePathname(); | ||||||
|  |   const { locale } = useParams(); | ||||||
|  | 
 | ||||||
|  |   const [_, startTransition] = useTransition(); | ||||||
|  |   const [currentLanguage, setCurrentLanguage] = useState<string>( | ||||||
|  |     locale as string | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   useEffect(() => { | ||||||
|  |     const params = window.location.search || ""; | ||||||
|  |     startTransition(() => { | ||||||
|  |       router.replace(`/${currentLanguage}${pathname}${params}`, { | ||||||
|  |         scroll: false, | ||||||
|  |       }); | ||||||
|  |     }); | ||||||
|  |   }, [currentLanguage]); | ||||||
|  | 
 | ||||||
|  |   const langKeys: Record<string, string> = { | ||||||
|  |     ru: "Русский", | ||||||
|  |     kg: "Кыргызча", | ||||||
|  |     en: "English", | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const languages = [ | ||||||
|  |     { id: 1, language: "Русский", pathname: "ru" as const }, | ||||||
|  |     { id: 2, language: "Кыргызча", pathname: "kg" as const }, | ||||||
|  |     { id: 3, language: "English", pathname: "en" as const }, | ||||||
|  |   ]; | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|     <nav className="nav-menu"> |     <nav className="nav-menu"> | ||||||
| @ -18,7 +52,7 @@ const NavMenu: React.FC<INavMenuProps> = ({ | |||||||
|         <Link |         <Link | ||||||
|           onClick={() => setOpenMenu(false)} |           onClick={() => setOpenMenu(false)} | ||||||
|           className={`nav-menu__link${ |           className={`nav-menu__link${ | ||||||
|             pathname.slice(4) === link.pathname ? "_active" : "" |             pathname === link.pathname ? "_active" : "" | ||||||
|           }`}
 |           }`}
 | ||||||
|           href={`${pathname.slice(1, 3)}/${link.pathname}`} |           href={`${pathname.slice(1, 3)}/${link.pathname}`} | ||||||
|           key={link.id} |           key={link.id} | ||||||
| @ -28,6 +62,32 @@ const NavMenu: React.FC<INavMenuProps> = ({ | |||||||
|       ))} |       ))} | ||||||
| 
 | 
 | ||||||
|       <NavAuth setOpenMenu={setOpenMenu} responsible /> |       <NavAuth setOpenMenu={setOpenMenu} responsible /> | ||||||
|  | 
 | ||||||
|  |       <div className="nav-menu__language"> | ||||||
|  |         <button onClick={() => setOpenMenuLanguage((prev) => !prev)}> | ||||||
|  |           {langKeys[currentLanguage as string]} | ||||||
|  |           <Image src={chevron_down} alt="Chevron Down" /> | ||||||
|  |         </button> | ||||||
|  | 
 | ||||||
|  |         {openMenuLanguage && ( | ||||||
|  |           <div className="nav-menu__language-wrapper"> | ||||||
|  |             {languages.map((lang) => ( | ||||||
|  |               <Link | ||||||
|  |                 onClick={() => setCurrentLanguage(lang.pathname)} | ||||||
|  |                 className={`${ | ||||||
|  |                   currentLanguage === lang.pathname | ||||||
|  |                     ? "nav-menu__language_active" | ||||||
|  |                     : "" | ||||||
|  |                 }`}
 | ||||||
|  |                 href="#" | ||||||
|  |                 locale={lang.pathname} | ||||||
|  |               > | ||||||
|  |                 {lang.language} | ||||||
|  |               </Link> | ||||||
|  |             ))} | ||||||
|  |           </div> | ||||||
|  |         )} | ||||||
|  |       </div> | ||||||
|     </nav> |     </nav> | ||||||
|   ); |   ); | ||||||
| }; | }; | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								src/widgets/Navbar/NavMenu/icons/chevron_down.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/widgets/Navbar/NavMenu/icons/chevron_down.svg
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | |||||||
|  | <svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||||||
|  | <g clip-path="url(#clip0_1252_38469)"> | ||||||
|  | <path d="M0.246139 1.47381C-0.0820464 1.13666 -0.0820464 0.590022 0.246139 0.252867C0.574324 -0.084289 1.10642 -0.084289 1.4346 0.252867L5.59423 4.52619C5.92241 4.86334 5.92241 5.40998 5.59423 5.74713C5.26604 6.08429 4.73395 6.08429 4.40576 5.74713L0.246139 1.47381Z" fill="#66727F"/> | ||||||
|  | <path d="M8.56495 0.252867C8.89313 -0.0842888 9.42523 -0.0842889 9.75341 0.252867C10.0816 0.590023 10.0816 1.13666 9.75341 1.47382L5.59378 5.747C5.26559 6.08416 4.7335 6.08416 4.40531 5.747C4.07713 5.40985 4.07714 4.86334 4.40532 4.52619L8.56495 0.252867Z" fill="#66727F"/> | ||||||
|  | </g> | ||||||
|  | <defs> | ||||||
|  | <clipPath id="clip0_1252_38469"> | ||||||
|  | <rect width="10" height="6" fill="white"/> | ||||||
|  | </clipPath> | ||||||
|  | </defs> | ||||||
|  | </svg> | ||||||
| After Width: | Height: | Size: 807 B | 
		Loading…
	
		Reference in New Issue
	
	Block a user