@@ -4,10 +4,9 @@ import { useEffect, useRef, useState } from 'react'
4
4
import styles from './styles.module.css'
5
5
6
6
function WithProvider ( ) {
7
- const tooltipper = useTooltip ( )
8
- const { attach, detach } = tooltipper ( )
9
- const { attach : attach1 , detach : detach1 } = tooltipper ( 'tooltip-1' )
10
- const { attach : attach2 , detach : detach2 } = tooltipper ( 'tooltip-2' )
7
+ const { attach, detach } = useTooltip ( )
8
+ const { attach : attach1 , detach : detach1 } = useTooltip ( ) ( 'tooltip-1' )
9
+ const { attach : attach2 , detach : detach2 } = useTooltip ( ) ( 'tooltip-2' )
11
10
const buttonRef1 = useRef < HTMLButtonElement > ( null )
12
11
const buttonRef2 = useRef < HTMLButtonElement > ( null )
13
12
const buttonRef3 = useRef < HTMLButtonElement > ( null )
@@ -29,40 +28,62 @@ function WithProvider() {
29
28
return (
30
29
< section style = { { marginTop : '100px' } } >
31
30
< p >
32
- < button
33
- ref = { buttonRef1 }
34
- data-tooltip-place = "right"
35
- data-tooltip-content = "Hello World from a Shared Global Tooltip"
36
- >
37
- Hover or focus me 5
31
+ < button ref = { buttonRef1 } data-tooltip-content = "Shared Global Tooltip" >
32
+ Provider 1
38
33
</ button >
39
- < button ref = { buttonRef2 } data-tooltip-content = "Hello World from a Shared Global Tooltip" >
40
- Hover or focus me 6
34
+ < button ref = { buttonRef2 } data-tooltip-content = "Shared Global Tooltip" >
35
+ Provider 2
41
36
</ button >
42
37
</ p >
43
38
< p >
44
- < button ref = { buttonRef3 } data-tooltip-content = "Hello World from Shared Tooltip 1" >
45
- Hover or focus me 7
39
+ < button ref = { buttonRef3 } data-tooltip-content = "Shared Tooltip 1" >
40
+ Provider 3
46
41
</ button >
47
- < button ref = { buttonRef4 } data-tooltip-content = "Hello World from Shared Tooltip 1" >
48
- Hover or focus me 8
42
+ < button ref = { buttonRef4 } data-tooltip-content = "Shared Tooltip 1" >
43
+ Provider 4
49
44
</ button >
50
45
</ p >
51
46
< p >
52
- < button ref = { buttonRef5 } data-tooltip-content = "Hello World from Shared Tooltip 2" >
53
- Hover or focus me 9
47
+ < button ref = { buttonRef5 } data-tooltip-content = "Shared Tooltip 2" >
48
+ Provider 5
54
49
</ button >
55
- < button ref = { buttonRef6 } data-tooltip-content = "Hello World from Shared Tooltip 2" >
56
- Hover or focus me 10
50
+ < button ref = { buttonRef6 } data-tooltip-content = "Shared Tooltip 2" >
51
+ Provider 6
57
52
</ button >
58
53
</ p >
59
- < Tooltip />
60
54
< Tooltip id = "tooltip-1" />
61
55
< Tooltip id = "tooltip-2" />
62
56
</ section >
63
57
)
64
58
}
65
59
60
+ function WithProviderMinimal ( ) {
61
+ const { attach, detach } = useTooltip ( )
62
+ const buttonRef1 = useRef < HTMLButtonElement > ( null )
63
+ const buttonRef2 = useRef < HTMLButtonElement > ( null )
64
+
65
+ useEffect ( ( ) => {
66
+ attach ( buttonRef1 , buttonRef2 )
67
+ return ( ) => {
68
+ detach ( buttonRef1 , buttonRef2 )
69
+ }
70
+ } , [ ] )
71
+
72
+ return (
73
+ < section style = { { marginTop : '100px' } } >
74
+ < p >
75
+ < button ref = { buttonRef1 } data-tooltip-content = "Shared Global Tooltip" >
76
+ Minimal 1
77
+ </ button >
78
+ < button ref = { buttonRef2 } data-tooltip-content = "Shared Global Tooltip" >
79
+ Minimal 2
80
+ </ button >
81
+ </ p >
82
+ < Tooltip />
83
+ </ section >
84
+ )
85
+ }
86
+
66
87
function App ( ) {
67
88
const [ anchorId , setAnchorId ] = useState ( 'button' )
68
89
const [ isDarkOpen , setIsDarkOpen ] = useState ( false )
@@ -136,6 +157,9 @@ function App() {
136
157
< TooltipProvider >
137
158
< WithProvider />
138
159
</ TooltipProvider >
160
+ < TooltipProvider >
161
+ < WithProviderMinimal />
162
+ </ TooltipProvider >
139
163
</ main >
140
164
)
141
165
}
0 commit comments