|
|
|
|
@ -1,27 +1,49 @@
|
|
|
|
|
import React, { memo } from 'react';
|
|
|
|
|
import React, { memo, useState, useCallback } from 'react';
|
|
|
|
|
import { Button } from 'evergreen-ui';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
const ValueTuner = memo(({ style, title, value, setValue, onFinished, resolution = 1000, min = 0, max = 1, resetToDefault }) => {
|
|
|
|
|
import Switch from './Switch';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ValueTuner = memo(({ style, title, value, setValue, onFinished, resolution = 1000, min: minIn = 0, max: maxIn = 1, resetToDefault }) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
const [min, setMin] = useState(minIn);
|
|
|
|
|
const [max, setMax] = useState(maxIn);
|
|
|
|
|
|
|
|
|
|
function onChange(e) {
|
|
|
|
|
e.target.blur();
|
|
|
|
|
setValue(Math.min(Math.max(min, ((e.target.value / resolution) * (max - min)) + min)), max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isZoomed = !(min === minIn && max === maxIn);
|
|
|
|
|
|
|
|
|
|
const toggleZoom = useCallback(() => {
|
|
|
|
|
if (isZoomed) {
|
|
|
|
|
setMin(minIn);
|
|
|
|
|
setMax(maxIn);
|
|
|
|
|
} else {
|
|
|
|
|
const zoomWindow = (maxIn - minIn) / 100;
|
|
|
|
|
setMin(Math.max(minIn, value - zoomWindow));
|
|
|
|
|
setMax(Math.min(maxIn, value + zoomWindow));
|
|
|
|
|
}
|
|
|
|
|
}, [isZoomed, maxIn, minIn, value]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div style={{ background: 'var(--gray1)', color: 'var(--gray12)', position: 'absolute', bottom: 0, padding: 10, margin: 10, borderRadius: 10, ...style }}>
|
|
|
|
|
<div style={{ display: 'flex', alignItems: 'center', flexBasis: 400 }}>
|
|
|
|
|
<div style={{ marginBottom: '.5em' }}>{title}</div>
|
|
|
|
|
<div style={{ marginLeft: 10, fontWeight: 'bold' }}>{value.toFixed(2)}</div>
|
|
|
|
|
<div style={{ flexGrow: 1, flexBasis: 10 }} />
|
|
|
|
|
<Button height={20} onClick={resetToDefault}>{t('Default')}</Button>
|
|
|
|
|
<Button height={20} intent="success" onClick={onFinished}>{t('Done')}</Button>
|
|
|
|
|
<div style={{ display: 'flex', alignItems: 'center', flexBasis: 400, marginBottom: '.2em' }}>
|
|
|
|
|
<div>{title}</div>
|
|
|
|
|
<div style={{ marginLeft: '.5em', fontWeight: 'bold', marginRight: '.5em', textDecoration: 'underline' }}>{value.toFixed(4)}</div>
|
|
|
|
|
<Switch checked={isZoomed} onCheckedChange={toggleZoom} style={{ flexShrink: 0 }} /><span style={{ marginLeft: '.3em' }}>{t('Precise')}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style={{ marginBottom: '.3em' }}>
|
|
|
|
|
<input style={{ width: '100%' }} type="range" min="0" max="1000" step="1" value={((value - min) / (max - min)) * resolution} onChange={onChange} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style={{ display: 'flex' }}>
|
|
|
|
|
<input style={{ flexGrow: 1 }} type="range" min="0" max="1000" step="1" value={((value - min) / (max - min)) * resolution} onChange={onChange} />
|
|
|
|
|
<div style={{ textAlign: 'right' }}>
|
|
|
|
|
<Button height={20} onClick={resetToDefault}>{t('Default')}</Button>
|
|
|
|
|
<Button height={20} intent="success" onClick={onFinished}>{t('Done')}</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|