refactor(svelte): disable zoom buttons when min/max is reached

This commit is contained in:
moklick
2023-05-17 11:55:35 +02:00
parent 35095236ff
commit bb847b7a77
2 changed files with 17 additions and 1 deletions
@@ -31,9 +31,21 @@
padding: 5px; padding: 5px;
} }
.svelte-flow__controls-button:hover {
background: #f4f4f4;
}
.svelte-flow__controls-button :global(svg) { .svelte-flow__controls-button :global(svg) {
width: 100%; width: 100%;
max-width: 12px; max-width: 12px;
max-height: 12px; max-height: 12px;
} }
.svelte-flow__controls-button:disabled {
pointer-events: none;
}
.svelte-flow__controls-button:disabled :global(svg) {
fill-opacity: 0.4;
}
</style> </style>
@@ -17,9 +17,11 @@
export let showFitView: $$Props['showFitView'] = true; export let showFitView: $$Props['showFitView'] = true;
export let showInteractive: $$Props['showInteractive'] = true; export let showInteractive: $$Props['showInteractive'] = true;
const { zoomIn, zoomOut, fitView } = useStore(); const { zoomIn, zoomOut, fitView, transform, minZoom, maxZoom } = useStore();
const isInteractive = true; const isInteractive = true;
$: minZoomReached = $transform[2] <= $minZoom;
$: maxZoomReached = $transform[2] >= $maxZoom;
const onZoomInHandler = () => { const onZoomInHandler = () => {
zoomIn(); zoomIn();
@@ -50,6 +52,7 @@
class="svelte-flow__controls-zoomin" class="svelte-flow__controls-zoomin"
title="zoom in" title="zoom in"
aria-label="zoom in" aria-label="zoom in"
disabled={maxZoomReached}
> >
<PlusIcon /> <PlusIcon />
</ControlButton> </ControlButton>
@@ -59,6 +62,7 @@
class="svelte-flow__controls-zoomout" class="svelte-flow__controls-zoomout"
title="zoom out" title="zoom out"
aria-label="zoom out" aria-label="zoom out"
disabled={minZoomReached}
> >
<MinusIcon /> <MinusIcon />
</svelte:component> </svelte:component>