feat: accept any path element attribute as a prop

This commit is contained in:
Matt Huggins
2024-11-28 17:18:01 -06:00
parent 616d266523
commit 23b3fb64c5
6 changed files with 16 additions and 7 deletions
@@ -20,10 +20,12 @@ export function BaseEdge({
markerStart, markerStart,
className, className,
interactionWidth = 20, interactionWidth = 20,
...props
}: BaseEdgeProps) { }: BaseEdgeProps) {
return ( return (
<> <>
<path <path
{...props}
id={id} id={id}
style={style} style={style}
d={path} d={path}
@@ -26,6 +26,7 @@ function createBezierEdge(params: { isInternal: boolean }) {
markerStart, markerStart,
pathOptions, pathOptions,
interactionWidth, interactionWidth,
...props
}: BezierEdgeProps) => { }: BezierEdgeProps) => {
const [path, labelX, labelY] = getBezierPath({ const [path, labelX, labelY] = getBezierPath({
sourceX, sourceX,
@@ -41,6 +42,7 @@ function createBezierEdge(params: { isInternal: boolean }) {
return ( return (
<BaseEdge <BaseEdge
{...props}
id={_id} id={_id}
path={path} path={path}
labelX={labelX} labelX={labelX}
@@ -92,6 +92,7 @@ function createSimpleBezierEdge(params: { isInternal: boolean }) {
markerEnd, markerEnd,
markerStart, markerStart,
interactionWidth, interactionWidth,
...props
}: SimpleBezierEdgeProps) => { }: SimpleBezierEdgeProps) => {
const [path, labelX, labelY] = getSimpleBezierPath({ const [path, labelX, labelY] = getSimpleBezierPath({
sourceX, sourceX,
@@ -106,6 +107,7 @@ function createSimpleBezierEdge(params: { isInternal: boolean }) {
return ( return (
<BaseEdge <BaseEdge
{...props}
id={_id} id={_id}
path={path} path={path}
labelX={labelX} labelX={labelX}
@@ -26,6 +26,7 @@ function createSmoothStepEdge(params: { isInternal: boolean }) {
markerStart, markerStart,
pathOptions, pathOptions,
interactionWidth, interactionWidth,
...props
}: SmoothStepEdgeProps) => { }: SmoothStepEdgeProps) => {
const [path, labelX, labelY] = getSmoothStepPath({ const [path, labelX, labelY] = getSmoothStepPath({
sourceX, sourceX,
@@ -42,6 +43,7 @@ function createSmoothStepEdge(params: { isInternal: boolean }) {
return ( return (
<BaseEdge <BaseEdge
{...props}
id={_id} id={_id}
path={path} path={path}
labelX={labelX} labelX={labelX}
@@ -23,6 +23,7 @@ function createStraightEdge(params: { isInternal: boolean }) {
markerEnd, markerEnd,
markerStart, markerStart,
interactionWidth, interactionWidth,
...props
}: StraightEdgeProps) => { }: StraightEdgeProps) => {
const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY }); const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY });
@@ -30,6 +31,7 @@ function createStraightEdge(params: { isInternal: boolean }) {
return ( return (
<BaseEdge <BaseEdge
{...props}
id={_id} id={_id}
path={path} path={path}
labelX={labelX} labelX={labelX}
@@ -44,6 +46,7 @@ function createStraightEdge(params: { isInternal: boolean }) {
markerEnd={markerEnd} markerEnd={markerEnd}
markerStart={markerStart} markerStart={markerStart}
interactionWidth={interactionWidth} interactionWidth={interactionWidth}
{...props}
/> />
); );
} }
+5 -7
View File
@@ -92,6 +92,8 @@ export type EdgeWrapperProps<EdgeType extends Edge = Edge> = {
disableKeyboardA11y?: boolean; disableKeyboardA11y?: boolean;
}; };
type BasePathAttributes = Omit<HTMLAttributes<SVGPathElement>, "d">;
export type DefaultEdgeOptions = DefaultEdgeOptionsBase<Edge>; export type DefaultEdgeOptions = DefaultEdgeOptionsBase<Edge>;
export type EdgeTextProps = HTMLAttributes<SVGElement> & export type EdgeTextProps = HTMLAttributes<SVGElement> &
@@ -123,12 +125,9 @@ export type EdgeProps<EdgeType extends Edge = Edge> = Pick<
* BaseEdge component props * BaseEdge component props
* @public * @public
*/ */
export type BaseEdgeProps = EdgeLabelOptions & { export type BaseEdgeProps = BasePathAttributes & EdgeLabelOptions & {
/** Unique id of edge */
id?: string;
/** Additional padding where interacting with an edge is still possible */ /** Additional padding where interacting with an edge is still possible */
interactionWidth?: number; interactionWidth?: number;
className?: string;
/** The x position of edge label */ /** The x position of edge label */
labelX?: number; labelX?: number;
/** The y position of edge label */ /** The y position of edge label */
@@ -143,14 +142,13 @@ export type BaseEdgeProps = EdgeLabelOptions & {
markerEnd?: string; markerEnd?: string;
/** SVG path of the edge */ /** SVG path of the edge */
path: string; path: string;
style?: CSSProperties;
}; };
/** /**
* 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 = EdgePosition & export type EdgeComponentProps = BasePathAttributes & EdgePosition &
EdgeLabelOptions & { EdgeLabelOptions & {
id?: EdgeProps['id']; id?: EdgeProps['id'];
markerStart?: EdgeProps['markerStart']; markerStart?: EdgeProps['markerStart'];
@@ -187,7 +185,7 @@ export type StepEdgeProps = EdgeComponentWithPathOptions<StepPathOptions>;
* StraightEdge component props * StraightEdge component props
* @public * @public
*/ */
export type StraightEdgeProps = Omit<EdgeComponentProps, 'sourcePosition' | 'targetPosition'>; export type StraightEdgeProps = HTMLAttributes<SVGPathElement> & Omit<EdgeComponentProps, 'sourcePosition' | 'targetPosition'>;
/** /**
* SimpleBezier component props * SimpleBezier component props