File tree Expand file tree Collapse file tree 4 files changed +189
-150
lines changed
docs/app/(home)/_components Expand file tree Collapse file tree 4 files changed +189
-150
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ const PDFContent = ({
125
125
< TextLayer />
126
126
< AnnotationHighlightLayer
127
127
focusedAnnotationId = { focusedAnnotationId }
128
+ tooltipClassName = "bg-white shadow-lg rounded-lg p-3 min-w-[200px]"
128
129
onAnnotationClick = { onAnnotationClick }
129
130
renderTooltipContent = { renderTooltipContent }
130
131
/>
Original file line number Diff line number Diff line change 1
-
2
1
import { useCallback } from "react" ;
2
+ import { createPortal } from "react-dom" ;
3
3
4
4
import type { Annotation } from "../hooks/useAnnotations" ;
5
5
import { useAnnotationTooltip } from "../hooks/useAnnotationTooltip" ;
6
+ import { usePdf } from "../internal" ;
6
7
7
8
interface AnnotationTooltipProps {
8
9
annotation : Annotation ;
9
10
children : React . ReactNode ;
10
11
tooltipContent : React . ReactNode ;
11
12
onOpenChange ?: ( open : boolean ) => void ;
12
13
isOpen ?: boolean ;
14
+ className ?: string ;
13
15
}
14
16
15
17
export const AnnotationTooltip = ( {
16
18
annotation,
17
19
children,
18
20
tooltipContent,
19
21
onOpenChange,
22
+ className,
20
23
isOpen : controlledIsOpen ,
21
24
} : AnnotationTooltipProps ) => {
25
+ const viewportRef = usePdf ( ( state ) => state . viewportRef ) ;
22
26
const {
23
27
isOpen : uncontrolledIsOpen ,
24
28
setIsOpen,
@@ -48,19 +52,20 @@ export const AnnotationTooltip = ({
48
52
>
49
53
{ children }
50
54
</ div >
51
- { isOpen && (
55
+ { isOpen && viewportRef . current && createPortal (
52
56
< div
53
57
ref = { refs . setFloating }
54
- className = "bg-white shadow-lg rounded-lg p-3 z-50 min-w-[200px]"
58
+ className = { className }
55
59
style = { {
56
60
...floatingStyles ,
57
- position : 'fixed ' ,
58
- zIndex : 9999 ,
61
+ position : 'absolute ' ,
62
+ pointerEvents : 'auto' ,
59
63
} }
60
64
{ ...getFloatingProps ( ) }
61
65
>
62
66
{ tooltipContent }
63
- </ div >
67
+ </ div > ,
68
+ viewportRef . current
64
69
) }
65
70
</ >
66
71
) ;
Original file line number Diff line number Diff line change @@ -12,12 +12,14 @@ interface AnnotationHighlightLayerProps {
12
12
} ) => React . ReactNode ;
13
13
focusedAnnotationId ?: string ;
14
14
onAnnotationClick ?: ( annotation : Annotation ) => void ;
15
+ tooltipClassName ?: string ;
15
16
}
16
17
17
18
export const AnnotationHighlightLayer = ( {
18
19
className,
19
20
style,
20
21
renderTooltipContent,
22
+ tooltipClassName,
21
23
focusedAnnotationId,
22
24
onAnnotationClick,
23
25
} : AnnotationHighlightLayerProps ) => {
@@ -34,6 +36,7 @@ export const AnnotationHighlightLayer = ({
34
36
< AnnotationTooltip
35
37
key = { annotation . id }
36
38
annotation = { annotation }
39
+ className = { tooltipClassName }
37
40
isOpen = { focusedAnnotationId === annotation . id }
38
41
onOpenChange = { ( open ) => {
39
42
if ( open && onAnnotationClick ) {
You can’t perform that action at this time.
0 commit comments