diff --git a/packages/demo-app-ts/src/demos/pipelinesDemo/DemoTaskNode.tsx b/packages/demo-app-ts/src/demos/pipelinesDemo/DemoTaskNode.tsx index 2c6a18c3..79dcc359 100644 --- a/packages/demo-app-ts/src/demos/pipelinesDemo/DemoTaskNode.tsx +++ b/packages/demo-app-ts/src/demos/pipelinesDemo/DemoTaskNode.tsx @@ -72,7 +72,7 @@ const DemoTaskNode: React.FunctionComponent = ({ }; return ( - + = ({ const data = element.getData(); const detailsLevel = element.getGraph().getDetailsLevel(); const [hover, hoverRef] = useHover(); + const focused = hover || contextMenuOpen; const passedData = React.useMemo(() => { const newData = { ...data }; @@ -154,18 +155,19 @@ const StyleNode: React.FunctionComponent = ({ const LabelIcon = passedData.labelIcon; return ( - + = ({ onHideCreateConnector={onHideCreateConnector} labelIcon={LabelIcon && } attachments={ - (hover || detailsLevel === ScaleDetailsLevel.high) && + (focused || detailsLevel === ScaleDetailsLevel.high) && renderDecorators(nodeElement, passedData, rest.getShapeDecoratorCenter) } > - {(hover || detailsLevel !== ScaleDetailsLevel.low) && renderIcon(passedData, nodeElement)} + {(focused || detailsLevel !== ScaleDetailsLevel.low) && renderIcon(passedData, nodeElement)} diff --git a/packages/demo-app-ts/src/demos/topologyPackageDemo/DemoNode.tsx b/packages/demo-app-ts/src/demos/topologyPackageDemo/DemoNode.tsx index cf64fab5..0010a906 100644 --- a/packages/demo-app-ts/src/demos/topologyPackageDemo/DemoNode.tsx +++ b/packages/demo-app-ts/src/demos/topologyPackageDemo/DemoNode.tsx @@ -147,12 +147,13 @@ const getShapeComponent = (shape: NodeShape): React.FunctionComponent = observer( - ({ element, onContextMenu, dragging, onShowCreateConnector, onHideCreateConnector, ...rest }) => { + ({ element, onContextMenu, dragging, contextMenuOpen, onShowCreateConnector, onHideCreateConnector, ...rest }) => { const options = React.useContext(DemoContext).nodeOptions; const nodeElement = element as Node; const data = element.getData() as GeneratedNodeData; const detailsLevel = element.getGraph().getDetailsLevel(); const [hover, hoverRef] = useHover(); + const focused = hover || contextMenuOpen; React.useEffect(() => { if (detailsLevel === ScaleDetailsLevel.low) { @@ -164,16 +165,18 @@ const DemoNode: React.FunctionComponent = observer( const LabelIcon = data.index % 2 === 1 ? (SignOutAltIcon as any) : undefined; return ( - + = observer( getCustomShape={options.showShapes ? () => getShapeComponent(data.shape) : undefined} badge={options.badges ? data.objectType : undefined} attachments={ - (hover || detailsLevel === ScaleDetailsLevel.high) && + (focused || detailsLevel === ScaleDetailsLevel.high) && options.showDecorators && renderDecorators(options, nodeElement, rest.getShapeDecoratorCenter) } > - {(hover || detailsLevel !== ScaleDetailsLevel.low) && renderIcon(data, nodeElement)} + {(focused || detailsLevel !== ScaleDetailsLevel.low) && renderIcon(data, nodeElement)} diff --git a/packages/module/src/components/nodes/DefaultNode.tsx b/packages/module/src/components/nodes/DefaultNode.tsx index c3420764..2b933f64 100644 --- a/packages/module/src/components/nodes/DefaultNode.tsx +++ b/packages/module/src/components/nodes/DefaultNode.tsx @@ -118,6 +118,8 @@ interface DefaultNodeProps { onContextMenu?: (e: React.MouseEvent) => void; /** Flag indicating that the context menu for the node is currently open */ contextMenuOpen?: boolean; + /** Flag indicating the label should move to the top layer when the node is hovered, set to `false` if you are already using TOP_LAYER on hover */ + raiseLabelOnHover?: boolean; // TODO: Update default to be false, assume demo code will be followed } const SCALE_UP_TIME = 200; @@ -166,7 +168,8 @@ const DefaultNodeInner: React.FunctionComponent = observe onHideCreateConnector, onShowCreateConnector, onContextMenu, - contextMenuOpen + contextMenuOpen, + raiseLabelOnHover = true }) => { const [hovered, hoverRef] = useHover(); const status = nodeStatus || element.getNodeStatus(); @@ -317,23 +320,72 @@ const DefaultNodeInner: React.FunctionComponent = observe return { translateX, translateY }; }, [element, nodeScale, scaleNode]); - let labelX; - let labelY; - const labelPaddingX = 8; - const labelPaddingY = 4; - if (nodeLabelPosition === LabelPosition.right) { - labelX = (width + labelPaddingX) * labelPositionScale; - labelY = height / 2; - } else if (nodeLabelPosition === LabelPosition.left) { - labelX = 0; - labelY = height / 2 - labelPaddingY; - } else if (nodeLabelPosition === LabelPosition.top) { - labelX = width / 2; - labelY = labelPaddingY + labelPaddingY / 2; - } else { - labelX = (width / 2) * labelPositionScale; - labelY = height + labelPaddingY + labelPaddingY / 2; - } + const renderLabel = () => { + if (!showLabel || !(label || element.getLabel())) { + return null; + } + + let labelX; + let labelY; + const labelPaddingX = 8; + const labelPaddingY = 4; + if (nodeLabelPosition === LabelPosition.right) { + labelX = (width + labelPaddingX) * labelPositionScale; + labelY = height / 2; + } else if (nodeLabelPosition === LabelPosition.left) { + labelX = 0; + labelY = height / 2 - labelPaddingY; + } else if (nodeLabelPosition === LabelPosition.top) { + labelX = width / 2; + labelY = labelPaddingY + labelPaddingY / 2; + } else { + labelX = (width / 2) * labelPositionScale; + labelY = height + labelPaddingY + labelPaddingY / 2; + } + + const nodeLabel = ( + + + + {label || element.getLabel()} + + + + ); + if (isHover && raiseLabelOnHover) { + return {nodeLabel}; + } + return nodeLabel; + }; + return ( = observe filter={filter} /> )} - {showLabel && (label || element.getLabel()) && ( - - - - - {label || element.getLabel()} - - - - - )} + {renderLabel()} {children} {statusDecorator} diff --git a/packages/module/src/components/nodes/labels/NodeLabel.tsx b/packages/module/src/components/nodes/labels/NodeLabel.tsx index 0f5d0ca7..f6fef1fb 100644 --- a/packages/module/src/components/nodes/labels/NodeLabel.tsx +++ b/packages/module/src/components/nodes/labels/NodeLabel.tsx @@ -86,7 +86,7 @@ const NodeLabel: React.FunctionComponent = ({ const [labelHover, labelHoverRef] = useHover(); const refs = useCombineRefs(dragRef, typeof truncateLength === 'number' ? labelHoverRef : undefined); - const [textSize, textRef] = useSize([children, truncateLength, className, labelHover]); + const [textSize, textRef] = useSize([children, truncateLength, className, labelHover, contextMenuOpen]); const [secondaryTextSize, secondaryTextRef] = useSize([secondaryLabel, truncateLength, className, labelHover]); const [badgeSize, badgeRef] = useSize([badge]); const [actionSize, actionRef] = useSize([actionIcon, paddingX]); @@ -266,7 +266,9 @@ const NodeLabel: React.FunctionComponent = ({ /> )} - {truncateLength > 0 && !labelHover ? truncateMiddle(children, { length: truncateLength }) : children} + {truncateLength > 0 && !labelHover && !contextMenuOpen + ? truncateMiddle(children, { length: truncateLength }) + : children} {textSize && actionIcon && ( <>