1
+ import Link from "next/link" ;
2
+ import { useState } from 'react' ;
3
+ import { useSelector } from 'react-redux'
4
+ import { mdiChevronUp , mdiChevronDown } from "@mdi/js" ;
5
+ import BaseDivider from "./baseDivider" ;
6
+ import BaseIcon from "./baseIcon" ;
7
+ import UserAvatarCurrentUser from "./userAvatarCurrentUser" ;
8
+ import NavBarMenuList from "./navBarMenuList" ;
9
+
10
+ export default function NavBarItem ( { item } ) {
11
+ const navBarItemLabelActiveColorStyle = useSelector ( state => state . style . navBarItemLabelActiveColorStyle )
12
+ const navBarItemLabelStyle = useSelector ( state => state . style . navBarItemLabelStyle )
13
+ const navBarItemLabelHoverStyle = useSelector ( state => state . style . navBarItemLabelHoverStyle )
14
+
15
+ const userName = useSelector ( state => state . main . userName )
16
+
17
+ const [ isDropdownActive , setIsDropdownActive ] = useState ( false )
18
+
19
+ const componentClass = [
20
+ "block lg:flex items-center relative cursor-pointer" ,
21
+ isDropdownActive
22
+ ? `${ navBarItemLabelActiveColorStyle } dark:text-slate-400`
23
+ : `${ navBarItemLabelStyle } dark:text-white dark:hover:text-slate-400 ${ navBarItemLabelHoverStyle } ` ,
24
+ item . menu ? "lg:py-2 lg:px-3" : "py-2 px-3" ,
25
+ item . isDesktopNoLabel ? "lg:w-16 lg:justify-center" : ""
26
+ ] . join ( ' ' )
27
+
28
+ const itemLabel = item . isCurrentUser ? userName : item . label
29
+
30
+ const NavBarItemComponentContents = (
31
+ < >
32
+ < div className = { `flex items-center ${ item . menu ? 'bg-gray-100 dark:bg-slate-800 lg:bg-transparent lg:dark:bg-transparent p-3 lg:p-0' : '' } ` } >
33
+ { item . isCurrentUser && < UserAvatarCurrentUser className = "w-6 h-6 mr-3 inline-flex" /> }
34
+ { item . icon && < BaseIcon path = { item . icon } className = "transition-colors" /> }
35
+ < span className = { `px-2 transition-colors ${ item . isDesktopNoLabel && item . icon ? 'lg:hidden' : '' } ` } >
36
+ { itemLabel }
37
+ </ span >
38
+ { item . menu && < BaseIcon path = { isDropdownActive ? mdiChevronUp : mdiChevronDown } className = "hidden lg:inline-flex transition-colors" /> }
39
+ </ div >
40
+ { item . menu && (
41
+ < div
42
+ className = { `${ ! isDropdownActive ? 'lg:hidden' : '' } text-sm border-b border-gray-100 lg:border lg:bg-white lg:absolute lg:top-full lg:left-0 lg:min-w-full lg:z-20 lg:rounded-lg lg:shadow-lg lg:dark:bg-slate-800 dark:border-slate-700` }
43
+ >
44
+ < NavBarMenuList menu = { item . menu } onClick = { ( ) => setIsDropdownActive ( ! isDropdownActive ) } />
45
+ </ div >
46
+ ) }
47
+ </ >
48
+ )
49
+
50
+ if ( item . isDivider ) {
51
+ return < BaseDivider navBar />
52
+ }
53
+
54
+ if ( item . href ) {
55
+ return (
56
+ < Link
57
+ href = { item . href }
58
+
59
+ >
60
+ < a className = { componentClass } >
61
+ { NavBarItemComponentContents }
62
+ </ a >
63
+ </ Link >
64
+ )
65
+ }
66
+
67
+ return (
68
+ < div className = { componentClass } >
69
+ { NavBarItemComponentContents }
70
+ </ div >
71
+ )
72
+ }
0 commit comments