How can a user resize a node (if is tagged as 'resizable')? #45
-
The use case flow:
How this can be implemented ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
To implement a "resizable" node you would have to create a custom node that can support the resizing on a corner click. But generally you can change a node's size by applying styles to it, so an example implementation could look like this. <script setup>
import { VueFlow } from '@braks/vue-flow'
import CustomNode from './CustomNode.vue'
const elements = ref([
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
{
id: '2',
type: 'custom',
label: 'Node 2',
position: { x: 100, y: 100 },
style: { backgroundColor: 'rgba(255, 0, 255, 0.7)', height: '150px', width: '270px' },
},
])
const onResize = (size) => {
const node = elements.value.find((el) => el.id === '2')
if (node) node.style = { ...node.style, ...size }
}
</script>
<template>
<VueFlow v-model="elements">
<template #node-custom="props">
<CustomNode v-bind="props" @resize="onResize" />
</template>
</VueFlow>
</template> <script setup>
// CustomNode
const emit = defineEmits(['resize'])
const onResize = () => {
emit('resize', size)
}
</script>
<template>
<div>...</div>
</template> In 0.4.0 you could actually manipulate the dimensions of a node directly instead of applying styles but the above example would work in 0.3.x or 0.4.0-x. |
Beta Was this translation helpful? Give feedback.
To implement a "resizable" node you would have to create a custom node that can support the resizing on a corner click.
Or you could check the onClick event for nodes and calculate where the click happened etc. but that seems more complicated than adding a custom node 😅
But generally you can change a node's size by applying styles to it, so an example implementation could look like this.