Skip to content

Commit

Permalink
Developed User Menu with dynamic theme switching, language dropdown w… (
Browse files Browse the repository at this point in the history
#115)

* Developed User Menu with dynamic theme switching, language dropdown with flags, updated icons, and improved UI consistency.

-Integrated dynamic theme switching (Light/Dark mode) using next-themes with a Switch component and dynamic Sun/Moon icons.
-Added language dropdown with flags (en-flag.svg and es-flag.svg) for English and Spanish, displaying the selected language in the menu trigger.
-Replaced History icon with FileDollar for the Transactions option.
-Improved alignment, spacing, and transitions.
-Refactored imports logic for maintainability.

* Changes on DropdownMenuSubContent for languaje.
  • Loading branch information
DanielVillatoro authored Jan 27, 2025
1 parent ae2dbd8 commit 9e353ec
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 11 deletions.
4 changes: 0 additions & 4 deletions apps/frontend/app/components/shared/header/action-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Bell, ShoppingCart, Wallet } from "lucide-react";

import { Button } from "@/app/components/ui/button";
import { ThemeToggle } from "../../ui/theme-toggle";
import { UserMenu } from "./user-menu";
import * as Tooltip from "@radix-ui/react-tooltip";
import { ConnectWalletModal } from "./connect-wallet-modal";
Expand Down Expand Up @@ -47,9 +46,6 @@ export const ActionButtons = () => {
</Tooltip.Root>


<ThemeToggle />


<Tooltip.Root>
<Tooltip.Trigger asChild>
<Button variant="ghost" size="icon">
Expand Down
106 changes: 99 additions & 7 deletions apps/frontend/app/components/shared/header/user-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,130 @@
import { History, List, Settings, User } from "lucide-react";
"use client";

import { List, Settings, User, Moon, Sun, Globe, Receipt } from "lucide-react";
import { useState } from "react";
import { useTheme } from "next-themes";

import { Button } from "@/app/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
DropdownMenuSub,
DropdownMenuSubTrigger,
DropdownMenuSubContent,
} from "@/app/components/ui/dropdown-menu";
import { Switch } from "@/app/components/ui/switch";

export const UserMenu = () => {
const { theme, setTheme } = useTheme(); // Handles the light/dark mode logic
const isDarkMode = theme === "dark"; // Check current theme
const [language, setLanguage] = useState("EN");

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon">
<User className="!h-6 !w-6 transition-transform group-hover:scale-110" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-48">
<DropdownMenuContent className="w-64">
{/* Profile Options */}
<DropdownMenuItem>
<User className="mr-2 h-4 w-4" />
Profile
<span>Profile</span>
</DropdownMenuItem>
<DropdownMenuItem>
<List className="mr-2 h-4 w-4" />
My Listings
<span>My Products</span>
</DropdownMenuItem>
<DropdownMenuItem>
<History className="mr-2 h-4 w-4" />
Transaction History
<Receipt className="mr-2 h-4 w-4" />
<span>Transactions</span>
</DropdownMenuItem>
<DropdownMenuItem>
<Settings className="mr-2 h-4 w-4" />
Settings
<span>Settings</span>
</DropdownMenuItem>

{/* Divider Line */}
<div className="my-2 h-px bg-gray-200" />

{/* Dark Mode Toggle */}
<DropdownMenuItem asChild>
<div className="flex items-center justify-between w-full">
<div className="flex items-center">
{isDarkMode ? (
<Moon className="mr-2 h-4 w-4" />
) : (
<Sun className="mr-2 h-4 w-4" />
)}
<span>{isDarkMode ? "Dark Mode" : "Light Mode"}</span>
</div>
<Switch
checked={isDarkMode}
onCheckedChange={(checked) =>
setTheme(checked ? "dark" : "light")
}
className="ml-2"
/>
</div>
</DropdownMenuItem>

{/* Language Dropdown */}
<DropdownMenuSub>
<DropdownMenuSubTrigger>
<div className="flex items-center justify-between w-full cursor-pointer">
<div className="flex items-center">
<Globe className="mr-2 h-4 w-4" />
<span>Language</span>
</div>
<div className="flex items-center">
<img
src={
language === "EN"
? "/images/en-flag.svg"
: "/images/es-flag.svg"
}
alt={language}
className="mr-1 h-4 w-4"
/>
<span>{language}</span>
</div>
</div>
</DropdownMenuSubTrigger>
{/* <DropdownMenuSubContent className="w-full mt-6 origin-top"> */}
{/* <DropdownMenuSubContent className="absolute mt-2 left-100 top-full w-full origin-top"> */}

<DropdownMenuSubContent
className="w-full mt-6 left-0 top-0 transform translate-x-[240px] translate-y-[5px] min-w-max z-50">
{/* <DropdownMenuSubContent className="mt-2 w-full origin-top"> */}




<DropdownMenuItem onClick={() => setLanguage("EN")}>
<div className="flex items-center">
<img
src="/images/en-flag.svg"
alt="English"
className="mr-2 h-4 w-4"
/>
<span>EN</span>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setLanguage("ES")}>
<div className="flex items-center">
<img
src="/images/es-flag.svg"
alt="Español"
className="mr-2 h-4 w-4"
/>
<span>ES</span>
</div>
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuSub>
</DropdownMenuContent>
</DropdownMenu>
);
Expand Down

0 comments on commit 9e353ec

Please sign in to comment.