refactor(controls): disable zoom in/out btns when max/min zoom is reached
This commit is contained in:
@@ -23,10 +23,25 @@ const emit = defineEmits<{
|
|||||||
(event: 'interactionChange', active: boolean): void
|
(event: 'interactionChange', active: boolean): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const { nodesDraggable, nodesConnectable, elementsSelectable, setInteractive, zoomIn, zoomOut, fitView } = useVueFlow()
|
const {
|
||||||
|
nodesDraggable,
|
||||||
|
nodesConnectable,
|
||||||
|
elementsSelectable,
|
||||||
|
setInteractive,
|
||||||
|
zoomIn,
|
||||||
|
zoomOut,
|
||||||
|
fitView,
|
||||||
|
viewport,
|
||||||
|
minZoom,
|
||||||
|
maxZoom,
|
||||||
|
} = useVueFlow()
|
||||||
|
|
||||||
const isInteractive = computed(() => nodesDraggable.value || nodesConnectable.value || elementsSelectable.value)
|
const isInteractive = computed(() => nodesDraggable.value || nodesConnectable.value || elementsSelectable.value)
|
||||||
|
|
||||||
|
const minZoomReached = computed(() => viewport.value.zoom <= minZoom.value)
|
||||||
|
|
||||||
|
const maxZoomReached = computed(() => viewport.value.zoom >= maxZoom.value)
|
||||||
|
|
||||||
function onZoomInHandler() {
|
function onZoomInHandler() {
|
||||||
zoomIn()
|
zoomIn()
|
||||||
|
|
||||||
@@ -62,22 +77,25 @@ export default {
|
|||||||
<template>
|
<template>
|
||||||
<Panel class="vue-flow__controls" :position="position">
|
<Panel class="vue-flow__controls" :position="position">
|
||||||
<slot name="top"></slot>
|
<slot name="top"></slot>
|
||||||
|
|
||||||
<template v-if="showZoom">
|
<template v-if="showZoom">
|
||||||
<slot name="control-zoom-in">
|
<slot name="control-zoom-in">
|
||||||
<ControlButton class="vue-flow__controls-zoomin" @click="onZoomInHandler">
|
<ControlButton class="vue-flow__controls-zoomin" :disabled="maxZoomReached" @click="onZoomInHandler">
|
||||||
<slot name="icon-zoom-in">
|
<slot name="icon-zoom-in">
|
||||||
<component :is="PlusIcon" />
|
<component :is="PlusIcon" />
|
||||||
</slot>
|
</slot>
|
||||||
</ControlButton>
|
</ControlButton>
|
||||||
</slot>
|
</slot>
|
||||||
|
|
||||||
<slot name="control-zoom-out">
|
<slot name="control-zoom-out">
|
||||||
<ControlButton class="vue-flow__controls-zoomout" @click="onZoomOutHandler">
|
<ControlButton class="vue-flow__controls-zoomout" :disabled="minZoomReached" @click="onZoomOutHandler">
|
||||||
<slot name="icon-zoom-out">
|
<slot name="icon-zoom-out">
|
||||||
<component :is="MinusIcon" />
|
<component :is="MinusIcon" />
|
||||||
</slot>
|
</slot>
|
||||||
</ControlButton>
|
</ControlButton>
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="showFitView">
|
<template v-if="showFitView">
|
||||||
<slot name="control-fit-view">
|
<slot name="control-fit-view">
|
||||||
<ControlButton class="vue-flow__controls-fitview" @click="onFitViewHandler">
|
<ControlButton class="vue-flow__controls-fitview" @click="onFitViewHandler">
|
||||||
@@ -87,6 +105,7 @@ export default {
|
|||||||
</ControlButton>
|
</ControlButton>
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="showInteractive">
|
<template v-if="showInteractive">
|
||||||
<slot name="control-interactive">
|
<slot name="control-interactive">
|
||||||
<ControlButton v-if="showInteractive" class="vue-flow__controls-interactive" @click="onInteractiveChangeHandler">
|
<ControlButton v-if="showInteractive" class="vue-flow__controls-interactive" @click="onInteractiveChangeHandler">
|
||||||
@@ -99,6 +118,7 @@ export default {
|
|||||||
</ControlButton>
|
</ControlButton>
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</Panel>
|
</Panel>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -26,3 +26,12 @@
|
|||||||
.vue-flow__controls-button:hover {
|
.vue-flow__controls-button:hover {
|
||||||
background: #f4f4f4;
|
background: #f4f4f4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.vue-flow__controls-button:disabled {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vue-flow__controls-button:disabled svg {
|
||||||
|
fill-opacity: 0.4;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user