2
0

step-2.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import '@flowgram.ai/fixed-layout-editor/index.css';
  2. import { defaultFixedSemiMaterials } from '@flowgram.ai/fixed-semi-materials';
  3. import {
  4. FixedLayoutEditorProvider,
  5. EditorRenderer,
  6. FlowNodeEntity,
  7. useNodeRender,
  8. } from '@flowgram.ai/fixed-layout-editor';
  9. export const NodeRender = ({ node }: { node: FlowNodeEntity }) => {
  10. const {
  11. onMouseEnter,
  12. onMouseLeave,
  13. startDrag,
  14. form,
  15. dragging,
  16. isBlockOrderIcon,
  17. isBlockIcon,
  18. activated,
  19. } = useNodeRender();
  20. return (
  21. <div
  22. onMouseEnter={onMouseEnter}
  23. onMouseLeave={onMouseLeave}
  24. onMouseDown={(e) => {
  25. startDrag(e);
  26. e.stopPropagation();
  27. }}
  28. style={{
  29. width: 280,
  30. minHeight: 88,
  31. height: 'auto',
  32. background: '#fff',
  33. border: '1px solid rgba(6, 7, 9, 0.15)',
  34. borderColor: activated ? '#82a7fc' : 'rgba(6, 7, 9, 0.15)',
  35. borderRadius: 8,
  36. boxShadow: '0 2px 6px 0 rgba(0, 0, 0, 0.04), 0 4px 12px 0 rgba(0, 0, 0, 0.02)',
  37. display: 'flex',
  38. flexDirection: 'column',
  39. justifyContent: 'center',
  40. position: 'relative',
  41. padding: 12,
  42. cursor: 'move',
  43. opacity: dragging ? 0.3 : 1,
  44. ...(isBlockOrderIcon || isBlockIcon ? { width: 260 } : {}),
  45. }}
  46. >
  47. {form?.render()}
  48. </div>
  49. );
  50. };
  51. const FlowGramApp = () => (
  52. <FixedLayoutEditorProvider
  53. nodeRegistries={[
  54. {
  55. type: 'custom',
  56. },
  57. ]}
  58. initialData={{
  59. nodes: [
  60. {
  61. id: 'custom_0',
  62. type: 'custom',
  63. },
  64. ],
  65. }}
  66. materials={{
  67. renderDefaultNode: NodeRender,
  68. components: defaultFixedSemiMaterials,
  69. }}
  70. >
  71. <EditorRenderer />
  72. </FixedLayoutEditorProvider>
  73. );
  74. export default FlowGramApp;