package.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { register } from "@antv/x6-react-shape";
  2. import { Graph, Node } from "@antv/x6";
  3. import CustomInput from "../../CustomInput";
  4. import { useSizeHook, useShapeProps } from "../../../hooks";
  5. const component = ({ node }: { node: Node }) => {
  6. const { label, text, fill, stroke, opacity, name } = node.getData();
  7. const { size, ref } = useSizeHook();
  8. const {
  9. fillContent,
  10. defsContent,
  11. strokeColor,
  12. strokeWidth,
  13. strokeDasharray,
  14. } = useShapeProps(fill, size, stroke);
  15. const { width, height } = size;
  16. const circleSize = 4;
  17. const handleSetName = (val: string) => {
  18. node.setData({ name: val });
  19. };
  20. return (
  21. <>
  22. <div
  23. className="relative text-0 w-full h-full"
  24. ref={ref}
  25. style={{ opacity: opacity / 100 }}
  26. >
  27. {/* 包名 */}
  28. <div className="absolute w-full h-25px top-0 left-0 pl-8px">
  29. <CustomInput value={name} styles={text} node={node} notSetData={true} onChange={handleSetName} />
  30. </div>
  31. {/* 文本 */}
  32. <div className="absolute w-full top-25px left-0" style={{height: height - 25}}>
  33. <CustomInput value={label} styles={text} node={node} notSetData={true} onChange={handleSetName} />
  34. </div>
  35. <svg
  36. className="w-full h-full"
  37. viewBox={`0 0 ${size?.width} ${size?.height}`}
  38. xmlns="http://www.w3.org/2000/svg"
  39. >
  40. <defs>{defsContent}</defs>
  41. <path
  42. d={`
  43. M ${strokeWidth}, 25
  44. L ${width - strokeWidth - circleSize}, 25
  45. Q ${width - strokeWidth}, 25 ${width - strokeWidth},${25 + circleSize}
  46. L ${width - strokeWidth}, ${height - strokeWidth - circleSize}
  47. Q ${width - strokeWidth}, ${height - strokeWidth} ${width - strokeWidth - circleSize},${height - strokeWidth}
  48. L ${strokeWidth + circleSize}, ${height - strokeWidth}
  49. Q ${strokeWidth}, ${height - strokeWidth} ${strokeWidth},${height - strokeWidth - circleSize}
  50. L ${strokeWidth}, ${25 + circleSize}
  51. Z
  52. M ${strokeWidth}, 25
  53. L ${strokeWidth}, ${circleSize}
  54. Q ${strokeWidth}, ${strokeWidth} ${circleSize},${strokeWidth}
  55. L ${width * 0.7 - circleSize }, ${strokeWidth}
  56. Q ${width * 0.7}, ${1} ${width * 0.7 + circleSize},${circleSize}
  57. L ${width * 0.76 }, 25
  58. Z
  59. `}
  60. fill={fillContent}
  61. stroke={strokeColor}
  62. strokeDasharray={strokeDasharray}
  63. strokeWidth={strokeWidth}
  64. />
  65. </svg>
  66. </div>
  67. </>
  68. );
  69. };
  70. register({
  71. shape: "custom-react-package",
  72. width: 210,
  73. height: 150,
  74. effect: ["data"],
  75. component: component,
  76. });
  77. const Package = {
  78. name: "包",
  79. icon: require("./image/package.png"),
  80. node: {
  81. shape: "custom-react-package",
  82. data: {
  83. label: "",
  84. // 包名
  85. name: "包名称",
  86. text: {
  87. textAlign: 'left',
  88. }
  89. },
  90. },
  91. };
  92. export default Package;