Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the arrow and line element easier to grap #703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/quiet-starfishes-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@nordeck/matrix-neoboard-react-sdk': patch
'@nordeck/matrix-neoboard-widget': patch
---

Enhance the interactivity of arrows and lines by increasing the clickable area around them
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ describe('<Display />', () => {
<g
data-testid="element-element-0"
>
<line
fill="none"
stroke="transparent"
stroke-width="14"
x1="0"
x2="2"
y1="2"
y2="4"
/>
<line
fill="none"
stroke="#ffffff"
Expand Down Expand Up @@ -144,6 +153,15 @@ describe('<Display />', () => {
stroke="#ffffff"
/>
</marker>
<line
fill="none"
stroke="transparent"
stroke-width="14"
x1="0"
x2="2"
y1="2"
y2="4"
/>
<line
fill="none"
marker-end="url(#end-marker-id-1)"
Expand Down
14 changes: 14 additions & 0 deletions packages/react-sdk/src/components/elements/line/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
SelectableElement,
WithExtendedSelectionProps,
} from '../../Whiteboard';
import { useSvgCanvasContext } from '../../Whiteboard/SvgCanvas';
import { getRenderProperties } from './getRenderProperties';
import { useEndMarker } from './useEndMarker';

Expand All @@ -40,12 +41,25 @@ const LineDisplay = ({
strokeWidth,
points: { start, end },
} = getRenderProperties(element);
const { scale } = useSvgCanvasContext();
// Fallback to scale = 1 if scale is 0
const adjustedScale = scale === 0 ? 1 : scale;
const adjustedStrokeWidth = strokeWidth + 10 / adjustedScale;

const { endMarkerId, endMarker } = useEndMarker(element);

const renderedChild = (
<g data-testid={`element-${elementId}`}>
{endMarker}
<line
fill="none"
stroke="transparent"
strokeWidth={adjustedStrokeWidth}
x1={start.x}
x2={end.x}
y1={start.y}
y2={end.y}
/>
<line
fill="none"
stroke={strokeColor}
Expand Down
Loading