UNPKG

rheostat

Version:

Rheostat is a www, mobile, and accessible slider component built with React

29 lines (21 loc) 584 B
export default { getPosition(value, min, max) { const minv = Math.log(min); const maxv = Math.log(max); const scale = (maxv - minv) / 100; return (Math.log(value) - minv) / scale; }, getValue(positionPercent, min, max) { const minv = Math.log(min); const maxv = Math.log(max); if (positionPercent === 0) { return min; } if (positionPercent === 100) { return max; } // calculate adjustment factor const scale = (maxv - minv) / 100; return Math.floor(Math.exp(minv + (scale * positionPercent))) || 0; }, };