@@ -89,6 +89,7 @@ var InputRange = (function (_React$Component) {
8989 _get ( Object . getPrototypeOf ( InputRange . prototype ) , 'constructor' , this ) . call ( this , props ) ;
9090
9191 var state = {
92+ didChange : false ,
9293 percentages : {
9394 min : 0 ,
9495 max : 0
@@ -105,7 +106,7 @@ var InputRange = (function (_React$Component) {
105106
106107 this . state = state ;
107108 this . valueTransformer = new _ValueTransformer2 [ 'default' ] ( this ) ;
108- this . isMultiValue = this . props . hasOwnProperty ( 'values' ) ;
109+ this . isMultiValue = this . props . hasOwnProperty ( 'defaultValues' ) || this . props . hasOwnProperty ( ' values') ;
109110
110111 ( 0 , _util . autobind ) ( [ 'handleSliderMouseMove' , 'handleSliderKeyDown' , 'handleTrackMouseDown' ] , this ) ;
111112 }
@@ -118,20 +119,23 @@ var InputRange = (function (_React$Component) {
118119 } , {
119120 key : 'componentWillReceiveProps' ,
120121 value : function componentWillReceiveProps ( nextProps ) {
121- this . setPositionsByProps ( nextProps ) ;
122+ var props = ( 0 , _util . omit ) ( nextProps , [ 'defaultValue' , 'defaultValues' ] ) ;
123+
124+ this . setPositionsByProps ( props ) ;
122125 }
123126 } , {
124127 key : 'shouldComponentUpdate' ,
125128 value : function shouldComponentUpdate ( nextProps , nextState ) {
126129 var currentProps = this . props ;
127130 var currentState = this . state ;
131+ var shouldUpdate = currentState . values . min !== nextState . values . min || currentState . values . max !== nextState . values . max || currentState . value !== nextState . value || currentProps . minValue !== nextProps . minValue || currentProps . maxValue !== nextProps . maxValue ;
128132
129- return currentState . values . min !== nextState . values . min || currentState . values . max !== nextState . values . max || currentState . value !== nextState . value || currentProps . minValue !== nextProps . minValue || currentProps . maxValue !== nextProps . maxValue ;
133+ return shouldUpdate ;
130134 }
131135 } , {
132136 key : 'componentDidUpdate' ,
133137 value : function componentDidUpdate ( ) {
134- if ( this . props . onChange ) {
138+ if ( this . props . onChange && this . state . didChange ) {
135139 var results = this . state . values . max ;
136140
137141 if ( this . isMultiValue ) {
@@ -140,6 +144,10 @@ var InputRange = (function (_React$Component) {
140144
141145 this . props . onChange ( this , results ) ;
142146 }
147+
148+ this . setState ( {
149+ didChange : true
150+ } ) ;
143151 }
144152 } , {
145153 key : 'setPositions' ,
@@ -189,6 +197,10 @@ var InputRange = (function (_React$Component) {
189197 } , {
190198 key : 'setPositionByValue' ,
191199 value : function setPositionByValue ( slider , value ) {
200+ if ( ! ( 0 , _util . isNumber ) ( value ) ) {
201+ return ;
202+ }
203+
192204 var validValue = ( 0 , _util . clamp ) ( value , this . props . minValue , this . props . maxValue ) ;
193205 var position = this . valueTransformer . positionFromValue ( validValue ) ;
194206
@@ -197,6 +209,10 @@ var InputRange = (function (_React$Component) {
197209 } , {
198210 key : 'setPositionsByValues' ,
199211 value : function setPositionsByValues ( values ) {
212+ if ( ! values || ! ( 0 , _util . isNumber ) ( values . min ) || ! ( 0 , _util . isNumber ) ( values . max ) ) {
213+ return ;
214+ }
215+
200216 var validValues = {
201217 min : ( 0 , _util . clamp ) ( values . min , this . props . minValue , this . props . maxValue ) ,
202218 max : ( 0 , _util . clamp ) ( values . max , this . props . minValue , this . props . maxValue )
@@ -213,9 +229,13 @@ var InputRange = (function (_React$Component) {
213229 key : 'setPositionsByProps' ,
214230 value : function setPositionsByProps ( props ) {
215231 if ( this . isMultiValue ) {
216- this . setPositionsByValues ( props . values ) ;
232+ var values = ! ( 0 , _util . isEmpty ) ( props . values ) ? props . values : props . defaultValues ;
233+
234+ this . setPositionsByValues ( values ) ;
217235 } else {
218- this . setPositionByValue ( this . refs . sliderMax , props . value ) ;
236+ var value = ( 0 , _util . isNumber ) ( props . value ) ? props . value : props . defaultValue ;
237+
238+ this . setPositionByValue ( this . refs . sliderMax , value ) ;
219239 }
220240 }
221241 } , {
@@ -237,13 +257,21 @@ var InputRange = (function (_React$Component) {
237257 } , {
238258 key : 'handleSliderMouseMove' ,
239259 value : function handleSliderMouseMove ( slider , event ) {
260+ if ( this . props . disabled ) {
261+ return ;
262+ }
263+
240264 var position = this . valueTransformer . positionFromEvent ( event ) ;
241265
242266 this . setPosition ( slider , position ) ;
243267 }
244268 } , {
245269 key : 'handleSliderKeyDown' ,
246270 value : function handleSliderKeyDown ( slider , event ) {
271+ if ( this . props . disabled ) {
272+ return ;
273+ }
274+
247275 switch ( event . keyCode ) {
248276 case KeyCode . LEFT_ARROW :
249277 this . decrementValue ( slider ) ;
@@ -260,6 +288,10 @@ var InputRange = (function (_React$Component) {
260288 } , {
261289 key : 'handleTrackMouseDown' ,
262290 value : function handleTrackMouseDown ( track , position ) {
291+ if ( this . props . disabled ) {
292+ return ;
293+ }
294+
263295 this . setPosition ( null , position ) ;
264296 }
265297 } , {
@@ -361,10 +393,18 @@ var InputRange = (function (_React$Component) {
361393 key : 'render' ,
362394 value : function render ( ) {
363395 var classNames = this . props . classNames ;
396+ var componentClassName = classNames . component ;
397+
398+ if ( this . props . disabled ) {
399+ componentClassName = componentClassName + ' is-disabled' ;
400+ }
364401
365402 return _react2 [ 'default' ] . createElement (
366403 'div' ,
367- { ref : 'inputRange' , className : classNames . component } ,
404+ {
405+ 'aria-disabled' : this . props . disabled ,
406+ ref : 'inputRange' ,
407+ className : componentClassName } ,
368408 _react2 [ 'default' ] . createElement (
369409 'span' ,
370410 { className : classNames . labelMin } ,
@@ -410,6 +450,9 @@ var InputRange = (function (_React$Component) {
410450InputRange . propTypes = {
411451 ariaLabelledby : _react2 [ 'default' ] . PropTypes . string ,
412452 classNames : _react2 [ 'default' ] . PropTypes . objectOf ( _react2 [ 'default' ] . PropTypes . string ) ,
453+ defaultValue : _propTypes . maxMinValuePropType ,
454+ defaultValues : _propTypes . maxMinValuePropType ,
455+ disabled : _react2 [ 'default' ] . PropTypes . bool ,
413456 maxValue : _propTypes . maxMinValuePropType ,
414457 minValue : _propTypes . maxMinValuePropType ,
415458 name : _react2 [ 'default' ] . PropTypes . string ,
@@ -421,9 +464,9 @@ InputRange.propTypes = {
421464
422465InputRange . defaultProps = {
423466 classNames : _defaultClassNames2 [ 'default' ] ,
467+ disabled : false ,
424468 minValue : 0 ,
425469 maxValue : 10 ,
426- value : 0 ,
427470 step : 1
428471} ;
429472
@@ -868,13 +911,15 @@ function maxMinValuePropType(props) {
868911 var minValue = props . minValue ;
869912 var value = props . value ;
870913 var values = props . values ;
914+ var defaultValue = props . defaultValue ;
915+ var defaultValues = props . defaultValues ;
871916
872- if ( ! numberPredicate ( value ) ) {
873- return new Error ( '`value` must be a number' ) ;
917+ if ( ! values && ! defaultValues && ! numberPredicate ( value ) && ! numberPredicate ( defaultValue ) ) {
918+ return new Error ( '`value` or `defaultValue` must be a number' ) ;
874919 }
875920
876- if ( ! value && ! ( 0 , _util . objectOf ) ( values , numberPredicate ) ) {
877- return new Error ( '`values` must be an object of numbers' ) ;
921+ if ( ! value && ! defaultValue && ! ( 0 , _util . objectOf ) ( values , numberPredicate ) && ! ( 0 , _util . objectOf ) ( defaultValues , numberPredicate ) ) {
922+ return new Error ( '`values` or `defaultValues` must be an object of numbers' ) ;
878923 }
879924
880925 if ( minValue >= maxValue ) {
@@ -904,6 +949,23 @@ function extend() {
904949 return Object . assign . apply ( Object , arguments ) ;
905950}
906951
952+ function includes ( array , value ) {
953+ return array . indexOf ( value ) > - 1 ;
954+ }
955+
956+ function omit ( obj , omitKeys ) {
957+ var keys = Object . keys ( obj ) ;
958+ var outputObj = { } ;
959+
960+ keys . forEach ( function ( key ) {
961+ if ( ! includes ( omitKeys , key ) ) {
962+ outputObj [ key ] = obj [ key ] ;
963+ }
964+ } ) ;
965+
966+ return outputObj ;
967+ }
968+
907969function captialize ( string ) {
908970 return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
909971}
@@ -916,6 +978,18 @@ function isNumber(number) {
916978 return typeof number === 'number' ;
917979}
918980
981+ function isEmpty ( obj ) {
982+ if ( ! obj ) {
983+ return true ;
984+ }
985+
986+ if ( Array . isArray ( obj ) ) {
987+ return obj . length === 0 ;
988+ }
989+
990+ return Object . keys ( obj ) . length === 0 ;
991+ }
992+
919993function arrayOf ( array , predicate ) {
920994 if ( ! Array . isArray ( array ) ) {
921995 return false ;
@@ -961,8 +1035,10 @@ var util = {
9611035 clamp : clamp ,
9621036 distanceTo : distanceTo ,
9631037 extend : extend ,
1038+ isEmpty : isEmpty ,
9641039 isNumber : isNumber ,
965- objectOf : objectOf
1040+ objectOf : objectOf ,
1041+ omit : omit
9661042} ;
9671043
9681044exports [ 'default' ] = util ;
0 commit comments