Skip to Content
参考手册组件

<EdgeLabelRenderer />

GitHub 上的源代码

¥Source on GitHub

边缘基于 SVG。如果你想渲染更复杂的标签,你可以使用 <EdgeLabelRenderer /> 组件访问基于 div 的渲染器。此组件是一个门户,它将标签渲染在位于边缘顶部的 <div /> 中。你可以在 边缘标签渲染器 示例中看到组件的示例用法。

¥Edges are SVG-based. If you want to render more complex labels you can use the <EdgeLabelRenderer /> component to access a div based renderer. This component is a portal that renders the label in a <div /> that is positioned on top of the edges. You can see an example usage of the component in the edge label renderer example.

import React from 'react'; import { getBezierPath, EdgeLabelRenderer, BaseEdge } from '@xyflow/react'; const CustomEdge = ({ id, data, ...props }) => { const [edgePath, labelX, labelY] = getBezierPath(props); return ( <> <BaseEdge id={id} path={edgePath} /> <EdgeLabelRenderer> <div style={{ position: 'absolute', transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`, background: '#ffcc00', padding: 10, borderRadius: 5, fontSize: 12, fontWeight: 700, }} className="nodrag nopan" > {data.label} </div> </EdgeLabelRenderer> </> ); }; export default CustomEdge;

属性

¥Props

NameTypeDefault
childrenReactNode

注释

¥Notes

  • <EdgeLabelRenderer /> 默认没有指针事件。如果你想要添加鼠标交互,则需要设置样式 pointerEvents: 'all' 并在标签或你想要交互的元素上添加 nopan 类。

    ¥The <EdgeLabelRenderer /> has no pointer events by default. If you want to add mouse interactions you need to set the style pointerEvents: 'all' and add the nopan class on the label or the element you want to interact with.

Last updated on