index.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from "react";
  2. import { Node, NodeProps } from "reaflow";
  3. import useGraph from "src/hooks/store/useGraph";
  4. import ObjectNode from "./ObjectNode";
  5. import TextNode from "./TextNode";
  6. export interface CustomNodeProps<T> {
  7. width: number;
  8. height: number;
  9. value: T;
  10. isParent?: boolean;
  11. x: number;
  12. y: number;
  13. }
  14. export const CustomNode = (nodeProps: NodeProps) => {
  15. const { properties } = nodeProps;
  16. return (
  17. <Node {...nodeProps} label={<React.Fragment />}>
  18. {({ width, height, x, y, node }) => {
  19. if (Array.isArray(properties.text)) {
  20. return (
  21. <ObjectNode
  22. value={properties.text}
  23. width={width}
  24. height={height}
  25. x={x}
  26. y={y}
  27. />
  28. );
  29. }
  30. return (
  31. <TextNode
  32. node={node as NodeData}
  33. isParent={properties.data.isParent}
  34. value={properties.text}
  35. width={width}
  36. height={height}
  37. hasCollapse={properties.data.hasChild}
  38. x={x}
  39. y={y}
  40. />
  41. );
  42. }}
  43. </Node>
  44. );
  45. };