TopicNode.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 [playModeEnable] = useSessionStorageState(
  12. "playModeEnable",
  13. {
  14. listenStorageChange: true,
  15. }
  16. );
  17. const handleEdit = () => {
  18. setTabActiveKey("3");
  19. };
  20. return (
  21. <div
  22. className="w-full h-full"
  23. style={{
  24. border: "1px solid #666",
  25. borderRadius: "4px",
  26. background: style.background?.includes("#")
  27. ? `${style.background}88`
  28. : style.background,
  29. padding: "10px",
  30. }}
  31. onMouseEnter={() => setShowEdit(true)}
  32. onMouseLeave={() => setShowEdit(false)}
  33. >
  34. <div className="color-#fff flex items-center justify-between leading-22px">
  35. {name}{" "}
  36. {showEdit && !playModeEnable && (
  37. <div
  38. className="edit-btn w-22px h-22px rounded-md flex items-center justify-center bg-#658dbe cursor-pointer"
  39. onClick={handleEdit}
  40. >
  41. <i className="iconfont icon-bianji color-#fff text-12px" />
  42. </div>
  43. )}
  44. </div>
  45. </div>
  46. );
  47. };
  48. register({
  49. shape: "topic-node",
  50. component: TopicAreaNode,
  51. width: 300,
  52. height: 300,
  53. effect: ["data"],
  54. });