From ac30ac1ecf1f33f597b11dd061ada688af2fc154 Mon Sep 17 00:00:00 2001 From: Mahyar Khanbolooki Date: Sun, 10 Aug 2025 16:30:37 +0330 Subject: [PATCH] add: profile dropdown --- src/components/topbar/TopBar.tsx | 96 ++++++++++++++----- src/components/utils/Dropdown.tsx | 62 ++++++++++++ src/components/utils/Seperator.tsx | 18 ++++ .../wrapper/ClientMenuRouteWrapper.tsx.tsx | 2 +- 4 files changed, 154 insertions(+), 24 deletions(-) create mode 100644 src/components/utils/Dropdown.tsx create mode 100644 src/components/utils/Seperator.tsx diff --git a/src/components/topbar/TopBar.tsx b/src/components/topbar/TopBar.tsx index 4af63f0..690197d 100644 --- a/src/components/topbar/TopBar.tsx +++ b/src/components/topbar/TopBar.tsx @@ -1,14 +1,14 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ 'use client' import React from 'react' -import NightModeSwitch from '../button/NightModeSwitch' import BurgerMenuIcon from '../icons/BurgerMenuIcon' import NotificationBellIcon from '../icons/NotificationBellIcon' -import WalletIcon from '../icons/WalletIcon' -import GridIcon from '../icons/GridIcon' import Image from 'next/image' -import { ArrowDown2 } from 'iconsax-react' +import { ArrowDown2, LogoutCurve, ProfileCircle, Setting2 } from 'iconsax-react' +import Dropdown from '../utils/Dropdown' +import Seperator from '../utils/Seperator' +import Link from 'next/link' +import { useParams } from 'next/navigation' type Props = { profileDropState: boolean, @@ -21,7 +21,10 @@ type Props = { toggleNightModeState: React.MouseEventHandler | undefined } -function TopBar({ profileDropState, toggleProfileDropState, menuState, toggleMenuState, searchModalState, toggleSearchModalState, nightModeState, toggleNightModeState }: Props) { +function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: Props) { + const params = useParams(); + const { name } = params; + return (
@@ -44,26 +47,32 @@ function TopBar({ profileDropState, toggleProfileDropState, menuState, toggleMen
*/}
- Profile avatar
-
+
{/* */} {/* */} - - - -
- {/* */} + + +
+ {'user +

mail@danakcorp.com

+
+ + + +
+ + +
پروفایل
+ + + +
تنظیمات
+ +
+ + + +
) diff --git a/src/components/utils/Dropdown.tsx b/src/components/utils/Dropdown.tsx new file mode 100644 index 0000000..5dbf0b8 --- /dev/null +++ b/src/components/utils/Dropdown.tsx @@ -0,0 +1,62 @@ +'use client'; + +import clsx from 'clsx' +import { HTMLMotionProps, motion } from 'framer-motion'; +import { CloseCircle } from 'iconsax-react' +import React, { useEffect, useRef } from 'react' + +interface DropdownProps extends Omit, "ref"> { + active?: boolean, + toggle?: React.MouseEventHandler | undefined, + children?: React.ReactNode +}; + +function Dropdown({ active, toggle, children, ...rest }: DropdownProps) { + const boxRef = useRef(null); + const closeButtonRef = useRef(null); + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (boxRef.current && !boxRef.current.contains(event.target as Node)) { + closeButtonRef.current?.click(); + } + }; + + if (active) { + document.addEventListener('click', handleClickOutside); + } + + return () => { + document.removeEventListener('click', handleClickOutside); + }; + }, [active]); + + + return ( + +
+ + {children} +
+
+ ) +} + +export default Dropdown \ No newline at end of file diff --git a/src/components/utils/Seperator.tsx b/src/components/utils/Seperator.tsx new file mode 100644 index 0000000..3d00b80 --- /dev/null +++ b/src/components/utils/Seperator.tsx @@ -0,0 +1,18 @@ +'use client'; + +import clsx from 'clsx' +import React from 'react' + +function Seperator({ className, ...rest }: React.HTMLAttributes) { + return ( +
+ ) +} + +export default Seperator \ No newline at end of file diff --git a/src/components/wrapper/ClientMenuRouteWrapper.tsx.tsx b/src/components/wrapper/ClientMenuRouteWrapper.tsx.tsx index bc55001..1be105c 100644 --- a/src/components/wrapper/ClientMenuRouteWrapper.tsx.tsx +++ b/src/components/wrapper/ClientMenuRouteWrapper.tsx.tsx @@ -52,7 +52,7 @@ function ClientMenuRouteWrapper({ children }: Props) { -
+