@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
30 lines (29 loc) • 720 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSliderValue = getSliderValue;
var _clamp = require("../../utils/clamp");
var _setValueIndex = require("./setValueIndex");
function getSliderValue(params) {
const {
valueInput,
index,
min,
max,
range,
values
} = params;
let newValue = valueInput;
newValue = (0, _clamp.clamp)(newValue, min, max);
if (range) {
// Bound the new value to the thumb's neighbours.
newValue = (0, _clamp.clamp)(newValue, values[index - 1] || -Infinity, values[index + 1] || Infinity);
newValue = (0, _setValueIndex.setValueIndex)({
values,
newValue,
index
});
}
return newValue;
}