Spaces:
Running

FlowWeb / src /features /canvas /components /StickerEdge.jsx
danylokhodus's picture
Claude Opus 5.5
feat: quest board — web auto-layout, groups, archive, XP and rewards
2740e39
Raw History Blame Contribute Delete
2.21 kB
import React from 'react';
import { getBezierPath, BaseEdge, useInternalNode } from '@xyflow/react';
import { floatingPoints } from './floatingEdge';
export default function StickerEdge({
id,
source,
target,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
style = {},
selected,
interactionWidth,
}) {
const sourceNode = useInternalNode(source);
const targetNode = useInternalNode(target);
// Threads float between the facing sides of the sticker and its card
const p = sourceNode && targetNode
? floatingPoints(sourceNode, targetNode, {})
: { sx: sourceX, sy: sourceY, tx: targetX, ty: targetY, sourcePos: sourcePosition, targetPos: targetPosition };
const [edgePath] = getBezierPath({
sourceX: p.sx,
sourceY: p.sy,
sourcePosition: p.sourcePos,
targetX: p.tx,
targetY: p.ty,
targetPosition: p.targetPos,
curvature: 0.6, // More curved for a "hanging thread" feel
});
return (
<>
{/* Interaction area for easier clicking */}
<path
id={id}
style={{ fill: 'none', strokeWidth: 20, stroke: 'transparent' }}
className="react-flow__edge-interaction"
d={edgePath}
/>
{/* Shadow path */}
<BaseEdge
path={edgePath}
style={{
...style,
strokeWidth: 3,
stroke: 'rgba(0,0,0,0.1)',
fill: 'none',
transform: 'translate(1px, 2px)',
}}
/>
{/* Main Thread */}
<BaseEdge
path={edgePath}
style={{
...style,
strokeWidth: selected ? 3 : 2,
stroke: selected ? '#f59e0b' : '#94a3b8', // Amber when selected, slate otherwise
strokeDasharray: '5 3', // Slightly longer dashes
fill: 'none',
strokeLinecap: 'round',
transition: 'stroke 0.2s, stroke-width 0.2s',
}}
/>
{/* Optional: Small highlight on the thread */}
<BaseEdge
path={edgePath}
style={{
...style,
strokeWidth: 0.5,
stroke: 'rgba(255,255,255,0.4)',
fill: 'none',
strokeDasharray: '2 10',
}}
/>
</>
);
}