import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' import { Circle, ContainerRange, Input, Progress, Svg } from './styled' export const Range = ({ min = 0, max = 100, value = 0, label, onChange, width }) => { const [currentValue, setCurrentValue] = useState(value) const inputWidth = 600 const widthInput = inputWidth - 15 const percent = (currentValue - min) / (max - min) const offset = -3 const onChangeInput = (event) => { setCurrentValue(event.target.value) onChange(event) } const [percentage, setPercentValue] = useState(0) useEffect(() => { setPercentValue((value / max) * 88) }, [max, value]) return ( {0 === 1 && }
{label} {' '} {`$ ${currentValue}`}
{ return onChange ? onChangeInput(evt) : setCurrentValue(evt.target.value) }} type='range' value={currentValue} width={width} />
) } Range.propTypes = { label: PropTypes.string, max: PropTypes.number, min: PropTypes.number, onChange: PropTypes.func, value: PropTypes.number, width: PropTypes.any }