1
- import Link from "next/link" ;
2
- import React from "react" ;
3
1
import { useRouter } from "next/router" ;
4
- import { IoChevronDown } from "react-icons/io5" ;
5
- import { Menu , MenuButton , MenuList , MenuItem , Button } from "@chakra-ui/react" ;
2
+ import { Menu , MenuButton , MenuList , Button , useDisclosure , MenuItem } from "@chakra-ui/react" ;
3
+ import { IoChevronDown , IoChevronUp } from "react-icons/io5" ;
4
+ import Link from "next/link" ;
6
5
7
6
export interface DropdownButtonProps {
8
7
hasMenu ?: boolean ;
@@ -13,22 +12,22 @@ export interface DropdownButtonProps {
13
12
14
13
const DropdownButton = ( { hasMenu = false , text, href, list } : DropdownButtonProps ) => {
15
14
const router = useRouter ( ) ;
15
+ const { isOpen, onOpen, onClose } = useDisclosure ( ) ;
16
16
const isActive = hasMenu ? list ?. some ( ( item ) => router . asPath . startsWith ( item . url ) ) : router . asPath === href ;
17
17
18
18
if ( hasMenu ) {
19
19
return (
20
- < Menu >
20
+ < Menu isOpen = { isOpen } onOpen = { onOpen } onClose = { onClose } >
21
21
< MenuButton
22
- color = " white"
23
- bg = { isActive ? "#c3a6d9) " : "transparent " }
22
+ color = { isActive ? "black" : " white"}
23
+ bg = { isActive ? "#c3a6d9" : "" }
24
24
as = { Button }
25
- pt = "25px"
26
- pb = "25px"
25
+ h = "100%"
27
26
borderRadius = { 0 }
28
- rightIcon = { < IoChevronDown /> }
29
- fontWeight = "normal"
27
+ rightIcon = { isOpen ? < IoChevronUp size = "10px" /> : < IoChevronDown size = "10px" /> }
28
+ fontWeight = { "normal" }
30
29
_hover = { { bgColor : "rgba(255, 255, 255, 0.3)" } }
31
- _active = { { bgColor : " rgba(255, 255, 255, 0.3)" } }
30
+ _active = { { bgColor : "rgba(255, 255, 255, 0.3)" } }
32
31
_focus = { { outline : 0 } }
33
32
>
34
33
{ text }
@@ -49,26 +48,24 @@ const DropdownButton = ({ hasMenu = false, text, href, list }: DropdownButtonPro
49
48
</ MenuList >
50
49
</ Menu >
51
50
) ;
52
- } else if ( href ) {
53
- return (
54
- < Link href = { href } passHref >
55
- < Button
56
- color = "white"
57
- bg = { isActive ? "#c3a6d9" : "transparent" }
58
- pt = "25px"
59
- pb = "25px"
60
- borderRadius = { 0 }
61
- fontWeight = "normal"
62
- _hover = { { bgColor : "rgba(255, 255, 255, 0.3)" } }
63
- _active = { { bgColor : " rgba(255, 255, 255, 0.3)" } }
64
- _focus = { { outline : "0" } }
65
- alignSelf = "self-end"
66
- >
67
- { text }
68
- </ Button >
69
- </ Link >
70
- ) ;
71
51
}
52
+
53
+ return (
54
+ < Link href = { href ?? "#" } style = { { height : "100%" } } passHref >
55
+ < Button
56
+ h = "100%"
57
+ color = { isActive ? "black" : "white" }
58
+ bg = { isActive ? "#c3a6d9" : "" }
59
+ borderRadius = { 0 }
60
+ fontWeight = "normal"
61
+ _hover = { { bgColor : "rgba(255, 255, 255, 0.3)" } }
62
+ _active = { { bgColor : "rgba(255, 255, 255, 0.3)" } }
63
+ _focus = { { outline : 0 } }
64
+ >
65
+ { text }
66
+ </ Button >
67
+ </ Link >
68
+ ) ;
72
69
} ;
73
70
74
71
export default DropdownButton ;
0 commit comments