refactor(connectionLine): cleanup props #2300
This commit is contained in:
@@ -2,26 +2,26 @@ import React, { FC } from 'react';
|
|||||||
import { ConnectionLineComponentProps } from '@react-flow/core';
|
import { ConnectionLineComponentProps } from '@react-flow/core';
|
||||||
|
|
||||||
const ConnectionLine: FC<ConnectionLineComponentProps> = ({
|
const ConnectionLine: FC<ConnectionLineComponentProps> = ({
|
||||||
sourceX,
|
fromX,
|
||||||
sourceY,
|
fromY,
|
||||||
targetX,
|
toX,
|
||||||
targetY,
|
toY,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<g>
|
<g>
|
||||||
<path
|
<path
|
||||||
fill='none'
|
fill="none"
|
||||||
stroke='#222'
|
stroke="#222"
|
||||||
strokeWidth={1.5}
|
strokeWidth={1.5}
|
||||||
className='animated'
|
className="animated"
|
||||||
d={`M${sourceX},${sourceY} C ${sourceX} ${targetY} ${sourceX} ${targetY} ${targetX},${targetY}`}
|
d={`M${fromX},${fromY} C ${fromX} ${toY} ${fromX} ${toY} ${toX},${toY}`}
|
||||||
/>
|
/>
|
||||||
<circle
|
<circle
|
||||||
cx={targetX}
|
cx={toX}
|
||||||
cy={targetY}
|
cy={toY}
|
||||||
fill='#fff'
|
fill="#fff"
|
||||||
r={3}
|
r={3}
|
||||||
stroke='#222'
|
stroke="#222"
|
||||||
strokeWidth={1.5}
|
strokeWidth={1.5}
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
|
|||||||
@@ -65,36 +65,6 @@ export default ({
|
|||||||
|
|
||||||
let toPosition: Position = oppositePosition[fromPosition];
|
let toPosition: Position = oppositePosition[fromPosition];
|
||||||
|
|
||||||
let sourceX: number,
|
|
||||||
sourceY: number,
|
|
||||||
sourcePosition: Position | undefined,
|
|
||||||
targetX: number,
|
|
||||||
targetY: number,
|
|
||||||
targetPosition: Position | undefined;
|
|
||||||
|
|
||||||
switch (connectionHandleType) {
|
|
||||||
case 'source':
|
|
||||||
{
|
|
||||||
sourceX = fromX;
|
|
||||||
sourceY = fromY;
|
|
||||||
sourcePosition = fromPosition;
|
|
||||||
targetX = toX;
|
|
||||||
targetY = toY;
|
|
||||||
targetPosition = toPosition;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'target':
|
|
||||||
{
|
|
||||||
sourceX = toX;
|
|
||||||
sourceY = toY;
|
|
||||||
sourcePosition = toPosition;
|
|
||||||
targetX = fromX;
|
|
||||||
targetY = fromY;
|
|
||||||
targetPosition = fromPosition;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CustomConnectionLineComponent) {
|
if (CustomConnectionLineComponent) {
|
||||||
return (
|
return (
|
||||||
<g className="react-flow__connection">
|
<g className="react-flow__connection">
|
||||||
@@ -109,15 +79,6 @@ export default ({
|
|||||||
toY={toY}
|
toY={toY}
|
||||||
fromPosition={fromPosition}
|
fromPosition={fromPosition}
|
||||||
toPosition={toPosition}
|
toPosition={toPosition}
|
||||||
// remove in v11
|
|
||||||
sourcePosition={sourcePosition}
|
|
||||||
targetPosition={targetPosition}
|
|
||||||
sourceNode={fromNode}
|
|
||||||
sourceHandle={fromHandle}
|
|
||||||
targetX={targetX}
|
|
||||||
targetY={targetY}
|
|
||||||
sourceX={sourceX}
|
|
||||||
sourceY={sourceY}
|
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
);
|
);
|
||||||
@@ -126,12 +87,12 @@ export default ({
|
|||||||
let dAttr: string = '';
|
let dAttr: string = '';
|
||||||
|
|
||||||
const pathParams = {
|
const pathParams = {
|
||||||
sourceX,
|
sourceX: fromX,
|
||||||
sourceY,
|
sourceY: fromY,
|
||||||
sourcePosition,
|
sourcePosition: fromPosition,
|
||||||
targetX,
|
targetX: toX,
|
||||||
targetY,
|
targetY: toY,
|
||||||
targetPosition,
|
targetPosition: toPosition,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (connectionLineType === ConnectionLineType.Bezier) {
|
if (connectionLineType === ConnectionLineType.Bezier) {
|
||||||
@@ -147,7 +108,7 @@ export default ({
|
|||||||
} else if (connectionLineType === ConnectionLineType.SimpleBezier) {
|
} else if (connectionLineType === ConnectionLineType.SimpleBezier) {
|
||||||
dAttr = getSimpleBezierPath(pathParams);
|
dAttr = getSimpleBezierPath(pathParams);
|
||||||
} else {
|
} else {
|
||||||
dAttr = `M${sourceX},${sourceY} ${targetX},${targetY}`;
|
dAttr = `M${fromX},${fromY} ${toX},${toY}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -158,15 +158,6 @@ export type ConnectionLineComponentProps = {
|
|||||||
toY: number;
|
toY: number;
|
||||||
fromPosition: Position;
|
fromPosition: Position;
|
||||||
toPosition: Position;
|
toPosition: Position;
|
||||||
// remove in v11
|
|
||||||
sourceX: number;
|
|
||||||
sourceY: number;
|
|
||||||
sourcePosition?: Position;
|
|
||||||
targetX: number;
|
|
||||||
targetY: number;
|
|
||||||
targetPosition?: Position;
|
|
||||||
sourceNode?: Node;
|
|
||||||
sourceHandle?: HandleElement;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ConnectionLineComponent = ComponentType<ConnectionLineComponentProps>;
|
export type ConnectionLineComponent = ComponentType<ConnectionLineComponentProps>;
|
||||||
|
|||||||
Reference in New Issue
Block a user