node-render.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import '@flowgram.ai/fixed-layout-editor/index.css';
  6. import { FlowNodeEntity, useNodeRender, useClientContext } from '@flowgram.ai/fixed-layout-editor';
  7. export const NodeRender = ({ node }: { node: FlowNodeEntity }) => {
  8. const {
  9. onMouseEnter,
  10. onMouseLeave,
  11. startDrag,
  12. form,
  13. dragging,
  14. isBlockOrderIcon,
  15. isBlockIcon,
  16. activated,
  17. } = useNodeRender();
  18. const ctx = useClientContext();
  19. return (
  20. <div
  21. onMouseEnter={onMouseEnter}
  22. onMouseLeave={onMouseLeave}
  23. onMouseDown={(e) => {
  24. startDrag(e);
  25. e.stopPropagation();
  26. }}
  27. style={{
  28. width: 280,
  29. minHeight: 88,
  30. height: 'auto',
  31. background: '#fff',
  32. border: '1px solid rgba(6, 7, 9, 0.15)',
  33. borderColor: activated ? '#82a7fc' : 'rgba(6, 7, 9, 0.15)',
  34. borderRadius: 8,
  35. boxShadow: '0 2px 6px 0 rgba(0, 0, 0, 0.04), 0 4px 12px 0 rgba(0, 0, 0, 0.02)',
  36. display: 'flex',
  37. flexDirection: 'column',
  38. justifyContent: 'center',
  39. position: 'relative',
  40. padding: 12,
  41. cursor: 'move',
  42. opacity: dragging ? 0.3 : 1,
  43. ...(isBlockOrderIcon || isBlockIcon ? { width: 260 } : {}),
  44. }}
  45. >
  46. {form?.render()}
  47. {/* 删除按钮 */}
  48. <button
  49. onClick={(e) => {
  50. e.stopPropagation();
  51. ctx.operation.deleteNode(node);
  52. }}
  53. style={{
  54. position: 'absolute',
  55. top: 4,
  56. right: 4,
  57. width: 20,
  58. height: 20,
  59. border: 'none',
  60. borderRadius: '50%',
  61. background: '#fff',
  62. color: '#666',
  63. fontSize: 12,
  64. cursor: 'pointer',
  65. display: 'flex',
  66. alignItems: 'center',
  67. justifyContent: 'center',
  68. boxShadow: '0 1px 3px rgba(0,0,0,0.12)',
  69. transition: 'all 0.2s',
  70. }}
  71. >
  72. ×
  73. </button>
  74. </div>
  75. );
  76. };