refactor(controls): disable zoom in/out btns when max/min zoom is reached

This commit is contained in:
braks
2023-05-25 20:48:26 +02:00
committed by Braks
parent 8fa6ad5076
commit 49fbdadb72
2 changed files with 32 additions and 3 deletions
+23 -3
View File
@@ -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>
+9
View File
@@ -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;
}