feat(examples): add node-toolbar example

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-09 20:52:01 +01:00
committed by Braks
parent f6acbd8dc6
commit 196215d9e2
5 changed files with 130 additions and 10 deletions
+2 -1
View File
@@ -9,7 +9,8 @@
"dependencies": {
"vueflow": "workspace:*",
"@vue-flow/additional-components": "workspace:*",
"@vue-flow/core": "workspace:*"
"@vue-flow/core": "workspace:*",
"@vue-flow/node-toolbar": "workspace:*"
},
"devDependencies": {
"@types/dagre": "^0.7.48",
+4
View File
@@ -18,6 +18,10 @@ export const routes: RouterOptions['routes'] = [
path: '/snap-handle',
component: () => import('./src/SnapHandle/SnapHandleExample.vue'),
},
{
path: '/node-toolbar',
component: () => import('./src/NodeToolbar/NodeToolbarExample.vue'),
},
{
path: '/custom-connectionline',
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>
+32 -9
View File
@@ -1,24 +1,47 @@
<script lang="ts" setup>
import { VueFlow, useVueFlow } from '@vue-flow/core'
<script setup>
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'
const { nodes, edges } = getElements(10, 10)
const { nodes, edges } = getElements(15, 15)
const elements = ref([...nodes, ...edges])
const { onPaneReady } = useVueFlow({
nodes,
edges,
})
const { onPaneReady, dimensions, onNodeClick, getEdges, fitView } = useVueFlow()
onPaneReady((i) => {
i.fitView({
padding: 0.2,
})
console.log(i.getEdges.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>
<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>