@julo-ui/sliders
Version:
A React Slider component that implements input[type='range']
24 lines (22 loc) • 630 B
JavaScript
// src/utils.ts
import { countDecimalPlaces, toPreciseDecimal } from "@julo-ui/number-utils";
function valueToPercent(value, min, max) {
return (value - min) * 100 / (max - min);
}
function percentToValue(percent, min, max) {
return (max - min) * percent + min;
}
function isMouseEvent(event) {
return !("touches" in event);
}
function roundValueToStep(value, from, step) {
const nextValue = Math.round((value - from) / step) * step + from;
const precision = countDecimalPlaces(step);
return toPreciseDecimal(nextValue, precision);
}
export {
valueToPercent,
percentToValue,
isMouseEvent,
roundValueToStep
};