UNPKG

@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.

24 lines 568 B
import { clamp } from '../../utils/clamp.js'; import { setValueIndex } from './setValueIndex.js'; export function getSliderValue(params) { const { valueInput, index, min, max, range, values } = params; let newValue = valueInput; newValue = clamp(newValue, min, max); if (range) { // Bound the new value to the thumb's neighbours. newValue = clamp(newValue, values[index - 1] || -Infinity, values[index + 1] || Infinity); newValue = setValueIndex({ values, newValue, index }); } return newValue; }