import React, { useEffect } from "react"; import "./Range.scss"; export type RangeProps = { label: React.ReactNode; value: number; onChange: (value: number) => void; min?: number; max?: number; step?: number; minLabel?: React.ReactNode; hasCommonValue?: boolean; testId?: string; }; export const Range = ({ label, value, onChange, min = 0, max = 100, step = 10, minLabel = min, hasCommonValue = true, testId, }: RangeProps) => { const rangeRef = React.useRef(null); const valueRef = React.useRef(null); useEffect(() => { if (rangeRef.current && valueRef.current) { const rangeElement = rangeRef.current; const valueElement = valueRef.current; const inputWidth = rangeElement.offsetWidth; const thumbWidth = parseFloat( getComputedStyle(rangeElement).getPropertyValue( "--slider-thumb-size", ), ) || 16; const progress = ((value - min) / (max - min || 1)) * 100; const position = (progress / 100) * (inputWidth - thumbWidth) + thumbWidth / 2; valueElement.style.left = `${position}px`; rangeElement.style.background = `linear-gradient(to right, var(--color-slider-track) 0%, var(--color-slider-track) ${progress}%, var(--button-bg) ${progress}%, var(--button-bg) 100%)`; } }, [max, min, value]); return ( ); };