import { useMemo } from 'react'; import Point from '../../geom/Point'; import { css } from '@patternfly/react-styles'; import styles from '../../css/topology-components'; import { StatusModifier, useSize } from '../../utils'; import { NodeStatus } from '../../types'; interface DefaultConnectorTagProps { className?: string; startPoint: Point; endPoint: Point; tag: string; status?: NodeStatus; paddingX?: number; paddingY?: number; } const DefaultConnectorTag: React.FunctionComponent = ({ className, startPoint, endPoint, tag, status, paddingX = 4, paddingY = 2, ...other }) => { const [textSize, textRef] = useSize([tag, className]); const { width, height, startX, startY } = useMemo(() => { if (!textSize) { return { width: 0, height: 0, startX: 0, startY: 0 }; } const width = textSize ? textSize.width + paddingX * 2 : 0; const height = textSize ? textSize.height + paddingY * 2 : 0; const startX = -width / 2; const startY = -height / 2; return { width, height, startX, startY }; }, [textSize, paddingX, paddingY]); return ( {textSize && ( )} {tag} ); }; export default DefaultConnectorTag;