import * as React from "react" import { getNumberItemsWidthByNumberOfChars } from "../helpers" export enum NumberOfChildrenPlacement { /** * Don't show the top right corner box indicating number of children */ None, TopRight, BottomRight, } interface NumberOfChildrenProps { id: number width: number height: number textColor: string borderColor: string bgColor: string nodeTotalNodes: number isSelectedNode: boolean placement: NumberOfChildrenPlacement style: React.CSSProperties } const NumberOfChildren: React.FunctionComponent = ({ id, width, height, textColor, borderColor, bgColor, nodeTotalNodes, isSelectedNode, placement, style, }) => { const realPlacement = isSelectedNode ? NumberOfChildrenPlacement.TopRight : placement const fontSize = Number(style.fontSize) const itemsWidth = getNumberItemsWidthByNumberOfChars( fontSize, nodeTotalNodes.toString().length ) const itemHeightFactor = 2 const itemsHeight = fontSize + itemHeightFactor const strokeDasharrayTotal = itemsWidth + itemsHeight if (width > itemsWidth && height > itemsHeight) { return ( {nodeTotalNodes} ) } return null } export default NumberOfChildren