"use client"; /** * Range Slider Field * * A dual-thumb slider for selecting a min/max range. */ import { useCallback, useMemo } from "react"; import { ANIMATION_CLASSES, getStaggerStyle, STAGGER_PRESETS, } from "../animations"; import { OnboardingLabel } from "../primitives/onboarding-label"; import { OnboardingSlider } from "../primitives/onboarding-slider"; import type { RangeSliderFieldProps } from "../types/fields"; export function RangeSliderField({ id, label, description, min, max, step = 1, value, onChange, unit = "", unitPosition = "prefix", formatValue, showMinMax = true, animationIndex = 0, disabled = false, }: RangeSliderFieldProps) { const handleChange = useCallback( (newValue: number[]) => { onChange([newValue[0], newValue[1]]); }, [onChange], ); const formatDisplayValue = useCallback( (val: number) => { if (formatValue) return formatValue(val); const formatted = val.toLocaleString(); if (!unit) return formatted; return unitPosition === "prefix" ? `${unit}${formatted}` : `${formatted} ${unit}`; }, [formatValue, unit, unitPosition], ); const displayRange = useMemo(() => { return `${formatDisplayValue(value[0])} – ${formatDisplayValue(value[1])}`; }, [value, formatDisplayValue]); return (
{label} {description && (

{description.includes("{range}") ? description.replace("{range}", displayRange) : description}

)} {!description && (

{formatDisplayValue(value[0])} {" – "} {formatDisplayValue(value[1])}

)} {showMinMax && (
{formatDisplayValue(min)} {formatDisplayValue(max)}
)}
); }