<EdgeText />

GitHub上のソース

<EdgeText /> コンポーネントは、カスタムエッジ内にテキストを表示するためのヘルパーコンポーネントとして使用できます。

import { EdgeText } from '@xyflow/react';
 
export function CustomEdgeLabel({ label }) {
  return (
    <EdgeText
      x={100}
      y={100}
      label={label}
      labelStyle={{ fill: 'white' }}
      labelShowBg
      labelBgStyle={{ fill: 'red' }}
      labelBgPadding={[2, 4]}
      labelBgBorderRadius={2}
    />
  );
}

プロパティ

TypeScriptユーザーの場合、<EdgeText />コンポーネントのプロパティ型はEdgeTextPropsとしてエクスポートされます。

#x
number
ラベルを表示する x 位置。
#y
number
ラベルを表示する y 位置。
#label
string | React.ReactNode
エッジに沿ってレンダリングするテキストまたはラベル。
#labelStyle
ラベルに適用するカスタムスタイル。
{}
#labelShowBg
boolean
#labelBgStyle
#labelBgPadding
[number, number]
#labelBgBorderRadius
number

さらに、onClickclassNameなどの標準的なReact HTML属性も渡すことができます。