react-slider
Advanced tools
Comparing version 0.3.1 to 0.3.2
{ | ||
"name": "react-slider", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Slider component for React", | ||
@@ -5,0 +5,0 @@ "main": "react-slider.js", |
@@ -72,3 +72,3 @@ (function (root, factory) { | ||
for (var i = 0; i < count; i++) { | ||
res.push(range * i); | ||
res.push(min + range * i); | ||
} | ||
@@ -137,6 +137,9 @@ return res; | ||
getInitialState: function () { | ||
var value = this._or(this.props.value, this.props.defaultValue); | ||
//var value = this._or(this.props.value, this.props.defaultValue); | ||
var value = map(this._or(this.props.value, this.props.defaultValue), this._trimAlignValue); | ||
return { | ||
index: -1, // TODO: find better solution | ||
min: this._trimAlignValue(this.props.min), | ||
max: this._trimAlignValue(this.props.max), | ||
upperBound: 0, | ||
@@ -155,3 +158,5 @@ sliderLength: 0, | ||
componentWillReceiveProps: function (newProps) { | ||
this.state.value = this._or(newProps.value, this.state.value) | ||
this.state.value = map(this._or(newProps.value, this.state.value), this._trimAlignValue); | ||
this.state.min = this._trimAlignValue(newProps.min); | ||
this.state.max = this._trimAlignValue(newProps.max); | ||
}, | ||
@@ -183,4 +188,6 @@ | ||
var value = map(this.state.value, this._trimAlignValue); | ||
this.setState({value: value}); | ||
// values could have changed due to `this._trimAlignValue`. | ||
if (this.props.onChange && !is(this.props.value, this.state.value)) { | ||
this.props.onChange(this.state.value); | ||
} | ||
}, | ||
@@ -207,7 +214,9 @@ | ||
var sliderMax = rect[this._max()] - handle[size]; | ||
var sliderMin = this._sliderMin = rect[this._min()]; | ||
var sliderMin = rect[this._min()]; | ||
this.setState({ | ||
upperBound: slider[size] - handle[size], | ||
sliderLength: sliderMax - sliderMin | ||
sliderLength: sliderMax - sliderMin, | ||
sliderMin: sliderMin, | ||
handleSize: handle[size] | ||
}); | ||
@@ -218,3 +227,3 @@ }, | ||
_calcOffset: function (value) { | ||
var ratio = (value - this.props.min) / (this.props.max - this.props.min); | ||
var ratio = (value - this.state.min) / (this.state.max - this.state.min); | ||
return ratio * this.state.upperBound; | ||
@@ -238,2 +247,3 @@ }, | ||
position: 'absolute', | ||
willChange: this.state.index >= 0 ? 'transform' : '', | ||
zIndex: this.state.zIndices.indexOf(i) + 1 | ||
@@ -245,3 +255,4 @@ } | ||
var obj = { | ||
position: 'absolute' | ||
position: 'absolute', | ||
willChange: this.state.index >= 0 ? this._min() + ',' + this._max() : '' | ||
}; | ||
@@ -254,4 +265,2 @@ obj[this._min()] = minMax.min; | ||
_getClosestIndex: function (pixelOffset) { | ||
var self = this; | ||
// TODO: No need to iterate all | ||
@@ -261,3 +270,3 @@ return reduce(this.state.value, function (min, value, i) { | ||
var offset = self._calcOffset(value); | ||
var offset = this._calcOffset(value); | ||
var dist = Math.abs(pixelOffset - offset); | ||
@@ -267,3 +276,3 @@ | ||
}, [-1, Number.MAX_VALUE])[0]; | ||
}.bind(this), [-1, Number.MAX_VALUE])[0]; | ||
}, | ||
@@ -273,3 +282,3 @@ | ||
_forceValueFromPosition: function (position, callback) { | ||
var pixelOffset = position - this._sliderMin; | ||
var pixelOffset = position - this.state.sliderMin - (this.state.handleSize / 2); | ||
var closestIndex = this._getClosestIndex(pixelOffset); | ||
@@ -290,12 +299,11 @@ | ||
var self = this; | ||
return function (e) { | ||
var position = e['page' + self._axis()]; | ||
self._start(i, position); | ||
var position = e['page' + this._axis()]; | ||
this._start(i, position); | ||
document.addEventListener('mousemove', self._dragMove, false); | ||
document.addEventListener('mouseup', self._dragEnd, false); | ||
document.addEventListener('mousemove', this._dragMove, false); | ||
document.addEventListener('mouseup', this._dragEnd, false); | ||
pauseEvent(e); | ||
} | ||
}.bind(this); | ||
}, | ||
@@ -306,8 +314,12 @@ | ||
var self = this; | ||
return function (e) { | ||
var last = e.changedTouches[e.changedTouches.length - 1]; | ||
var position = last['page' + self._axis()]; | ||
self._start(i, position); | ||
} | ||
var position = last['page' + this._axis()]; | ||
this._start(i, position); | ||
document.addEventListener('touchmove', this._touchMove, false); | ||
document.addEventListener('touchend', this._touchEnd, false); | ||
pauseEvent(e); | ||
}.bind(this); | ||
}, | ||
@@ -334,3 +346,5 @@ | ||
_onTouchEnd: function () { | ||
_touchEnd: function () { | ||
document.removeEventListener('touchmove', this._touchMove, false); | ||
document.removeEventListener('touchend', this._touchEnd, false); | ||
this._end(); | ||
@@ -369,3 +383,3 @@ }, | ||
var diffPosition = position - this.state.startPosition; | ||
var diffValue = (diffPosition / this.state.sliderLength) * (this.props.max - this.props.min); | ||
var diffValue = (diffPosition / this.state.sliderLength) * (this.state.max - this.state.min); | ||
var nextValue = this._trimAlignValue(this.state.startValue + diffValue); | ||
@@ -421,4 +435,4 @@ | ||
for (var i = 0; i < n; i++) { | ||
if (nextValue[n - 1 - i] > this.props.max - i * this.props.minDistance) { | ||
nextValue[n - 1 - i] = this.props.max - i * this.props.minDistance; | ||
if (nextValue[n - 1 - i] > this.state.max - i * this.props.minDistance) { | ||
nextValue[n - 1 - i] = this.state.max - i * this.props.minDistance; | ||
} | ||
@@ -437,4 +451,4 @@ } | ||
for (var i = 0; i < n; i++) { | ||
if (nextValue[i] < this.props.min + i * this.props.minDistance) { | ||
nextValue[i] = this.props.min + i * this.props.minDistance; | ||
if (nextValue[i] < this.state.min + i * this.props.minDistance) { | ||
nextValue[i] = this.state.min + i * this.props.minDistance; | ||
} | ||
@@ -480,7 +494,6 @@ } | ||
_renderHandle: function (styles) { | ||
var self = this; | ||
return function (child, i) { | ||
var className = self.props.handleClassName + ' ' + | ||
(self.props.handleClassName + '-' + i) + ' ' + | ||
(self.state.index === i ? self.props.handleActiveClassName : ''); | ||
var className = this.props.handleClassName + ' ' + | ||
(this.props.handleClassName + '-' + i) + ' ' + | ||
(this.state.index === i ? this.props.handleActiveClassName : ''); | ||
@@ -493,6 +506,6 @@ return ( | ||
style: at(styles, i), | ||
onMouseDown: self._dragStart(i), | ||
onTouchStart: self._touchStart(i), | ||
onTouchMove: self._touchMove, | ||
onTouchEnd: self._onTouchEnd | ||
onMouseDown: this._dragStart(i), | ||
onTouchStart: this._touchStart(i) | ||
//onTouchMove: this._touchMove, | ||
//onTouchEnd: this._onTouchEnd | ||
}, | ||
@@ -502,3 +515,3 @@ child | ||
); | ||
} | ||
}.bind(this); | ||
}, | ||
@@ -550,3 +563,3 @@ | ||
if (this.props.disabled) return; | ||
console.log('_onSliderTouchStart'); | ||
var position = e['page' + this._axis()]; | ||
@@ -565,2 +578,3 @@ | ||
}.bind(this)); | ||
pauseEvent(e); | ||
@@ -572,5 +586,6 @@ }, | ||
if (this.props.disabled) return; | ||
console.log('_onSliderTouchStart'); | ||
var last = e.changedTouches[e.changedTouches.length - 1]; | ||
var position = last['page' + this._axis()]; | ||
this._forceValueFromPosition(position, function (i) { | ||
@@ -585,8 +600,8 @@ // Set up a drag operation. | ||
document.addEventListener('touchmove', this._touchMove, false); | ||
document.addEventListener('touchend', this._onTouchEnd, false); | ||
document.addEventListener('touchend', this._touchEnd, false); | ||
}.bind(this)); | ||
pauseEvent(e); | ||
}, | ||
render: function () { | ||
@@ -593,0 +608,0 @@ var offset = map(this.state.value, this._calcOffset, this); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1330065
98
26424
6
4
1