card.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 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 ${Math.min(h/2,w/4)},${strokeWidth}
  35. L ${w-strokeWidth},${strokeWidth}
  36. L ${w-strokeWidth},${h-strokeWidth}
  37. L ${strokeWidth},${h-strokeWidth}
  38. L ${strokeWidth},${Math.min(h/2,w/4)}
  39. L ${Math.min(h/2,w/4)},${strokeWidth}
  40. Z
  41. `}
  42. fill={fillContent}
  43. stroke={strokeColor}
  44. strokeDasharray={strokeDasharray}
  45. strokeWidth={strokeWidth}
  46. />
  47. </svg>
  48. </div>
  49. </>
  50. );
  51. };
  52. register({
  53. shape: "custom-react-card",
  54. width: 100,
  55. height: 70,
  56. effect: ["data"],
  57. component: component,
  58. });
  59. const card: CompoundedComponent = {
  60. name: "卡片",
  61. icon: require("./image/card.png"),
  62. node: {
  63. shape: "custom-react-card",
  64. data: {
  65. label: "",
  66. ...defaultData,
  67. },
  68. ports,
  69. },
  70. };
  71. export default card;