Skip to content

Commit 63824a9

Browse files
authored
fix: improve annotation placements on zoom (#69)
1 parent 4c4ce9b commit 63824a9

File tree

4 files changed

+189
-150
lines changed

4 files changed

+189
-150
lines changed

packages/docs/app/(home)/_components/anara.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const PDFContent = ({
125125
<TextLayer />
126126
<AnnotationHighlightLayer
127127
focusedAnnotationId={focusedAnnotationId}
128+
tooltipClassName="bg-white shadow-lg rounded-lg p-3 min-w-[200px]"
128129
onAnnotationClick={onAnnotationClick}
129130
renderTooltipContent={renderTooltipContent}
130131
/>

packages/lector/src/components/annotation-tooltip.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
21
import { useCallback} from "react";
2+
import { createPortal } from "react-dom";
33

44
import type { Annotation } from "../hooks/useAnnotations";
55
import { useAnnotationTooltip } from "../hooks/useAnnotationTooltip";
6+
import { usePdf } from "../internal";
67

78
interface AnnotationTooltipProps {
89
annotation: Annotation;
910
children: React.ReactNode;
1011
tooltipContent: React.ReactNode;
1112
onOpenChange?: (open: boolean) => void;
1213
isOpen?: boolean;
14+
className?: string;
1315
}
1416

1517
export const AnnotationTooltip = ({
1618
annotation,
1719
children,
1820
tooltipContent,
1921
onOpenChange,
22+
className,
2023
isOpen: controlledIsOpen,
2124
}: AnnotationTooltipProps) => {
25+
const viewportRef = usePdf((state) => state.viewportRef);
2226
const {
2327
isOpen: uncontrolledIsOpen,
2428
setIsOpen,
@@ -48,19 +52,20 @@ export const AnnotationTooltip = ({
4852
>
4953
{children}
5054
</div>
51-
{isOpen && (
55+
{isOpen && viewportRef.current && createPortal(
5256
<div
5357
ref={refs.setFloating}
54-
className="bg-white shadow-lg rounded-lg p-3 z-50 min-w-[200px]"
58+
className={className}
5559
style={{
5660
...floatingStyles,
57-
position: 'fixed',
58-
zIndex: 9999,
61+
position: 'absolute',
62+
pointerEvents: 'auto',
5963
}}
6064
{...getFloatingProps()}
6165
>
6266
{tooltipContent}
63-
</div>
67+
</div>,
68+
viewportRef.current
6469
)}
6570
</>
6671
);

packages/lector/src/components/layers/annotation-highlight-layer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ interface AnnotationHighlightLayerProps {
1212
}) => React.ReactNode;
1313
focusedAnnotationId?: string;
1414
onAnnotationClick?: (annotation: Annotation) => void;
15+
tooltipClassName?: string;
1516
}
1617

1718
export const AnnotationHighlightLayer = ({
1819
className,
1920
style,
2021
renderTooltipContent,
22+
tooltipClassName,
2123
focusedAnnotationId,
2224
onAnnotationClick,
2325
}: AnnotationHighlightLayerProps) => {
@@ -34,6 +36,7 @@ export const AnnotationHighlightLayer = ({
3436
<AnnotationTooltip
3537
key={annotation.id}
3638
annotation={annotation}
39+
className={tooltipClassName}
3740
isOpen={focusedAnnotationId === annotation.id}
3841
onOpenChange={(open) => {
3942
if (open && onAnnotationClick) {

0 commit comments

Comments
 (0)