diff --git a/src/lib/components/AmountRangeFilter.svelte b/src/lib/components/AmountRangeFilter.svelte index 9ec47f0..1c34598 100644 --- a/src/lib/components/AmountRangeFilter.svelte +++ b/src/lib/components/AmountRangeFilter.svelte @@ -2,7 +2,6 @@ import SlidersHorizontalIcon from '@lucide/svelte/icons/sliders-horizontal'; import * as Popover from '$lib/components/ui/popover'; - import { Slider } from '$lib/components/ui/slider'; import { formatValue } from '$lib/format'; const LIMIT = 10_000_000_000; @@ -19,22 +18,16 @@ } = $props(); let open = $state(false); - let localMin = $state(0); - let localMax = $state(LIMIT); + let localMin = $state(normalizedRange()[0]); + let localMax = $state(normalizedRange()[1]); const hasFilter = $derived(minAmount !== null || maxAmount !== null); - let sliderValue = $state([0, LIMIT]); + const minPosition = $derived((localMin / LIMIT) * 100); + const maxPosition = $derived((localMax / LIMIT) * 100); - $effect(() => { - localMin = Math.max(0, Math.min(minAmount ?? 0, LIMIT)); - localMax = Math.max(localMin, Math.min(maxAmount ?? LIMIT, LIMIT)); - sliderValue = [localMin, localMax]; - }); - - function updateRange(value: number[]) { - const [nextMin = 0, nextMax = LIMIT] = [...value].sort((left, right) => left - right); - localMin = nextMin; - localMax = nextMax; - sliderValue = [nextMin, nextMax]; + function normalizedRange(): [number, number] { + const nextMin = Math.max(0, Math.min(minAmount ?? 0, LIMIT)); + const nextMax = Math.max(nextMin, Math.min(maxAmount ?? LIMIT, LIMIT)); + return [nextMin, nextMax]; } function apply() { @@ -43,7 +36,12 @@ } - + { + if (nextOpen) [localMin, localMax] = normalizedRange(); + }} +> تا {formatValue(localMax)} ریال - +
+ + + + { + if (localMin > localMax) localMin = localMax; + }} + class="amount-range-input absolute inset-0 h-8 w-full" + aria-label="کمینه مبلغ تراکنش" + /> + { + if (localMax < localMin) localMax = localMin; + }} + class="amount-range-input absolute inset-0 h-8 w-full" + aria-label="بیشینه مبلغ تراکنش" + /> +