2020-03-22 22:14:51 +00:00
|
|
|
import { formatValue } from 'Engine/format'
|
2019-09-13 10:42:19 +00:00
|
|
|
import React, { useCallback, useState } from 'react'
|
2020-03-22 22:14:51 +00:00
|
|
|
import { debounce as debounceFn } from '../utils'
|
2019-04-26 10:41:57 +00:00
|
|
|
import './PercentageField.css'
|
|
|
|
|
2020-03-22 22:14:51 +00:00
|
|
|
export default function PercentageField({ onChange, value, debounce = 0 }) {
|
2019-09-13 10:42:19 +00:00
|
|
|
const [localValue, setLocalValue] = useState(value)
|
|
|
|
const debouncedOnChange = useCallback(
|
2020-03-22 22:14:51 +00:00
|
|
|
debounce ? debounceFn(debounce, onChange) : onChange,
|
2019-09-15 20:51:13 +00:00
|
|
|
[debounce, onChange]
|
2019-09-13 10:42:19 +00:00
|
|
|
)
|
2019-09-11 08:06:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<input
|
|
|
|
className="range"
|
2019-09-13 10:42:19 +00:00
|
|
|
onChange={e => {
|
|
|
|
const value = e.target.value
|
|
|
|
setLocalValue(value)
|
|
|
|
debouncedOnChange(value)
|
|
|
|
}}
|
2019-09-11 08:06:26 +00:00
|
|
|
type="range"
|
|
|
|
value={localValue}
|
|
|
|
name="volume"
|
|
|
|
min="0"
|
|
|
|
step="0.05"
|
|
|
|
max="1"
|
|
|
|
/>
|
|
|
|
<span style={{ display: 'inline-block', width: '3em' }}>
|
2020-03-22 22:14:51 +00:00
|
|
|
{formatValue({
|
|
|
|
value: localValue,
|
|
|
|
unit: '%'
|
|
|
|
})}
|
2019-09-11 08:06:26 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)
|
2019-04-26 10:41:57 +00:00
|
|
|
}
|