Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions docs/src/guide/components/controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,51 @@ import '@vue-flow/controls/dist/style.css'
</template>
```

You can also customize the controls by using the provided slots and slot props.

```vue
<script setup>
import { VueFlow } from '@vue-flow/core'
import type { ControlType } from '@vue-flow/controls'
import { ControlButton, Controls } from '@vue-flow/controls'

// import default controls styles
import '@vue-flow/controls/dist/style.css'

// import custom tooltip component
import Tooltip from './Tooltip.vue'

const tooltips: Record<ControlType, string> = {
'zoom-in': 'Zoom In',
'zoom-out': 'Zoom Out',
'fit-view': 'Fit View',
'interactive': 'Lock/Unlock Interaction',
}
</script>

<template>
<VueFlow>
<Controls>
<template #control-item="{ control, onClick, icon }">
<Tooltip :text="tooltips[control]">
<ControlButton @click="onClick">
<component :is="icon" />
</ControlButton>
</Tooltip>
</template>
</Controls>
</VueFlow>
</template>
```

## [Props](/typedocs/interfaces/ControlProps)

| Name | Definition | Type | Optional | Default |
|-----------------|----------------------------------------|------------------------------------------------|----------|---------|
| showZoom | Show zoom btn | boolean | true | true |
| showFitView | Show fit-view btn | boolean | true | true |
| showInteractive | Show lock interactive btn | boolean | true | true |
| showZoom | Show zoom button | boolean | true | true |
| Name | Definition | Type | Optional | Default |
|-----------------|----------------------------------------|-------------------------------------------------------|----------|---------|
| showZoom | Show zoom btn | boolean | true | true |
| showFitView | Show fit-view btn | boolean | true | true |
| showInteractive | Show lock interactive btn | boolean | true | true |
| showZoom | Show zoom button | boolean | true | true |
| fitViewParams | Params to use on fit-view button click | [FitViewParams](/typedocs/type-aliases/FitViewParams) | true | - |

## Emits
Expand All @@ -59,14 +95,15 @@ import '@vue-flow/controls/dist/style.css'

### Control Buttons

| Name | Definition |
|---------------------|----------------------------|
| top | Slot above default buttons |
| control-zoom-in | Zoom-in btn |
| control-zoom-out | Zoom-out btn |
| control-fit-view | Fit-view btn |
| control-interactive | Interaction btn |
| default | Slot below default buttons |
| Name | Definition | Props |
|---------------------|----------------------------|----------------------------------------------------------------------------------------------------------------------|
| top | Slot above default buttons | [ControlsSlotProps](/typedocs/interfaces/ControlsSlotProps) |
| control-item | Each control btn | [ControlItemSlotProps](/typedocs/interfaces/ControlItemSlotProps) |
| control-zoom-in | Zoom-in btn | { disabled: boolean; zoomIn: () \=> any; icon: Component } |
| control-zoom-out | Zoom-out btn | { disabled: boolean; zoomOut: () \=> any; icon: Component } |
| control-fit-view | Fit-view btn | { fitView: () \=> any; icon: Component } |
| control-interactive | Interaction btn | { interactive: boolean; toggleInteractive: () \=> any; icon: Component; lockIcon: Component; unlockIcon: Component } |
| default | Slot below default buttons | [ControlsSlotProps](/typedocs/interfaces/ControlsSlotProps) |

### Icons

Expand All @@ -77,5 +114,3 @@ import '@vue-flow/controls/dist/style.css'
| icon-fit-view | Fit-view icon |
| icon-lock | Interaction locked icon |
| icon-unlock | Interaction unlocked icon |


4 changes: 4 additions & 0 deletions examples/vite/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export const routes: RouterOptions['routes'] = [
path: '/confirm-delete',
component: () => import('./src/ConfirmDelete/ConfirmDeleteExample.vue'),
},
{
path: '/controls-slot',
component: () => import('./src/Controls/ControlsSlot.vue'),
},
]

export const router = createRouter({
Expand Down
69 changes: 69 additions & 0 deletions examples/vite/src/Controls/ControlsSlot.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<script lang="ts" setup>
import type { Node } from '@vue-flow/core'
import { VueFlow } from '@vue-flow/core'

import { Background } from '@vue-flow/background'
import type { ControlType } from '@vue-flow/controls'
import { Controls } from '@vue-flow/controls'

const nodes = ref<Node[]>([
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'light' },
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 }, class: 'light' },
{ id: '3', label: 'Node 3', position: { x: 400, y: 100 }, class: 'light' },
{ id: '4', label: 'Node 4', position: { x: 400, y: 200 }, class: 'light' },
])

const tooltips: Record<ControlType, string> = {
'zoom-in': 'Zoom In',
'zoom-out': 'Zoom Out',
'fit-view': 'Fit View',
'interactive': 'Lock/Unlock Interaction',
}
</script>

<template>
<VueFlow :nodes="nodes" fit-view-on-init class="vue-flow-controls-example">
<Background />
<Controls>
<template #control-item="{ control, disabled, onClick, icon }">
<button class="control" :title="tooltips[control]" :disabled="disabled" @click="onClick">
<component :is="icon" class="icon" />
</button>
</template>

<template #control-interactive="{ interactive, toggleInteractive }">
<button class="control" :title="interactive ? 'Lock' : 'Unock'" @click="toggleInteractive">
{{ interactive ? '🔓' : '🔒' }}
</button>
</template>
</Controls>
</VueFlow>
</template>

<style scoped>
.control {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
border: none;
background: #fafafa;
cursor: pointer;
}

.control:not(:disabled):hover {
background: #eee;
}

.control:disabled {
cursor: not-allowed;
color: #ccc;
}

.icon {
fill: currentColor;
width: 16px;
height: 16px;
}
</style>
1 change: 0 additions & 1 deletion packages/controls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import '@vue-flow/controls/dist/style.css'

import initialElements from './initial-elements'


// some nodes and edges
const elements = ref(initialElements)
</script>
Expand Down
20 changes: 10 additions & 10 deletions packages/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "@vue-flow/controls",
"version": "1.1.3",
"private": false,
"license": "MIT",
"author": "Burak Cakmakoglu<[email protected]>",
"license": "MIT",
"homepage": "https://github.com/bcakmakoglu/vue-flow#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/bcakmakoglu/vue-flow/packages/plugins/controls"
},
"homepage": "https://github.com/bcakmakoglu/vue-flow#readme",
"bugs": {
"url": "https://github.com/bcakmakoglu/vue-flow/issues"
},
Expand All @@ -28,11 +28,9 @@
"vueflow",
"typescript"
],
"main": "./dist/vue-flow-controls.js",
"module": "./dist/vue-flow-controls.mjs",
"types": "./dist/index.d.ts",
"unpkg": "./dist/vue-flow-controls.iife.js",
"jsdelivr": "./dist/vue-flow-controls.iife.js",
"sideEffects": [
"*.css"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand All @@ -41,13 +39,15 @@
},
"./dist/style.css": "./dist/style.css"
},
"main": "./dist/vue-flow-controls.js",
"module": "./dist/vue-flow-controls.mjs",
"unpkg": "./dist/vue-flow-controls.iife.js",
"jsdelivr": "./dist/vue-flow-controls.iife.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"*.d.ts"
],
"sideEffects": [
"*.css"
],
"scripts": {
"dev": "pnpm types:watch & pnpm build:watch",
"build": "vite build",
Expand Down
Loading