2
2
3
3
import Link from 'next/link' ;
4
4
import { topics } from '../constants/topics' ;
5
- import { useState , useEffect , useRef } from 'react' ;
5
+ import { useState } from 'react' ;
6
6
7
7
export default function TopicsList ( ) {
8
8
const [ hoveredTopic , setHoveredTopic ] = useState < string | null > ( null ) ;
9
- const tooltipRefs = useRef < { [ key : string ] : HTMLDivElement | null } > ( { } ) ;
10
- const buttonRefs = useRef < { [ key : string ] : HTMLButtonElement | null } > ( { } ) ;
11
-
12
- const setTooltipRef = ( id : string ) => ( el : HTMLDivElement | null ) => {
13
- tooltipRefs . current [ id ] = el ;
14
- } ;
15
-
16
- const setButtonRef = ( id : string ) => ( el : HTMLButtonElement | null ) => {
17
- buttonRefs . current [ id ] = el ;
18
- } ;
19
-
20
- useEffect ( ( ) => {
21
- const handleClickOutside = ( event : MouseEvent ) => {
22
- if ( hoveredTopic ) {
23
- const tooltip = tooltipRefs . current [ hoveredTopic ] ;
24
- const button = buttonRefs . current [ hoveredTopic ] ;
25
- if ( tooltip && button &&
26
- ! tooltip . contains ( event . target as Node ) &&
27
- ! button . contains ( event . target as Node ) ) {
28
- setHoveredTopic ( null ) ;
29
- }
30
- }
31
- } ;
32
-
33
- document . addEventListener ( 'mousedown' , handleClickOutside ) ;
34
- return ( ) => {
35
- document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
36
- } ;
37
- } , [ hoveredTopic ] ) ;
38
9
39
10
return (
40
11
< div className = "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 sm:gap-8" >
@@ -48,22 +19,17 @@ export default function TopicsList() {
48
19
< h2 className = "text-2xl font-staatliches text-white mb-2 pr-10" >
49
20
{ topic . title }
50
21
</ h2 >
51
- < button
52
- ref = { setButtonRef ( id ) }
53
- type = "button"
22
+ < div
54
23
className = "absolute top-6 sm:top-8 right-6 sm:right-8 w-8 h-8 rounded-full bg-white/20 hover:bg-white/30 flex items-center justify-center transition-colors border border-white/40"
55
- onClick = { ( e ) => {
56
- e . stopPropagation ( ) ;
57
- setHoveredTopic ( hoveredTopic === id ? null : id ) ;
58
- } }
24
+ onMouseEnter = { ( ) => setHoveredTopic ( id ) }
25
+ onMouseLeave = { ( ) => setHoveredTopic ( null ) }
59
26
>
60
27
< span className = "text-white text-sm font-medium" > ?</ span >
61
- </ button >
28
+ </ div >
62
29
</ div >
63
30
</ Link >
64
31
65
32
< div
66
- ref = { setTooltipRef ( id ) }
67
33
className = { `absolute z-10 w-80 p-5 bg-white rounded-xl shadow-xl top-full mt-2 right-0 text-left border-2 border-purple transition-all duration-200 origin-top-right ${
68
34
hoveredTopic === id
69
35
? 'opacity-100 scale-100 translate-y-0'
0 commit comments