import React, { useEffect } from "react"; import { getFormValue } from "../actions/actionProperties"; import { t } from "../i18n"; import "./Range.scss"; export type RangeProps = { updateData: (value: number) => void; appState: any; elements: any; testId?: string; }; export const Range = ({ updateData, appState, elements, testId, }: RangeProps) => { const rangeRef = React.useRef(null); const valueRef = React.useRef(null); const value = getFormValue( elements, appState, (element) => element.opacity, true, appState.currentItemOpacity, ); useEffect(() => { if (rangeRef.current && valueRef.current) { const rangeElement = rangeRef.current; const valueElement = valueRef.current; const inputWidth = rangeElement.offsetWidth; const thumbWidth = 15; // 15 is the width of the thumb const position = (value / 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) ${value}%, var(--button-bg) ${value}%, var(--button-bg) 100%)`; } }, [value]); return ( ); };