Skip to content

Commit b13a89d

Browse files
committed
Release v0.6.0
1 parent 4c43190 commit b13a89d

File tree

4 files changed

+104
-12
lines changed

4 files changed

+104
-12
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dist/react-input-range.js",
55
"dist/react-input-range.css"
66
],
7-
"version": "0.5.1",
7+
"version": "0.6.0",
88
"description": "React component for inputting numeric values within a range",
99
"homepage": "https://github.com/davidchin/react-input-range",
1010
"authors": [

dist/react-input-range.js

Lines changed: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ var _util = require('./util');
4444

4545
var _propTypes = require('./propTypes');
4646

47+
var internals = new WeakMap();
48+
4749
var KeyCode = {
4850
LEFT_ARROW: 37,
4951
RIGHT_ARROW: 39
@@ -71,6 +73,12 @@ function shouldUpdate(inputRange, values) {
7173
return isWithinRange(inputRange, values) && hasStepDifference(inputRange, values);
7274
}
7375

76+
function getDocument(inputRange) {
77+
var ownerDocument = inputRange.refs.inputRange.ownerDocument;
78+
79+
return ownerDocument;
80+
}
81+
7482
function getComponentClassName(inputRange) {
7583
var props = inputRange.props;
7684

@@ -217,7 +225,9 @@ var InputRange = (function (_React$Component) {
217225

218226
_get(Object.getPrototypeOf(InputRange.prototype), 'constructor', this).call(this, props);
219227

220-
(0, _util.autobind)(['handleSliderMouseMove', 'handleSliderKeyDown', 'handleTrackMouseDown'], this);
228+
internals.set(this, {});
229+
230+
(0, _util.autobind)(['handleInteractionEnd', 'handleInteractionStart', 'handleKeyDown', 'handleKeyUp', 'handleMouseDown', 'handleMouseUp', 'handleSliderKeyDown', 'handleSliderMouseMove', 'handleTouchStart', 'handleTouchEnd', 'handleTrackMouseDown'], this);
221231
}
222232

223233
_createClass(InputRange, [{
@@ -285,7 +295,7 @@ var InputRange = (function (_React$Component) {
285295
}
286296
}, {
287297
key: 'handleSliderMouseMove',
288-
value: function handleSliderMouseMove(slider, event) {
298+
value: function handleSliderMouseMove(event, slider) {
289299
if (this.props.disabled) {
290300
return;
291301
}
@@ -297,7 +307,7 @@ var InputRange = (function (_React$Component) {
297307
}
298308
}, {
299309
key: 'handleSliderKeyDown',
300-
value: function handleSliderKeyDown(slider, event) {
310+
value: function handleSliderKeyDown(event, slider) {
301311
if (this.props.disabled) {
302312
return;
303313
}
@@ -319,7 +329,7 @@ var InputRange = (function (_React$Component) {
319329
}
320330
}, {
321331
key: 'handleTrackMouseDown',
322-
value: function handleTrackMouseDown(track, position) {
332+
value: function handleTrackMouseDown(event, track, position) {
323333
if (this.props.disabled) {
324334
return;
325335
}
@@ -328,6 +338,78 @@ var InputRange = (function (_React$Component) {
328338

329339
this.updatePosition(key, position);
330340
}
341+
}, {
342+
key: 'handleInteractionStart',
343+
value: function handleInteractionStart() {
344+
var _this = internals.get(this);
345+
346+
if (!this.props.onChangeComplete || (0, _util.isDefined)(_this.startValue)) {
347+
return;
348+
}
349+
350+
_this.startValue = this.props.value;
351+
}
352+
}, {
353+
key: 'handleInteractionEnd',
354+
value: function handleInteractionEnd() {
355+
var _this = internals.get(this);
356+
357+
if (!this.props.onChangeComplete || !(0, _util.isDefined)(_this.startValue)) {
358+
return;
359+
}
360+
361+
if (_this.startValue !== this.props.value) {
362+
this.props.onChangeComplete(this, this.props.value);
363+
}
364+
365+
_this.startValue = null;
366+
}
367+
}, {
368+
key: 'handleKeyDown',
369+
value: function handleKeyDown(event) {
370+
this.handleInteractionStart(event);
371+
}
372+
}, {
373+
key: 'handleKeyUp',
374+
value: function handleKeyUp(event) {
375+
this.handleInteractionEnd(event);
376+
}
377+
}, {
378+
key: 'handleMouseDown',
379+
value: function handleMouseDown(event) {
380+
var document = getDocument(this);
381+
382+
this.handleInteractionStart(event);
383+
384+
document.addEventListener('mouseup', this.handleMouseUp);
385+
}
386+
}, {
387+
key: 'handleMouseUp',
388+
value: function handleMouseUp(event) {
389+
var document = getDocument(this);
390+
391+
this.handleInteractionEnd(event);
392+
393+
document.removeEventListener('mouseup', this.handleMouseUp);
394+
}
395+
}, {
396+
key: 'handleTouchStart',
397+
value: function handleTouchStart(event) {
398+
var document = getDocument(this);
399+
400+
this.handleInteractionStart(event);
401+
402+
document.addEventListener('touchend', this.handleTouchEnd);
403+
}
404+
}, {
405+
key: 'handleTouchEnd',
406+
value: function handleTouchEnd(event) {
407+
var document = getDocument(this);
408+
409+
this.handleInteractionEnd(event);
410+
411+
document.removeEventListener('touchend', this.handleTouchEnd);
412+
}
331413
}, {
332414
key: 'render',
333415
value: function render() {
@@ -342,7 +424,11 @@ var InputRange = (function (_React$Component) {
342424
{
343425
'aria-disabled': this.props.disabled,
344426
ref: 'inputRange',
345-
className: componentClassName },
427+
className: componentClassName,
428+
onKeyDown: this.handleKeyDown,
429+
onKeyUp: this.handleKeyUp,
430+
onMouseDown: this.handleMouseDown,
431+
onTouchStart: this.handleTouchStart },
346432
_react2['default'].createElement(
347433
_Label2['default'],
348434
{
@@ -404,6 +490,7 @@ InputRange.propTypes = {
404490
minValue: _propTypes.maxMinValuePropType,
405491
name: _react2['default'].PropTypes.string,
406492
onChange: _react2['default'].PropTypes.func.isRequired,
493+
onChangeComplete: _react2['default'].PropTypes.func,
407494
step: _react2['default'].PropTypes.number,
408495
value: _propTypes.maxMinValuePropType
409496
};
@@ -564,7 +651,7 @@ var Slider = (function (_React$Component) {
564651
}, {
565652
key: 'handleMouseMove',
566653
value: function handleMouseMove(event) {
567-
this.props.onSliderMouseMove(this, event);
654+
this.props.onSliderMouseMove(event, this);
568655
}
569656
}, {
570657
key: 'handleTouchStart',
@@ -579,7 +666,7 @@ var Slider = (function (_React$Component) {
579666
}, {
580667
key: 'handleTouchMove',
581668
value: function handleTouchMove(event) {
582-
this.props.onSliderMouseMove(this, event);
669+
this.props.onSliderMouseMove(event, this);
583670
}
584671
}, {
585672
key: 'handleTouchEnd',
@@ -594,7 +681,7 @@ var Slider = (function (_React$Component) {
594681
}, {
595682
key: 'handleKeyDown',
596683
value: function handleKeyDown(event) {
597-
this.props.onSliderKeyDown(this, event);
684+
this.props.onSliderKeyDown(event, this);
598685
}
599686
}, {
600687
key: 'render',
@@ -714,7 +801,7 @@ var Track = (function (_React$Component) {
714801
y: 0
715802
};
716803

717-
this.props.onTrackMouseDown(this, position);
804+
this.props.onTrackMouseDown(event, this, position);
718805
}
719806
}, {
720807
key: 'handleTouchStart',
@@ -883,6 +970,10 @@ function isObject(object) {
883970
return object !== null && typeof object === 'object';
884971
}
885972

973+
function isDefined(value) {
974+
return value !== undefined && value !== null;
975+
}
976+
886977
function isEmpty(obj) {
887978
if (!obj) {
888979
return true;
@@ -940,6 +1031,7 @@ var util = {
9401031
clamp: clamp,
9411032
distanceTo: distanceTo,
9421033
extend: extend,
1034+
isDefined: isDefined,
9431035
isEmpty: isEmpty,
9441036
isNumber: isNumber,
9451037
isObject: isObject,

0 commit comments

Comments
 (0)