simpleClass.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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, 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. return (
  16. <>
  17. <div
  18. className="relative text-0 w-full h-full"
  19. ref={ref}
  20. style={{ opacity: opacity / 100 }}
  21. >
  22. <CustomInput value={label} styles={text} node={node} />
  23. <svg
  24. className="w-full h-full"
  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. width={size?.width - strokeWidth * 2}
  33. height={size?.height - strokeWidth * 2}
  34. rx={4}
  35. ry={4}
  36. fill={fillContent}
  37. stroke={strokeColor}
  38. strokeDasharray={strokeDasharray}
  39. strokeWidth={strokeWidth}
  40. />
  41. </svg>
  42. </div>
  43. </>
  44. );
  45. };
  46. register({
  47. shape: "custom-react-simpleClass",
  48. width: 100,
  49. height: 70,
  50. effect: ["data"],
  51. component: component,
  52. });
  53. const simpleClass = {
  54. name: "简单类",
  55. icon: require("./image/simpleClass.png"),
  56. node: {
  57. shape: "custom-react-simpleClass",
  58. data: {
  59. label: "",
  60. },
  61. },
  62. };
  63. export default simpleClass;