From 8f682b5b3daa96796f875dcb98a8bfd60cb378ac Mon Sep 17 00:00:00 2001 From: Stephen Nease Date: Tue, 24 Sep 2024 13:16:12 -0400 Subject: [PATCH] Add the ability to override pointerEvents on Annotations --- .../visx-annotation/src/components/CircleSubject.tsx | 7 ++++++- packages/visx-annotation/src/components/Connector.tsx | 9 +++++++-- packages/visx-annotation/src/components/HtmlLabel.tsx | 4 +++- packages/visx-annotation/src/components/Label.tsx | 7 ++++++- packages/visx-annotation/src/components/LineSubject.tsx | 7 ++++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/visx-annotation/src/components/CircleSubject.tsx b/packages/visx-annotation/src/components/CircleSubject.tsx index 5ae2a1279..d86217286 100644 --- a/packages/visx-annotation/src/components/CircleSubject.tsx +++ b/packages/visx-annotation/src/components/CircleSubject.tsx @@ -6,6 +6,10 @@ import AnnotationContext from '../context/AnnotationContext'; export type CircleSubjectProps = Pick & { /** Optional className to apply to CircleSubject in addition to 'visx-annotation-subject'. */ className?: string; + /** Allows you to customize the pointerEvents attribute on the `` element. + * + * Default: `"none"` */ + pointerEvents?: React.SVGAttributes['pointerEvents']; /** Color of CircleSubject. */ stroke?: string; /** Radius of CircleSubject. */ @@ -16,6 +20,7 @@ export default function CircleSubject({ className, x: propsX, y: propsY, + pointerEvents = 'none', stroke = '#222', radius = 16, ...restProps @@ -30,7 +35,7 @@ export default function CircleSubject({ cy={propsY || annotationContext.y} r={radius} fill="transparent" - pointerEvents="none" + pointerEvents={pointerEvents} stroke={stroke} {...restProps} /> diff --git a/packages/visx-annotation/src/components/Connector.tsx b/packages/visx-annotation/src/components/Connector.tsx index 4391af2bd..92a9c5dd0 100644 --- a/packages/visx-annotation/src/components/Connector.tsx +++ b/packages/visx-annotation/src/components/Connector.tsx @@ -14,7 +14,11 @@ export type ConnectorProps = Pick; + pathProps?: Omit, 'pointerEvents'>; + /** Allows you to customize the pointerEvents attribute on the `` element. + * + * Default: `"none"` */ + pointerEvents?: React.SVGAttributes['pointerEvents']; }; export default function Connector({ @@ -26,6 +30,7 @@ export default function Connector({ type = 'elbow', stroke = '#222', pathProps, + pointerEvents = 'none', }: ConnectorProps) { // if props are provided, they take precedence over context const annotationContext = useContext(AnnotationContext); @@ -63,7 +68,7 @@ export default function Connector({ strokeWidth={1} stroke={stroke} fill="transparent" - pointerEvents="none" + pointerEvents={pointerEvents} d={`M${x0},${y0}${type === 'elbow' ? `L${x1},${y1}` : ''}L${x2},${y2}`} {...pathProps} /> diff --git a/packages/visx-annotation/src/components/HtmlLabel.tsx b/packages/visx-annotation/src/components/HtmlLabel.tsx index 9b6302476..1ae07647d 100644 --- a/packages/visx-annotation/src/components/HtmlLabel.tsx +++ b/packages/visx-annotation/src/components/HtmlLabel.tsx @@ -13,6 +13,7 @@ export type HtmlLabelProps = Pick< | 'anchorLineStroke' | 'className' | 'horizontalAnchor' + | 'pointerEvents' | 'resizeObserverPolyfill' | 'showAnchorLine' | 'verticalAnchor' @@ -30,6 +31,7 @@ export default function HtmlLabel({ className, containerStyle, horizontalAnchor: propsHorizontalAnchor, + pointerEvents = 'none', resizeObserverPolyfill, showAnchorLine = true, verticalAnchor: propsVerticalAnchor, @@ -67,7 +69,7 @@ export default function HtmlLabel({ diff --git a/packages/visx-annotation/src/components/Label.tsx b/packages/visx-annotation/src/components/Label.tsx index 4bc03e95f..06f664bf6 100644 --- a/packages/visx-annotation/src/components/Label.tsx +++ b/packages/visx-annotation/src/components/Label.tsx @@ -21,6 +21,10 @@ export type LabelProps = { fontColor?: string; /** Whether the label is horizontally anchored to the start, middle, or end of its x position. */ horizontalAnchor?: TextProps['textAnchor']; + /** Allows you to customize the pointerEvents attribute on the Group (``) wrapper of the Annotation. + * + * Default: `"none"` */ + pointerEvents?: React.SVGAttributes['pointerEvents']; /** Optionally inject a ResizeObserver polyfill, else this *must* be globally available. */ resizeObserverPolyfill?: UseMeasureOptions['polyfill']; /** Whether to render a line indicating label text anchor. */ @@ -75,6 +79,7 @@ export default function Label({ className, fontColor = '#222', horizontalAnchor: propsHorizontalAnchor, + pointerEvents = 'none', resizeObserverPolyfill, showAnchorLine = true, showBackground = true, @@ -190,7 +195,7 @@ export default function Label({ diff --git a/packages/visx-annotation/src/components/LineSubject.tsx b/packages/visx-annotation/src/components/LineSubject.tsx index 2876d509e..fa7821fb8 100644 --- a/packages/visx-annotation/src/components/LineSubject.tsx +++ b/packages/visx-annotation/src/components/LineSubject.tsx @@ -11,6 +11,10 @@ export type LineSubjectProps = { strokeWidth?: number; /** Orientation of line. */ orientation?: 'vertical' | 'horizontal'; + /** Allows you to customize the pointerEvents attribute on the `` element. + * + * Default: `"none"` */ + pointerEvents?: React.SVGAttributes['pointerEvents']; /** x position of LineSubject (for vertical LineSubjects). */ x?: number; /** y position of LineSubject (for horizontal LineSubjects). */ @@ -26,6 +30,7 @@ export default function LineSubject({ x: propsX, y: propsY, orientation = 'vertical', + pointerEvents = 'none', min, max, stroke = '#222', @@ -43,7 +48,7 @@ export default function LineSubject({ y1={lineIsVertical ? min : propsY || annotationContext.y} y2={lineIsVertical ? max : propsY || annotationContext.y} fill="transparent" - pointerEvents="none" + pointerEvents={pointerEvents} stroke={stroke} {...restProps} />