From 0ca48c2b7f240fa735cd515284233cba74a7db48 Mon Sep 17 00:00:00 2001 From: moklick Date: Fri, 5 Mar 2021 20:49:14 +0100 Subject: [PATCH] refactor(edgeAnchor): add types, class name handling --- src/components/Edges/EdgeAnchor.tsx | 52 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/components/Edges/EdgeAnchor.tsx b/src/components/Edges/EdgeAnchor.tsx index a452ef39..9f68e6bb 100644 --- a/src/components/Edges/EdgeAnchor.tsx +++ b/src/components/Edges/EdgeAnchor.tsx @@ -1,42 +1,40 @@ -import React from 'react'; +import React, { FC, HTMLAttributes } from 'react'; +import cc from 'classcat'; import { Position } from '../../types'; -const shiftX = (x: number, shift: number, position: Position) => { +const shiftX = (x: number, shift: number, position: Position): number => { if (position === Position.Left) return x - shift; if (position === Position.Right) return x + shift; return x; -} +}; -const shiftY = (y: number, shift: number, position: Position) => { +const shiftY = (y: number, shift: number, position: Position): number => { if (position === Position.Top) return y - shift; if (position === Position.Bottom) return y + shift; return y; +}; + +export interface EdgeAnchorProps extends HTMLAttributes { + position: Position; + centerX: number; + centerY: number; + radius?: number; } -export interface EdgeAnchorProps { - className?: string - position: Position - centerX: number - centerY: number - radius?: number -} - -export const EdgeAnchor = ({ - className = "react-flow__edgeupdater", +export const EdgeAnchor: FC = ({ + className, position, centerX, centerY, - radius = 10 -}: EdgeAnchorProps): JSX.Element => { - return ( - - ); -} + radius = 10, +}: EdgeAnchorProps) => ( + +);