preparation.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { CompoundedComponent } from "@/types";
  2. import { register } from "@antv/x6-react-shape";
  3. import { Node } from "@antv/x6";
  4. import { ports, defaultData } from "../../config/data";
  5. import CustomInput from "../CustomInput";
  6. import { useSizeHook, useShapeProps } from "@/hooks";
  7. const component = ({ node }: { node: Node }) => {
  8. const { label, text, fill, stroke, opacity } = node.getData();
  9. const { size, ref } = useSizeHook();
  10. const {
  11. fillContent,
  12. defsContent,
  13. strokeColor,
  14. strokeWidth,
  15. strokeDasharray,
  16. } = useShapeProps(fill, size, stroke);
  17. return (
  18. <>
  19. <div
  20. className="relative text-0 w-full h-full"
  21. ref={ref}
  22. style={{ opacity: opacity / 100 }}
  23. >
  24. <CustomInput value={label} styles={text} node={node} />
  25. <svg
  26. className="w-full h-full"
  27. viewBox={`0 0 ${size?.width} ${size?.height}`}
  28. xmlns="http://www.w3.org/2000/svg"
  29. >
  30. <defs>{defsContent}</defs>
  31. <polygon
  32. points={`
  33. ${size.width * 0.2},${strokeWidth}
  34. ${size.width * 0.8},${strokeWidth}
  35. ${size.width - strokeWidth},${size.height / 2}
  36. ${size.width * 0.8},${size.height - strokeWidth}
  37. ${size.width * 0.2},${size.height - strokeWidth}
  38. ${strokeWidth},${size.height / 2}
  39. `}
  40. fill={fillContent}
  41. stroke={strokeColor}
  42. strokeDasharray={strokeDasharray}
  43. strokeWidth={strokeWidth}
  44. />
  45. </svg>
  46. </div>
  47. </>
  48. );
  49. };
  50. register({
  51. shape: "custom-react-preparation",
  52. width: 100,
  53. height: 70,
  54. effect: ["data"],
  55. component: component,
  56. });
  57. const preparation: CompoundedComponent = {
  58. name: "预备",
  59. icon: require("./image/preparation.png"),
  60. node: {
  61. shape: "custom-react-preparation",
  62. data: {
  63. label: "预备",
  64. ...defaultData,
  65. },
  66. ports,
  67. },
  68. };
  69. export default preparation;