refactor(node-resizer): rename onBeforeResize to shouldResize, cleanup types

This commit is contained in:
moklick
2023-01-16 14:39:11 +01:00
parent e6b71d474f
commit 1ab7a0f0d9
5 changed files with 29 additions and 23 deletions
@@ -1,15 +1,17 @@
import { memo, FC } from 'react';
import { Handle, Position, NodeProps } from 'reactflow';
import { NodeResizeControl, OnResize, OnBeforeResize } from '@reactflow/node-resizer';
import { NodeResizeControl, OnResize, ShouldResize } from '@reactflow/node-resizer';
import '@reactflow/node-resizer/dist/style.css';
const onBeforeResize: OnBeforeResize = (event, params) => {
const shouldResize: ShouldResize = (event, params) => {
console.log('before resize', params);
if (params.width > 100) {
return false;
}
return true;
};
const onResize: OnResize = (event, params) => {
@@ -20,7 +22,7 @@ const CustomNode: FC<NodeProps> = ({ id, data }) => {
return (
<>
<NodeResizeControl color="red" position={Position.Left} />
<NodeResizeControl color="red" position={Position.Right} onBeforeResize={onBeforeResize} onResize={onResize} />
<NodeResizeControl color="red" position={Position.Right} shouldResize={shouldResize} onResize={onResize} />
<Handle type="target" position={Position.Top} />
<div style={{ padding: 10 }}>{data.label}</div>
<Handle type="source" position={Position.Bottom} />
@@ -1,17 +1,13 @@
import { memo, FC } from 'react';
import { Handle, Position, NodeProps } from 'reactflow';
import { NodeResizer, OnBeforeResize, OnResize, OnResizeEnd, OnResizeStart } from '@reactflow/node-resizer';
import { NodeResizer, ShouldResize, OnResize, OnResizeEnd, OnResizeStart } from '@reactflow/node-resizer';
import '@reactflow/node-resizer/dist/style.css';
const onResizeStart: OnResizeStart = (_, params) => {
console.log('resize start', params);
};
const onBeforeResize: OnBeforeResize = (_, params) => {
console.log('before resize', params);
};
const onResize: OnResize = (_, params) => {
console.log('resize', params);
};
@@ -20,6 +16,12 @@ const onResizeEnd: OnResizeEnd = (_, params) => {
console.log('resize end', params);
};
const shouldResize: ShouldResize = (_, params) => {
console.log('should resize', params);
return true;
};
const CustomNode: FC<NodeProps> = ({ data, selected }) => {
return (
<>
@@ -27,8 +29,8 @@ const CustomNode: FC<NodeProps> = ({ data, selected }) => {
minWidth={100}
minHeight={100}
isVisible={selected}
shouldResize={shouldResize}
onResizeStart={onResizeStart}
onBeforeResize={onBeforeResize}
onResize={onResize}
onResizeEnd={onResizeEnd}
/>