react-input-range
Version:
React component for inputting numeric values within a range
1,727 lines (1,423 loc) • 104 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["InputRange"] = factory(require("react"));
else
root["InputRange"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_3__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 11);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _captialize = __webpack_require__(19);
Object.defineProperty(exports, 'captialize', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_captialize).default;
}
});
var _clamp = __webpack_require__(20);
Object.defineProperty(exports, 'clamp', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_clamp).default;
}
});
var _distanceTo = __webpack_require__(21);
Object.defineProperty(exports, 'distanceTo', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_distanceTo).default;
}
});
var _isDefined = __webpack_require__(22);
Object.defineProperty(exports, 'isDefined', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_isDefined).default;
}
});
var _isNumber = __webpack_require__(23);
Object.defineProperty(exports, 'isNumber', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_isNumber).default;
}
});
var _isObject = __webpack_require__(24);
Object.defineProperty(exports, 'isObject', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_isObject).default;
}
});
var _length = __webpack_require__(25);
Object.defineProperty(exports, 'length', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_length).default;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
if (process.env.NODE_ENV !== 'production') {
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
0xeac7;
var isValidElement = function(object) {
return typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE;
};
// By explicitly using `prop-types` you are opting into new development behavior.
// http://fb.me/prop-types-in-prod
var throwOnDirectAccess = true;
module.exports = __webpack_require__(28)(isValidElement, throwOnDirectAccess);
} else {
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = __webpack_require__(27)();
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* @copyright 2015, Andrey Popp <8mayday@gmail.com>
*
* The decorator may be used on classes or methods
* ```
* @autobind
* class FullBound {}
*
* class PartBound {
* @autobind
* method () {}
* }
* ```
*/
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = autobind;
function autobind() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (args.length === 1) {
return boundClass.apply(undefined, args);
} else {
return boundMethod.apply(undefined, args);
}
}
/**
* Use boundMethod to bind all methods on the target.prototype
*/
function boundClass(target) {
// (Using reflect to get all keys including symbols)
var keys = undefined;
// Use Reflect if exists
if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') {
keys = Reflect.ownKeys(target.prototype);
} else {
keys = Object.getOwnPropertyNames(target.prototype);
// use symbols if support is provided
if (typeof Object.getOwnPropertySymbols === 'function') {
keys = keys.concat(Object.getOwnPropertySymbols(target.prototype));
}
}
keys.forEach(function (key) {
// Ignore special case target method
if (key === 'constructor') {
return;
}
var descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
// Only methods need binding
if (typeof descriptor.value === 'function') {
Object.defineProperty(target.prototype, key, boundMethod(target, key, descriptor));
}
});
return target;
}
/**
* Return a descriptor removing the value and returning a getter
* The getter will return a .bind version of the function
* and memoize the result against a symbol on the instance
*/
function boundMethod(target, key, descriptor) {
var fn = descriptor.value;
if (typeof fn !== 'function') {
throw new Error('@autobind decorator can only be applied to methods not: ' + typeof fn);
}
// In IE11 calling Object.defineProperty has a side-effect of evaluating the
// getter for the property which is being replaced. This causes infinite
// recursion and an "Out of stack space" error.
var definingProperty = false;
return {
configurable: true,
get: function get() {
if (definingProperty || this === target.prototype || this.hasOwnProperty(key)) {
return fn;
}
var boundFn = fn.bind(this);
definingProperty = true;
Object.defineProperty(this, key, {
value: boundFn,
configurable: true,
writable: true
});
definingProperty = false;
return boundFn;
}
};
}
module.exports = exports['default'];
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if (process.env.NODE_ENV !== 'production') {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Label;
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(2);
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @ignore
* @param {Object} props
* @param {InputRangeClassNames} props.classNames
* @param {Function} props.formatLabel
* @param {string} props.type
*/
function Label(props) {
var labelValue = props.formatLabel ? props.formatLabel(props.children, props.type) : props.children;
return _react2.default.createElement(
'span',
{ className: props.classNames[props.type + 'Label'] },
_react2.default.createElement(
'span',
{ className: props.classNames.labelContainer },
labelValue
)
);
}
/**
* @type {Object}
* @property {Function} children
* @property {Function} classNames
* @property {Function} formatLabel
* @property {Function} type
*/
Label.propTypes = {
children: _propTypes2.default.node.isRequired,
classNames: _propTypes2.default.objectOf(_propTypes2.default.string).isRequired,
formatLabel: _propTypes2.default.func,
type: _propTypes2.default.string.isRequired
};
module.exports = exports['default'];
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
var emptyFunction = __webpack_require__(5);
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if (process.env.NODE_ENV !== 'production') {
(function () {
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
})();
}
module.exports = warning;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _desc, _value, _class;
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(2);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _autobindDecorator = __webpack_require__(4);
var _autobindDecorator2 = _interopRequireDefault(_autobindDecorator);
var _valueTransformer = __webpack_require__(18);
var valueTransformer = _interopRequireWildcard(_valueTransformer);
var _defaultClassNames = __webpack_require__(12);
var _defaultClassNames2 = _interopRequireDefault(_defaultClassNames);
var _label = __webpack_require__(7);
var _label2 = _interopRequireDefault(_label);
var _rangePropType = __webpack_require__(14);
var _rangePropType2 = _interopRequireDefault(_rangePropType);
var _valuePropType = __webpack_require__(17);
var _valuePropType2 = _interopRequireDefault(_valuePropType);
var _slider = __webpack_require__(15);
var _slider2 = _interopRequireDefault(_slider);
var _track = __webpack_require__(16);
var _track2 = _interopRequireDefault(_track);
var _utils = __webpack_require__(1);
var _keyCodes = __webpack_require__(13);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return desc;
}
/**
* A React component that allows users to input numeric values within a range
* by dragging its sliders.
*/
var InputRange = (_class = function (_React$Component) {
_inherits(InputRange, _React$Component);
_createClass(InputRange, null, [{
key: 'propTypes',
/**
* @ignore
* @override
* @return {Object}
*/
get: function get() {
return {
allowSameValues: _propTypes2.default.bool,
ariaLabelledby: _propTypes2.default.string,
ariaControls: _propTypes2.default.string,
classNames: _propTypes2.default.objectOf(_propTypes2.default.string),
disabled: _propTypes2.default.bool,
draggableTrack: _propTypes2.default.bool,
formatLabel: _propTypes2.default.func,
maxValue: _rangePropType2.default,
minValue: _rangePropType2.default,
name: _propTypes2.default.string,
onChangeStart: _propTypes2.default.func,
onChange: _propTypes2.default.func.isRequired,
onChangeComplete: _propTypes2.default.func,
step: _propTypes2.default.number,
value: _valuePropType2.default
};
}
/**
* @ignore
* @override
* @return {Object}
*/
}, {
key: 'defaultProps',
get: function get() {
return {
allowSameValues: false,
classNames: _defaultClassNames2.default,
disabled: false,
maxValue: 10,
minValue: 0,
step: 1
};
}
/**
* @param {Object} props
* @param {boolean} [props.allowSameValues]
* @param {string} [props.ariaLabelledby]
* @param {string} [props.ariaControls]
* @param {InputRangeClassNames} [props.classNames]
* @param {boolean} [props.disabled = false]
* @param {Function} [props.formatLabel]
* @param {number|Range} [props.maxValue = 10]
* @param {number|Range} [props.minValue = 0]
* @param {string} [props.name]
* @param {string} props.onChange
* @param {Function} [props.onChangeComplete]
* @param {Function} [props.onChangeStart]
* @param {number} [props.step = 1]
* @param {number|Range} props.value
*/
}]);
function InputRange(props) {
_classCallCheck(this, InputRange);
/**
* @private
* @type {?number}
*/
var _this = _possibleConstructorReturn(this, (InputRange.__proto__ || Object.getPrototypeOf(InputRange)).call(this, props));
_this.startValue = null;
/**
* @private
* @type {?Component}
*/
_this.node = null;
/**
* @private
* @type {?Component}
*/
_this.trackNode = null;
/**
* @private
* @type {bool}
*/
_this.isSliderDragging = false;
/**
* @private
* @type {?string}
*/
_this.lastKeyMoved = null;
return _this;
}
/**
* @ignore
* @override
* @return {void}
*/
_createClass(InputRange, [{
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.removeDocumentMouseUpListener();
this.removeDocumentTouchEndListener();
}
/**
* Return the CSS class name of the component
* @private
* @return {string}
*/
}, {
key: 'getComponentClassName',
value: function getComponentClassName() {
if (!this.props.disabled) {
return this.props.classNames.inputRange;
}
return this.props.classNames.disabledInputRange;
}
/**
* Return the bounding rect of the track
* @private
* @return {ClientRect}
*/
}, {
key: 'getTrackClientRect',
value: function getTrackClientRect() {
return this.trackNode.getClientRect();
}
/**
* Return the slider key closest to a point
* @private
* @param {Point} position
* @return {string}
*/
}, {
key: 'getKeyByPosition',
value: function getKeyByPosition(position) {
var values = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
var positions = valueTransformer.getPositionsFromValues(values, this.props.minValue, this.props.maxValue, this.getTrackClientRect());
if (this.isMultiValue()) {
var distanceToMin = (0, _utils.distanceTo)(position, positions.min);
var distanceToMax = (0, _utils.distanceTo)(position, positions.max);
if (distanceToMin < distanceToMax) {
return 'min';
}
}
return 'max';
}
/**
* Return all the slider keys
* @private
* @return {string[]}
*/
}, {
key: 'getKeys',
value: function getKeys() {
if (this.isMultiValue()) {
return ['min', 'max'];
}
return ['max'];
}
/**
* Return true if the difference between the new and the current value is
* greater or equal to the step amount of the component
* @private
* @param {Range} values
* @return {boolean}
*/
}, {
key: 'hasStepDifference',
value: function hasStepDifference(values) {
var currentValues = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
return (0, _utils.length)(values.min, currentValues.min) >= this.props.step || (0, _utils.length)(values.max, currentValues.max) >= this.props.step;
}
/**
* Return true if the component accepts a min and max value
* @private
* @return {boolean}
*/
}, {
key: 'isMultiValue',
value: function isMultiValue() {
return (0, _utils.isObject)(this.props.value);
}
/**
* Return true if the range is within the max and min value of the component
* @private
* @param {Range} values
* @return {boolean}
*/
}, {
key: 'isWithinRange',
value: function isWithinRange(values) {
if (this.isMultiValue()) {
return values.min >= this.props.minValue && values.max <= this.props.maxValue && this.props.allowSameValues ? values.min <= values.max : values.min < values.max;
}
return values.max >= this.props.minValue && values.max <= this.props.maxValue;
}
/**
* Return true if the new value should trigger a render
* @private
* @param {Range} values
* @return {boolean}
*/
}, {
key: 'shouldUpdate',
value: function shouldUpdate(values) {
return this.isWithinRange(values) && this.hasStepDifference(values);
}
/**
* Update the position of a slider
* @private
* @param {string} key
* @param {Point} position
* @return {void}
*/
}, {
key: 'updatePosition',
value: function updatePosition(key, position) {
var values = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
var positions = valueTransformer.getPositionsFromValues(values, this.props.minValue, this.props.maxValue, this.getTrackClientRect());
positions[key] = position;
this.lastKeyMoved = key;
this.updatePositions(positions);
}
/**
* Update the positions of multiple sliders
* @private
* @param {Object} positions
* @param {Point} positions.min
* @param {Point} positions.max
* @return {void}
*/
}, {
key: 'updatePositions',
value: function updatePositions(positions) {
var values = {
min: valueTransformer.getValueFromPosition(positions.min, this.props.minValue, this.props.maxValue, this.getTrackClientRect()),
max: valueTransformer.getValueFromPosition(positions.max, this.props.minValue, this.props.maxValue, this.getTrackClientRect())
};
var transformedValues = {
min: valueTransformer.getStepValueFromValue(values.min, this.props.step),
max: valueTransformer.getStepValueFromValue(values.max, this.props.step)
};
this.updateValues(transformedValues);
}
/**
* Update the value of a slider
* @private
* @param {string} key
* @param {number} value
* @return {void}
*/
}, {
key: 'updateValue',
value: function updateValue(key, value) {
var values = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
values[key] = value;
this.updateValues(values);
}
/**
* Update the values of multiple sliders
* @private
* @param {Range|number} values
* @return {void}
*/
}, {
key: 'updateValues',
value: function updateValues(values) {
if (!this.shouldUpdate(values)) {
return;
}
this.props.onChange(this.isMultiValue() ? values : values.max);
}
/**
* Increment the value of a slider by key name
* @private
* @param {string} key
* @return {void}
*/
}, {
key: 'incrementValue',
value: function incrementValue(key) {
var values = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
var value = values[key] + this.props.step;
this.updateValue(key, value);
}
/**
* Decrement the value of a slider by key name
* @private
* @param {string} key
* @return {void}
*/
}, {
key: 'decrementValue',
value: function decrementValue(key) {
var values = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
var value = values[key] - this.props.step;
this.updateValue(key, value);
}
/**
* Listen to mouseup event
* @private
* @return {void}
*/
}, {
key: 'addDocumentMouseUpListener',
value: function addDocumentMouseUpListener() {
this.removeDocumentMouseUpListener();
this.node.ownerDocument.addEventListener('mouseup', this.handleMouseUp);
}
/**
* Listen to touchend event
* @private
* @return {void}
*/
}, {
key: 'addDocumentTouchEndListener',
value: function addDocumentTouchEndListener() {
this.removeDocumentTouchEndListener();
this.node.ownerDocument.addEventListener('touchend', this.handleTouchEnd);
}
/**
* Stop listening to mouseup event
* @private
* @return {void}
*/
}, {
key: 'removeDocumentMouseUpListener',
value: function removeDocumentMouseUpListener() {
this.node.ownerDocument.removeEventListener('mouseup', this.handleMouseUp);
}
/**
* Stop listening to touchend event
* @private
* @return {void}
*/
}, {
key: 'removeDocumentTouchEndListener',
value: function removeDocumentTouchEndListener() {
this.node.ownerDocument.removeEventListener('touchend', this.handleTouchEnd);
}
/**
* Handle any "mousemove" event received by the slider
* @private
* @param {SyntheticEvent} event
* @param {string} key
* @return {void}
*/
}, {
key: 'handleSliderDrag',
value: function handleSliderDrag(event, key) {
var _this2 = this;
if (this.props.disabled) {
return;
}
var position = valueTransformer.getPositionFromEvent(event, this.getTrackClientRect());
this.isSliderDragging = true;
requestAnimationFrame(function () {
return _this2.updatePosition(key, position);
});
}
/**
* Handle any "mousemove" event received by the track
* @private
* @param {SyntheticEvent} event
* @return {void}
*/
}, {
key: 'handleTrackDrag',
value: function handleTrackDrag(event, prevEvent) {
if (this.props.disabled || !this.props.draggableTrack || this.isSliderDragging) {
return;
}
var _props = this.props,
maxValue = _props.maxValue,
minValue = _props.minValue,
_props$value = _props.value,
max = _props$value.max,
min = _props$value.min;
var position = valueTransformer.getPositionFromEvent(event, this.getTrackClientRect());
var value = valueTransformer.getValueFromPosition(position, minValue, maxValue, this.getTrackClientRect());
var stepValue = valueTransformer.getStepValueFromValue(value, this.props.step);
var prevPosition = valueTransformer.getPositionFromEvent(prevEvent, this.getTrackClientRect());
var prevValue = valueTransformer.getValueFromPosition(prevPosition, minValue, maxValue, this.getTrackClientRect());
var prevStepValue = valueTransformer.getStepValueFromValue(prevValue, this.props.step);
var offset = prevStepValue - stepValue;
var transformedValues = {
min: min - offset,
max: max - offset
};
this.updateValues(transformedValues);
}
/**
* Handle any "keydown" event received by the slider
* @private
* @param {SyntheticEvent} event
* @param {string} key
* @return {void}
*/
}, {
key: 'handleSliderKeyDown',
value: function handleSliderKeyDown(event, key) {
if (this.props.disabled) {
return;
}
switch (event.keyCode) {
case _keyCodes.LEFT_ARROW:
case _keyCodes.DOWN_ARROW:
event.preventDefault();
this.decrementValue(key);
break;
case _keyCodes.RIGHT_ARROW:
case _keyCodes.UP_ARROW:
event.preventDefault();
this.incrementValue(key);
break;
default:
break;
}
}
/**
* Handle any "mousedown" event received by the track
* @private
* @param {SyntheticEvent} event
* @param {Point} position
* @return {void}
*/
}, {
key: 'handleTrackMouseDown',
value: function handleTrackMouseDown(event, position) {
if (this.props.disabled) {
return;
}
var _props2 = this.props,
maxValue = _props2.maxValue,
minValue = _props2.minValue,
_props2$value = _props2.value,
max = _props2$value.max,
min = _props2$value.min;
event.preventDefault();
var value = valueTransformer.getValueFromPosition(position, minValue, maxValue, this.getTrackClientRect());
var stepValue = valueTransformer.getStepValueFromValue(value, this.props.step);
if (!this.props.draggableTrack || stepValue > max || stepValue < min) {
this.updatePosition(this.getKeyByPosition(position), position);
}
}
/**
* Handle the start of any mouse/touch event
* @private
* @return {void}
*/
}, {
key: 'handleInteractionStart',
value: function handleInteractionStart() {
if (this.props.onChangeStart) {
this.props.onChangeStart(this.props.value);
}
if (this.props.onChangeComplete && !(0, _utils.isDefined)(this.startValue)) {
this.startValue = this.props.value;
}
}
/**
* Handle the end of any mouse/touch event
* @private
* @return {void}
*/
}, {
key: 'handleInteractionEnd',
value: function handleInteractionEnd() {
if (this.isSliderDragging) {
this.isSliderDragging = false;
}
if (!this.props.onChangeComplete || !(0, _utils.isDefined)(this.startValue)) {
return;
}
if (this.startValue !== this.props.value) {
this.props.onChangeComplete(this.props.value);
}
this.startValue = null;
}
/**
* Handle any "keydown" event received by the component
* @private
* @param {SyntheticEvent} event
* @return {void}
*/
}, {
key: 'handleKeyDown',
value: function handleKeyDown(event) {
this.handleInteractionStart(event);
}
/**
* Handle any "keyup" event received by the component
* @private
* @param {SyntheticEvent} event
* @return {void}
*/
}, {
key: 'handleKeyUp',
value: function handleKeyUp(event) {
this.handleInteractionEnd(event);
}
/**
* Handle any "mousedown" event received by the component
* @private
* @param {SyntheticEvent} event
* @return {void}
*/
}, {
key: 'handleMouseDown',
value: function handleMouseDown(event) {
this.handleInteractionStart(event);
this.addDocumentMouseUpListener();
}
/**
* Handle any "mouseup" event received by the component
* @private
* @param {SyntheticEvent} event
*/
}, {
key: 'handleMouseUp',
value: function handleMouseUp(event) {
this.handleInteractionEnd(event);
this.removeDocumentMouseUpListener();
}
/**
* Handle any "touchstart" event received by the component
* @private
* @param {SyntheticEvent} event
* @return {void}
*/
}, {
key: 'handleTouchStart',
value: function handleTouchStart(event) {
this.handleInteractionStart(event);
this.addDocumentTouchEndListener();
}
/**
* Handle any "touchend" event received by the component
* @private
* @param {SyntheticEvent} event
*/
}, {
key: 'handleTouchEnd',
value: function handleTouchEnd(event) {
this.handleInteractionEnd(event);
this.removeDocumentTouchEndListener();
}
/**
* Return JSX of sliders
* @private
* @return {JSX.Element}
*/
}, {
key: 'renderSliders',
value: function renderSliders() {
var _this3 = this;
var values = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
var percentages = valueTransformer.getPercentagesFromValues(values, this.props.minValue, this.props.maxValue);
var keys = this.props.allowSameValues && this.lastKeyMoved === 'min' ? this.getKeys().reverse() : this.getKeys();
return keys.map(function (key) {
var value = values[key];
var percentage = percentages[key];
var _props3 = _this3.props,
maxValue = _props3.maxValue,
minValue = _props3.minValue;
if (key === 'min') {
maxValue = values.max;
} else {
minValue = values.min;
}
var slider = _react2.default.createElement(_slider2.default, {
ariaLabelledby: _this3.props.ariaLabelledby,
ariaControls: _this3.props.ariaControls,
classNames: _this3.props.classNames,
formatLabel: _this3.props.formatLabel,
key: key,
maxValue: maxValue,
minValue: minValue,
onSliderDrag: _this3.handleSliderDrag,
onSliderKeyDown: _this3.handleSliderKeyDown,
percentage: percentage,
type: key,
value: value });
return slider;
});
}
/**
* Return JSX of hidden inputs
* @private
* @return {JSX.Element}
*/
}, {
key: 'renderHiddenInputs',
value: function renderHiddenInputs() {
var _this4 = this;
if (!this.props.name) {
return [];
}
var isMultiValue = this.isMultiValue();
var values = valueTransformer.getValueFromProps(this.props, isMultiValue);
return this.getKeys().map(function (key) {
var value = values[key];
var name = isMultiValue ? '' + _this4.props.name + (0, _utils.captialize)(key) : _this4.props.name;
return _react2.default.createElement('input', { key: key, type: 'hidden', name: name, value: value });
});
}
/**
* @ignore
* @override
* @return {JSX.Element}
*/
}, {
key: 'render',
value: function render() {
var _this5 = this;
var componentClassName = this.getComponentClassName();
var values = valueTransformer.getValueFromProps(this.props, this.isMultiValue());
var percentages = valueTransformer.getPercentagesFromValues(values, this.props.minValue, this.props.maxValue);
return _react2.default.createElement(
'div',
{
'aria-disabled': this.props.disabled,
ref: function ref(node) {
_this5.node = node;
},
className: componentClassName,
onKeyDown: this.handleKeyDown,
onKeyUp: this.handleKeyUp,
onMouseDown: this.handleMouseDown,
onTouchStart: this.handleTouchStart },
_react2.default.createElement(
_label2.default,
{
classNames: this.props.classNames,
formatLabel: this.props.formatLabel,
type: 'min' },
this.props.minValue
),
_react2.default.createElement(
_track2.default,
{
classNames: this.props.classNames,
draggableTrack: this.props.draggableTrack,
ref: function ref(trackNode) {
_this5.trackNode = trackNode;
},
percentages: percentages,
onTrackDrag: this.handleTrackDrag,
onTrackMouseDown: this.handleTrackMouseDown },
this.renderSliders()
),
_react2.default.createElement(
_label2.default,
{
classNames: this.props.classNames,
formatLabel: this.props.formatLabel,
type: 'max' },
this.props.maxValue
),
this.renderHiddenInputs()
);
}
}]);
return InputRange;
}(_react2.default.Component), (_applyDecoratedDescriptor(_class.prototype, 'handleSliderDrag', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleSliderDrag'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleTrackDrag', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleTrackDrag'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleSliderKeyDown', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleSliderKeyDown'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleTrackMouseDown', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleTrackMouseDown'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleInteractionStart', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleInteractionStart'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleInteractionEnd', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleInteractionEnd'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleKeyDown', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleKeyDown'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleKeyUp', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleKeyUp'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleMouseDown', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleMouseDown'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleMouseUp', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleMouseUp'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleTouchStart', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleTouchStart'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleTouchEnd', [_autobindDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'handleTouchEnd'), _class.prototype)), _class);
exports.default = InputRange;
module.exports = exports['default'];
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _inputRange = __webpack_require__(10);
var _inputRange2 = _interopRequireDefault(_inputRange);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @ignore
* @typedef {Object} ClientRect
* @property {number} height
* @property {number} left
* @property {number} top
* @property {number} width
*/
/**
* @typedef {Object} InputRangeClassNames
* @property {string} activeTrack
* @property {string} disabledInputRange
* @property {string} inputRange
* @property {string} labelContainer
* @property {string} maxLabel
* @property {string} minLabel
* @property {string} slider
* @property {string} sliderContainer
* @property {string} track
* @property {string} valueLabel
*/
/**
* @typedef {Function} LabelFormatter
* @param {number} value
* @param {string} type
* @return {string}
*/
/**
* @ignore
* @typedef {Object} Point
* @property {number} x
* @property {number} y
*/
/**
* @typedef {Object} Range
* @property {number} min - Min value
* @property {number} max - Max value
*/
exports.default = _inputRange2.default;
module.exports = exports['default'];
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProp