feat(examples): add node-toolbar example
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -9,7 +9,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vueflow": "workspace:*",
|
"vueflow": "workspace:*",
|
||||||
"@vue-flow/additional-components": "workspace:*",
|
"@vue-flow/additional-components": "workspace:*",
|
||||||
"@vue-flow/core": "workspace:*"
|
"@vue-flow/core": "workspace:*",
|
||||||
|
"@vue-flow/node-toolbar": "workspace:*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/dagre": "^0.7.48",
|
"@types/dagre": "^0.7.48",
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ export const routes: RouterOptions['routes'] = [
|
|||||||
path: '/snap-handle',
|
path: '/snap-handle',
|
||||||
component: () => import('./src/SnapHandle/SnapHandleExample.vue'),
|
component: () => import('./src/SnapHandle/SnapHandleExample.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/node-toolbar',
|
||||||
|
component: () => import('./src/NodeToolbar/NodeToolbarExample.vue'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/custom-connectionline',
|
path: '/custom-connectionline',
|
||||||
component: () => import('./src/CustomConnectionLine/CustomConnectionLine.vue'),
|
component: () => import('./src/CustomConnectionLine/CustomConnectionLine.vue'),
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { Handle, Position } from '@vue-flow/core'
|
||||||
|
import { NodeToolbar } from '@vue-flow/node-toolbar'
|
||||||
|
|
||||||
|
interface NodeData {
|
||||||
|
toolbarVisible: boolean
|
||||||
|
toolbarPosition: Position
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
data: NodeData
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<Props>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NodeToolbar :is-visible="data.toolbarVisible" :position="data.toolbarPosition">
|
||||||
|
<button>delete</button>
|
||||||
|
<button>copy</button>
|
||||||
|
<button>expand</button>
|
||||||
|
</NodeToolbar>
|
||||||
|
|
||||||
|
<div :style="{ padding: '10px 20px' }">
|
||||||
|
{{ label }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Handle type="target" :position="Position.Left" />
|
||||||
|
<Handle type="source" :position="Position.Right" />
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { Position, VueFlow } from '@vue-flow/core'
|
||||||
|
import CustomNode from './CustomNode.vue'
|
||||||
|
|
||||||
|
const defaultNodeStyle = {
|
||||||
|
border: '2px solid #ff0071',
|
||||||
|
background: 'white',
|
||||||
|
borderRadius: '20px',
|
||||||
|
}
|
||||||
|
|
||||||
|
const elements = ref([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
type: 'custom',
|
||||||
|
label: 'toolbar top',
|
||||||
|
data: { toolbarPosition: Position.Top },
|
||||||
|
position: { x: 200, y: 0 },
|
||||||
|
style: defaultNodeStyle,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
type: 'custom',
|
||||||
|
label: 'toolbar right',
|
||||||
|
data: { toolbarPosition: Position.Right },
|
||||||
|
position: { x: -50, y: 100 },
|
||||||
|
style: defaultNodeStyle,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
type: 'custom',
|
||||||
|
label: 'toolbar bottom',
|
||||||
|
data: { toolbarPosition: Position.Bottom },
|
||||||
|
position: { x: 0, y: 200 },
|
||||||
|
style: defaultNodeStyle,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '4',
|
||||||
|
type: 'custom',
|
||||||
|
label: 'toolbar left',
|
||||||
|
data: { toolbarPosition: Position.Left },
|
||||||
|
position: { x: 200, y: 300 },
|
||||||
|
style: defaultNodeStyle,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '5',
|
||||||
|
type: 'custom',
|
||||||
|
label: 'toolbar always open',
|
||||||
|
data: { toolbarPosition: Position.Top, toolbarVisible: true },
|
||||||
|
position: { x: 0, y: -100 },
|
||||||
|
style: defaultNodeStyle,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VueFlow v-model="elements" fit-view-on-init class="vue-flow-basic-example">
|
||||||
|
<template #node-custom="nodeProps">
|
||||||
|
<CustomNode :data="nodeProps.data" :label="nodeProps.label" />
|
||||||
|
</template>
|
||||||
|
</VueFlow>
|
||||||
|
</template>
|
||||||
@@ -1,24 +1,47 @@
|
|||||||
<script lang="ts" setup>
|
<script setup>
|
||||||
import { VueFlow, useVueFlow } from '@vue-flow/core'
|
import { Background, MiniMap, Panel, PanelPosition } from '@vue-flow/additional-components'
|
||||||
|
import { VueFlow, isNode, useVueFlow } from '@vue-flow/core'
|
||||||
|
import { nextTick, ref } from 'vue'
|
||||||
import { getElements } from './utils'
|
import { getElements } from './utils'
|
||||||
|
|
||||||
const { nodes, edges } = getElements(10, 10)
|
const { nodes, edges } = getElements(15, 15)
|
||||||
|
const elements = ref([...nodes, ...edges])
|
||||||
|
|
||||||
const { onPaneReady } = useVueFlow({
|
const { onPaneReady, dimensions, onNodeClick, getEdges, fitView } = useVueFlow()
|
||||||
nodes,
|
|
||||||
edges,
|
|
||||||
})
|
|
||||||
|
|
||||||
onPaneReady((i) => {
|
onPaneReady((i) => {
|
||||||
i.fitView({
|
i.fitView({
|
||||||
padding: 0.2,
|
padding: 0.2,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(i.getEdges.value)
|
|
||||||
console.log(i.getElements.value)
|
console.log(i.getElements.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const toggleClass = () => elements.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
|
||||||
|
|
||||||
|
const updatePos = () => {
|
||||||
|
elements.value.forEach((el) => {
|
||||||
|
if (isNode(el)) {
|
||||||
|
el.position = {
|
||||||
|
x: Math.random() * 10 * dimensions.value.width,
|
||||||
|
y: Math.random() * 10 * dimensions.value.height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
fitView({ duration: 1000, padding: 0.5 })
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VueFlow />
|
<VueFlow v-model="elements" :min-zoom="0.1">
|
||||||
|
<Background />
|
||||||
|
|
||||||
|
<Panel :position="PanelPosition.TopRight">
|
||||||
|
<button style="margin-right: 5px" @click="updatePos">update positions</button>
|
||||||
|
<button @click="toggleClass">toggle class</button>
|
||||||
|
</Panel>
|
||||||
|
</VueFlow>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user