sigleDownArrow.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { CompoundedComponent } from "@/types";
  2. import { register } from "@antv/x6-react-shape";
  3. import { Node } from "@antv/x6";
  4. import { ports, defaultData } from "../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. const { width: w, height: h } = size;
  18. return (
  19. <>
  20. <div
  21. className="relative text-0 w-full h-full"
  22. ref={ref}
  23. style={{ opacity: opacity / 100 }}
  24. >
  25. <CustomInput value={label} styles={text} node={node} />
  26. <svg
  27. className="w-full h-full"
  28. viewBox={`0 0 ${size?.width} ${size?.height}`}
  29. xmlns="http://www.w3.org/2000/svg"
  30. >
  31. <defs>{defsContent}</defs>
  32. <path
  33. d={`
  34. M ${w*0.67},${strokeWidth}
  35. L ${w*0.67},${h-Math.min(w*0.5,h*0.45)}
  36. L ${w-strokeWidth},${h-Math.min(w*0.5,h*0.45)}
  37. L ${w/2},${h-strokeWidth}
  38. L ${strokeWidth},${h-Math.min(w*0.5,h*0.45)}
  39. L ${w*0.33},${h-Math.min(w*0.5,h*0.45)}
  40. L ${w*0.33},${strokeWidth}
  41. Z
  42. `}
  43. fill={fillContent}
  44. stroke={strokeColor}
  45. strokeDasharray={strokeDasharray}
  46. strokeWidth={strokeWidth}
  47. />
  48. </svg>
  49. </div>
  50. </>
  51. );
  52. };
  53. register({
  54. shape: "custom-react-singleDownArrow",
  55. width: 60,
  56. height: 90,
  57. effect: ["data"],
  58. component: component,
  59. });
  60. const singleDownArrow: CompoundedComponent = {
  61. name: "下箭头",
  62. icon: require("./image/singleDownArrow.png"),
  63. node: {
  64. shape: "custom-react-singleDownArrow",
  65. data: {
  66. label: "",
  67. ...defaultData,
  68. },
  69. ports,
  70. },
  71. };
  72. export default singleDownArrow;