rc-slider
Advanced tools
Comparing version
@@ -30,2 +30,18 @@ 'use strict'; | ||
function getValueFromIndex(props) { | ||
var value; | ||
var marksLen = props.marks.length; | ||
var index; | ||
if ('index' in props) { | ||
index = props.index; | ||
} else { | ||
index = props.defaultIndex; | ||
} | ||
if (marksLen > 0) { | ||
value = (props.max - props.min) / (marksLen - 1) * index; | ||
value = value.toFixed(5); | ||
} | ||
return value; | ||
} | ||
var Slider = React.createClass({ | ||
@@ -40,2 +56,4 @@ displayName: 'Slider', | ||
defaultIndex: React.PropTypes.number, | ||
value: React.PropTypes.number, | ||
index: React.PropTypes.number, | ||
marks: React.PropTypes.array, | ||
@@ -68,9 +86,10 @@ isIncluded: React.PropTypes.bool, | ||
var value = props.defaultValue; | ||
if ('value' in props) { | ||
value = props.value; | ||
} | ||
value = this._trimAlignValue(value); | ||
var marksLen = props.marks.length; | ||
if (marksLen > 0) { | ||
value = (props.max - props.min) / (marksLen - 1) * props.defaultIndex; | ||
value = value.toFixed(5); | ||
value = getValueFromIndex(props); | ||
} | ||
return { | ||
@@ -81,2 +100,14 @@ value: value | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | ||
if ('value' in nextProps) { | ||
this.setState({ | ||
value: nextProps.value | ||
}); | ||
} else if ('index' in nextProps) { | ||
this.setState({ | ||
value: getValueFromIndex(nextProps) | ||
}); | ||
} | ||
}, | ||
getIndex: function getIndex() { | ||
@@ -83,0 +114,0 @@ var props = this.props; |
{ | ||
"name": "rc-slider", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "slider ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21267
3.37%522
6.1%0
-100%