class1.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { register } from "@antv/x6-react-shape";
  2. import { Node } from "@antv/x6";
  3. import CustomInput from "../../CustomInput";
  4. import { useSizeHook, useShapeProps } from "../../../hooks";
  5. const component = ({ node }: { node: Node }) => {
  6. const { label, text1, text2, text, fill, stroke, opacity } = 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 || { width: 0, height: 0 };
  16. return (
  17. <>
  18. <div
  19. className="relative text-0 w-full h-full"
  20. ref={ref}
  21. style={{ opacity: opacity / 100 }}
  22. >
  23. <svg
  24. className="w-full h-full absolute top-0 left-0"
  25. viewBox={`0 0 ${size?.width} ${size?.height}`}
  26. xmlns="http://www.w3.org/2000/svg"
  27. >
  28. <defs>{defsContent}</defs>
  29. <rect
  30. x={strokeWidth}
  31. y={strokeWidth}
  32. rx={4}
  33. ry={4}
  34. width={size?.width - strokeWidth * 2}
  35. height={size?.height - strokeWidth * 2}
  36. fill={fillContent}
  37. stroke={strokeColor}
  38. strokeDasharray={strokeDasharray}
  39. strokeWidth={strokeWidth}
  40. />
  41. <path
  42. d={`
  43. M ${strokeWidth}, 30
  44. L ${width - strokeWidth}, 30
  45. M ${strokeWidth}, ${height / 2 + 15}
  46. L ${width - strokeWidth}, ${height / 2 + 15}
  47. `}
  48. stroke={strokeColor}
  49. strokeWidth={strokeWidth}
  50. />
  51. </svg>
  52. {/* 类名 */}
  53. <div className="w-full h-30px relative">
  54. <CustomInput value={label} styles={text} node={node} />
  55. </div>
  56. {/* 属性 */}
  57. <div
  58. className="w-full relative"
  59. style={{
  60. height: (height - 30 - 3 * strokeWidth) / 2,
  61. marginTop: strokeWidth,
  62. }}
  63. >
  64. <CustomInput
  65. value={text1}
  66. styles={{
  67. ...text,
  68. textAlign: "left",
  69. bold: false
  70. }}
  71. node={node}
  72. notSetData={true}
  73. onChange={(val) => {
  74. node.setData({ text1: val });
  75. }}
  76. />
  77. </div>
  78. {/* 方法 */}
  79. <div
  80. className="w-full relative"
  81. style={{
  82. height: (height - 30 - 3 * strokeWidth) / 2,
  83. marginTop: strokeWidth,
  84. }}
  85. >
  86. <CustomInput
  87. value={text2}
  88. styles={{
  89. ...text,
  90. textAlign: "left",
  91. bold: false
  92. }}
  93. node={node}
  94. notSetData={true}
  95. onChange={(val) => {
  96. node.setData({ text2: val });
  97. }}
  98. />
  99. </div>
  100. </div>
  101. </>
  102. );
  103. };
  104. register({
  105. shape: "custom-react-class1",
  106. width: 230,
  107. height: 150,
  108. effect: ["data"],
  109. component: component,
  110. });
  111. const class1 = {
  112. name: "类",
  113. icon: require("./image/class1.png"),
  114. node: {
  115. shape: "custom-react-class1",
  116. data: {
  117. label: "类名",
  118. // 属性
  119. text1:
  120. `+ attribute1:type = defaultValue
  121. + attribute2:type
  122. - attribute3:type`,
  123. // 方法
  124. text2:
  125. `+ operation1(params):returnType
  126. - operation2(params)
  127. - operation3()`,
  128. text: {
  129. bold: true
  130. }
  131. },
  132. },
  133. };
  134. export default class1;