From e68837342b1347e5393d94b6de8dc9c6629602ae Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 18 Apr 2024 23:47:18 +0500 Subject: [PATCH] Fix Progress and Toggle components (#5401) Signed-off-by: Denis Bykhov --- packages/ui/src/components/Progress.svelte | 21 ++++++++++----------- packages/ui/src/components/Toggle.svelte | 5 ++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/ui/src/components/Progress.svelte b/packages/ui/src/components/Progress.svelte index c96aad6c38..7abcf7a908 100644 --- a/packages/ui/src/components/Progress.svelte +++ b/packages/ui/src/components/Progress.svelte @@ -24,8 +24,8 @@ export let editable = false $: proc = (max - min) / 100 - if (value > max) value = max - if (value < min) value = min + $: if (value > max) value = max + $: if (value < min) value = min const dispatch = createEventDispatcher() @@ -38,10 +38,10 @@ function calcValue (e: MouseEvent): void { const rect = (e.currentTarget as HTMLElement).getBoundingClientRect() const x = e.clientX - rect.left - const pos = x / rect.width - value = (max - min) * pos - if (value > max) value = max - if (value < min) value = min + let pos = x / rect.width + if (pos > 100) pos = 100 + if (pos < 0) pos = 0 + value = (max - min) * pos + min } function save (): void { @@ -57,6 +57,8 @@ } let drag: boolean = false + + $: position = proc !== 0 ? Math.round((value - min) / proc) : 0 @@ -66,9 +68,7 @@ class="bar" style="background-color: {color !== undefined ? getPlatformColor(color, $themeStore.dark) - : 'var(--theme-toggle-on-bg-color)'}; width: calc(100% * {proc !== 0 - ? Math.round((value - min) / proc) - : 0} / 100);" + : 'var(--theme-toggle-on-bg-color)'}; width: calc(100% * {position} / 100 + 0.5rem);" /> {#if editable}
{ drag = true }} - style="left: calc(100% * {proc !== 0 ? Math.round((value - min) / proc) : 0} / 100 - 0.5rem);" + style="left: calc(100% * {position} / 100 - 0.5rem);" /> {/if}
@@ -84,7 +84,6 @@