TopicNode.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { useEffect, useMemo, useRef } from "react";
  2. import { register } from "@antv/x6-react-shape";
  3. import { Graph, Node } from "@antv/x6";
  4. import type { TopicAreaInfo } from "@/type";
  5. import { useSessionStorageState } from "ahooks";
  6. const TopicAreaNode = ({ node, graph }: { node: Node; graph: Graph }) => {
  7. const { style, name } = node.getData<TopicAreaInfo>();
  8. const [showEdit, setShowEdit] = React.useState(false);
  9. const [_tabActiveKey, setTabActiveKey] =
  10. useSessionStorageState("tabs-active-key");
  11. const handleEdit = () => {
  12. setTabActiveKey("3");
  13. };
  14. return (
  15. <div
  16. className="w-full h-full"
  17. style={{
  18. border: "1px solid #666",
  19. borderRadius: "4px",
  20. background: style.background?.includes("#")
  21. ? `${style.background}88`
  22. : style.background,
  23. padding: "10px",
  24. }}
  25. onMouseEnter={() => setShowEdit(true)}
  26. onMouseLeave={() => setShowEdit(false)}
  27. >
  28. <div className="color-#fff flex items-center justify-between leading-22px">
  29. {name}{" "}
  30. {showEdit && (
  31. <div
  32. className="edit-btn w-22px h-22px rounded-md flex items-center justify-center bg-#658dbe cursor-pointer"
  33. onClick={handleEdit}
  34. >
  35. <i className="iconfont icon-bianji color-#fff text-12px" />
  36. </div>
  37. )}
  38. </div>
  39. </div>
  40. );
  41. };
  42. register({
  43. shape: "topic-node",
  44. component: TopicAreaNode,
  45. width: 300,
  46. height: 300,
  47. effect: ["data"],
  48. });