sequenceLifeLine.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. 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. <div className="absolute top-0 left-0 w-full h-30px">
  24. <CustomInput value={label} styles={text} node={node} />
  25. </div>
  26. <svg
  27. className="w-full h-full"
  28. viewBox={`0 0 ${width} ${height}`}
  29. xmlns="http://www.w3.org/2000/svg"
  30. >
  31. <defs>{defsContent}</defs>
  32. <rect
  33. x={strokeWidth}
  34. y={strokeWidth}
  35. width={width - strokeWidth * 2}
  36. height={30}
  37. fill={fillContent}
  38. stroke={strokeColor}
  39. strokeDasharray={strokeDasharray}
  40. strokeWidth={strokeWidth}
  41. />
  42. <path
  43. d={`
  44. M ${width/2},${30 + strokeWidth}
  45. L ${width/2},${height - strokeWidth}
  46. `}
  47. fill="none"
  48. stroke={strokeColor}
  49. strokeDasharray='2 2'
  50. strokeWidth={strokeWidth}
  51. />
  52. </svg>
  53. </div>
  54. </>
  55. );
  56. };
  57. register({
  58. shape: "custom-react-sequenceLifeLine",
  59. width: 70,
  60. height: 140,
  61. effect: ["data"],
  62. component: component,
  63. });
  64. const sequenceLifeLine = {
  65. name: "生命线",
  66. icon: require("./image/sequenceLifeLine.png"),
  67. node: {
  68. shape: "custom-react-sequenceLifeLine",
  69. data: {
  70. label: "",
  71. },
  72. },
  73. };
  74. export default sequenceLifeLine;