Revert back to passing props manually

This commit is contained in:
peterkogo
2024-12-04 11:12:49 +01:00
parent 8b8ef2bffa
commit 3526963f0b
6 changed files with 127 additions and 34 deletions
@@ -21,27 +21,10 @@ export function BaseEdge({
interactionWidth = 20, interactionWidth = 20,
...props ...props
}: BaseEdgeProps) { }: BaseEdgeProps) {
// We are not allowed to pass these props to the path element otherwise we get a bunch of warnings
const {
animated,
selectable,
deletable,
data,
selected,
source,
target,
targetHandleId,
sourceHandleId,
targetPosition,
sourcePosition,
pathOptions,
...restProps
} = props as EdgeComponentWithPathOptions<any> & EdgeProps;
return ( return (
<> <>
<path <path
{...restProps} {...props}
id={id} id={id}
d={path} d={path}
fill="none" fill="none"
@@ -15,8 +15,17 @@ function createBezierEdge(params: { isInternal: boolean }) {
targetY, targetY,
sourcePosition = Position.Bottom, sourcePosition = Position.Bottom,
targetPosition = Position.Top, targetPosition = Position.Top,
label,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
markerEnd,
markerStart,
pathOptions, pathOptions,
...props interactionWidth,
}: BezierEdgeProps) => { }: BezierEdgeProps) => {
const [path, labelX, labelY] = getBezierPath({ const [path, labelX, labelY] = getBezierPath({
sourceX, sourceX,
@@ -30,7 +39,24 @@ function createBezierEdge(params: { isInternal: boolean }) {
const _id = params.isInternal ? undefined : id; const _id = params.isInternal ? undefined : id;
return <BaseEdge {...props} id={_id} path={path} labelX={labelX} labelY={labelY} />; return (
<BaseEdge
id={_id}
path={path}
labelX={labelX}
labelY={labelY}
label={label}
labelStyle={labelStyle}
labelShowBg={labelShowBg}
labelBgStyle={labelBgStyle}
labelBgPadding={labelBgPadding}
labelBgBorderRadius={labelBgBorderRadius}
style={style}
markerEnd={markerEnd}
markerStart={markerStart}
interactionWidth={interactionWidth}
/>
);
} }
); );
} }
@@ -82,7 +82,16 @@ function createSimpleBezierEdge(params: { isInternal: boolean }) {
targetY, targetY,
sourcePosition = Position.Bottom, sourcePosition = Position.Bottom,
targetPosition = Position.Top, targetPosition = Position.Top,
...props label,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
markerEnd,
markerStart,
interactionWidth,
}: SimpleBezierEdgeProps) => { }: SimpleBezierEdgeProps) => {
const [path, labelX, labelY] = getSimpleBezierPath({ const [path, labelX, labelY] = getSimpleBezierPath({
sourceX, sourceX,
@@ -95,7 +104,24 @@ function createSimpleBezierEdge(params: { isInternal: boolean }) {
const _id = params.isInternal ? undefined : id; const _id = params.isInternal ? undefined : id;
return <BaseEdge {...props} id={_id} path={path} labelX={labelX} labelY={labelY} />; return (
<BaseEdge
id={_id}
path={path}
labelX={labelX}
labelY={labelY}
label={label}
labelStyle={labelStyle}
labelShowBg={labelShowBg}
labelBgStyle={labelBgStyle}
labelBgPadding={labelBgPadding}
labelBgBorderRadius={labelBgBorderRadius}
style={style}
markerEnd={markerEnd}
markerStart={markerStart}
interactionWidth={interactionWidth}
/>
);
} }
); );
} }
@@ -13,10 +13,19 @@ function createSmoothStepEdge(params: { isInternal: boolean }) {
sourceY, sourceY,
targetX, targetX,
targetY, targetY,
label,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
sourcePosition = Position.Bottom, sourcePosition = Position.Bottom,
targetPosition = Position.Top, targetPosition = Position.Top,
markerEnd,
markerStart,
pathOptions, pathOptions,
...props interactionWidth,
}: SmoothStepEdgeProps) => { }: SmoothStepEdgeProps) => {
const [path, labelX, labelY] = getSmoothStepPath({ const [path, labelX, labelY] = getSmoothStepPath({
sourceX, sourceX,
@@ -31,7 +40,24 @@ function createSmoothStepEdge(params: { isInternal: boolean }) {
const _id = params.isInternal ? undefined : id; const _id = params.isInternal ? undefined : id;
return <BaseEdge {...props} id={_id} path={path} labelX={labelX} labelY={labelY} />; return (
<BaseEdge
id={_id}
path={path}
labelX={labelX}
labelY={labelY}
label={label}
labelStyle={labelStyle}
labelShowBg={labelShowBg}
labelBgStyle={labelBgStyle}
labelBgPadding={labelBgPadding}
labelBgBorderRadius={labelBgBorderRadius}
style={style}
markerEnd={markerEnd}
markerStart={markerStart}
interactionWidth={interactionWidth}
/>
);
} }
); );
} }
@@ -6,13 +6,48 @@ import type { StraightEdgeProps } from '../../types';
function createStraightEdge(params: { isInternal: boolean }) { function createStraightEdge(params: { isInternal: boolean }) {
// eslint-disable-next-line react/display-name // eslint-disable-next-line react/display-name
return memo(({ id, sourceX, sourceY, targetX, targetY, ...props }: StraightEdgeProps) => { return memo(
const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY }); ({
id,
sourceX,
sourceY,
targetX,
targetY,
label,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
markerEnd,
markerStart,
interactionWidth,
}: StraightEdgeProps) => {
const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY });
const _id = params.isInternal ? undefined : id; const _id = params.isInternal ? undefined : id;
return <BaseEdge {...props} id={_id} path={path} labelX={labelX} labelY={labelY} />; return (
}); <BaseEdge
id={_id}
path={path}
labelX={labelX}
labelY={labelY}
label={label}
labelStyle={labelStyle}
labelShowBg={labelShowBg}
labelBgStyle={labelBgStyle}
labelBgPadding={labelBgPadding}
labelBgBorderRadius={labelBgBorderRadius}
style={style}
markerEnd={markerEnd}
markerStart={markerStart}
interactionWidth={interactionWidth}
/>
);
}
);
} }
const StraightEdge = createStraightEdge({ isInternal: false }); const StraightEdge = createStraightEdge({ isInternal: false });
+2 -5
View File
@@ -125,13 +125,11 @@ export type EdgeProps<EdgeType extends Edge = Edge> = Pick<
interactionWidth?: number; interactionWidth?: number;
}; };
type BasePathAttributes = Omit<SVGAttributes<SVGPathElement>, 'd'>;
/** /**
* BaseEdge component props * BaseEdge component props
* @public * @public
*/ */
export type BaseEdgeProps = BasePathAttributes & export type BaseEdgeProps = Omit<SVGAttributes<SVGPathElement>, 'd'> &
EdgeLabelOptions & { EdgeLabelOptions & {
/** Additional padding where interacting with an edge is still possible */ /** Additional padding where interacting with an edge is still possible */
interactionWidth?: number; interactionWidth?: number;
@@ -155,8 +153,7 @@ export type BaseEdgeProps = BasePathAttributes &
* Helper type for edge components that get exported by the library * Helper type for edge components that get exported by the library
* @public * @public
*/ */
export type EdgeComponentProps = BasePathAttributes & export type EdgeComponentProps = EdgePosition &
EdgePosition &
EdgeLabelOptions & { EdgeLabelOptions & {
id?: EdgeProps['id']; id?: EdgeProps['id'];
markerStart?: EdgeProps['markerStart']; markerStart?: EdgeProps['markerStart'];