rc-slider
Advanced tools
Comparing version 9.3.0 to 9.3.1
@@ -33,3 +33,3 @@ import React from 'react'; | ||
handleMouseUp: () => void; | ||
handleMouseDown: () => void; | ||
handleMouseDown: (e: any) => void; | ||
handleBlur: () => void; | ||
@@ -36,0 +36,0 @@ handleKeyDown: () => void; |
@@ -46,4 +46,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
_this.handleMouseDown = function () { | ||
// fix https://github.com/ant-design/ant-design/issues/15324 | ||
_this.handleMouseDown = function (e) { | ||
// avoid selecting text during drag | ||
// https://github.com/ant-design/ant-design/issues/25010 | ||
e.preventDefault(); // fix https://github.com/ant-design/ant-design/issues/15324 | ||
_this.focus(); | ||
@@ -50,0 +53,0 @@ }; |
908
es/Range.js
@@ -48,545 +48,539 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
var Range = | ||
/** @class */ | ||
function () { | ||
var Range = /*#__PURE__*/function (_React$Component) { | ||
_inherits(Range, _React$Component); | ||
var Range = /*#__PURE__*/function (_React$Component) { | ||
_inherits(Range, _React$Component); | ||
var _super = _createSuper(Range); | ||
var _super = _createSuper(Range); | ||
function Range(props) { | ||
var _this; | ||
function Range(props) { | ||
var _this; | ||
_classCallCheck(this, Range); | ||
_classCallCheck(this, Range); | ||
_this = _super.call(this, props); | ||
_this = _super.call(this, props); | ||
_this.onEnd = function (force) { | ||
var handle = _this.state.handle; | ||
_this.onEnd = function (force) { | ||
var handle = _this.state.handle; | ||
_this.removeDocumentEvents(); | ||
_this.removeDocumentEvents(); | ||
if (handle !== null || force) { | ||
_this.props.onAfterChange(_this.getValue()); | ||
} | ||
if (handle !== null || force) { | ||
_this.props.onAfterChange(_this.getValue()); | ||
} | ||
_this.setState({ | ||
handle: null | ||
}); | ||
}; | ||
_this.setState({ | ||
handle: null | ||
}); | ||
}; | ||
var count = props.count, | ||
min = props.min, | ||
max = props.max; | ||
var initialValue = Array.apply(void 0, _toConsumableArray(Array(count + 1))).map(function () { | ||
return min; | ||
var count = props.count, | ||
min = props.min, | ||
max = props.max; | ||
var initialValue = Array.apply(void 0, _toConsumableArray(Array(count + 1))).map(function () { | ||
return min; | ||
}); | ||
var defaultValue = 'defaultValue' in props ? props.defaultValue : initialValue; | ||
var value = props.value !== undefined ? props.value : defaultValue; | ||
var bounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
handle: i, | ||
props: props | ||
}); | ||
var defaultValue = 'defaultValue' in props ? props.defaultValue : initialValue; | ||
var value = props.value !== undefined ? props.value : defaultValue; | ||
var bounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
handle: i, | ||
props: props | ||
}); | ||
}); | ||
var recent = bounds[0] === max ? 0 : bounds.length - 1; | ||
_this.state = { | ||
handle: null, | ||
recent: recent, | ||
bounds: bounds | ||
}; | ||
return _this; | ||
} | ||
/** | ||
* [Legacy] Used for inherit other component. | ||
* It's a bad code style which should be refactor. | ||
*/ | ||
}); | ||
var recent = bounds[0] === max ? 0 : bounds.length - 1; | ||
_this.state = { | ||
handle: null, | ||
recent: recent, | ||
bounds: bounds | ||
}; | ||
return _this; | ||
} | ||
/** | ||
* [Legacy] Used for inherit other component. | ||
* It's a bad code style which should be refactor. | ||
*/ | ||
/* eslint-disable @typescript-eslint/no-unused-vars, class-methods-use-this */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars, class-methods-use-this */ | ||
_createClass(Range, [{ | ||
key: "calcValueByPos", | ||
value: function calcValueByPos(value) { | ||
return 0; | ||
_createClass(Range, [{ | ||
key: "calcValueByPos", | ||
value: function calcValueByPos(value) { | ||
return 0; | ||
} | ||
}, { | ||
key: "calcOffset", | ||
value: function calcOffset(value) { | ||
return 0; | ||
} | ||
}, { | ||
key: "saveHandle", | ||
value: function saveHandle(index, h) {} | ||
}, { | ||
key: "removeDocumentEvents", | ||
value: function removeDocumentEvents() {} | ||
}, { | ||
key: "componentDidUpdate", | ||
value: function componentDidUpdate(prevProps, prevState) { | ||
var _this2 = this; | ||
if (!('value' in this.props || 'min' in this.props || 'max' in this.props)) { | ||
return; | ||
} | ||
}, { | ||
key: "calcOffset", | ||
value: function calcOffset(value) { | ||
return 0; | ||
if (this.props.min === prevProps.min && this.props.max === prevProps.max && shallowEqual(this.props.value, prevProps.value)) { | ||
return; | ||
} | ||
}, { | ||
key: "saveHandle", | ||
value: function saveHandle(index, h) {} | ||
}, { | ||
key: "removeDocumentEvents", | ||
value: function removeDocumentEvents() {} | ||
}, { | ||
key: "componentDidUpdate", | ||
value: function componentDidUpdate(prevProps, prevState) { | ||
var _this2 = this; | ||
if (!('value' in this.props || 'min' in this.props || 'max' in this.props)) { | ||
return; | ||
} | ||
var _this$props = this.props, | ||
onChange = _this$props.onChange, | ||
value = _this$props.value; | ||
var currentValue = value || prevState.bounds; | ||
if (this.props.min === prevProps.min && this.props.max === prevProps.max && shallowEqual(this.props.value, prevProps.value)) { | ||
return; | ||
} | ||
if (currentValue.some(function (v) { | ||
return utils.isValueOutOfRange(v, _this2.props); | ||
})) { | ||
var newValues = currentValue.map(function (v) { | ||
return utils.ensureValueInRange(v, _this2.props); | ||
}); | ||
onChange(newValues); | ||
} | ||
} | ||
}, { | ||
key: "onChange", | ||
value: function onChange(state) { | ||
var props = this.props; | ||
var isNotControlled = !('value' in props); | ||
var _this$props = this.props, | ||
onChange = _this$props.onChange, | ||
value = _this$props.value; | ||
var currentValue = value || prevState.bounds; | ||
if (isNotControlled) { | ||
this.setState(state); | ||
} else { | ||
var controlledState = {}; | ||
['handle', 'recent'].forEach(function (item) { | ||
if (state[item] !== undefined) { | ||
controlledState[item] = state[item]; | ||
} | ||
}); | ||
if (currentValue.some(function (v) { | ||
return utils.isValueOutOfRange(v, _this2.props); | ||
})) { | ||
var newValues = currentValue.map(function (v) { | ||
return utils.ensureValueInRange(v, _this2.props); | ||
}); | ||
onChange(newValues); | ||
if (Object.keys(controlledState).length) { | ||
this.setState(controlledState); | ||
} | ||
} | ||
}, { | ||
key: "onChange", | ||
value: function onChange(state) { | ||
var props = this.props; | ||
var isNotControlled = !('value' in props); | ||
if (isNotControlled) { | ||
this.setState(state); | ||
} else { | ||
var controlledState = {}; | ||
['handle', 'recent'].forEach(function (item) { | ||
if (state[item] !== undefined) { | ||
controlledState[item] = state[item]; | ||
} | ||
}); | ||
var data = _objectSpread(_objectSpread({}, this.state), state); | ||
if (Object.keys(controlledState).length) { | ||
this.setState(controlledState); | ||
} | ||
} | ||
var changedValue = data.bounds; | ||
props.onChange(changedValue); | ||
} | ||
}, { | ||
key: "onStart", | ||
value: function onStart(position) { | ||
var props = this.props, | ||
state = this.state; | ||
var bounds = this.getValue(); | ||
props.onBeforeChange(bounds); | ||
var value = this.calcValueByPos(position); | ||
this.startValue = value; | ||
this.startPosition = position; | ||
var closestBound = this.getClosestBound(value); | ||
this.prevMovedHandleIndex = this.getBoundNeedMoving(value, closestBound); | ||
this.setState({ | ||
handle: this.prevMovedHandleIndex, | ||
recent: this.prevMovedHandleIndex | ||
}); | ||
var prevValue = bounds[this.prevMovedHandleIndex]; | ||
if (value === prevValue) return; | ||
var data = _objectSpread(_objectSpread({}, this.state), state); | ||
var nextBounds = _toConsumableArray(state.bounds); | ||
var changedValue = data.bounds; | ||
props.onChange(changedValue); | ||
} | ||
}, { | ||
key: "onStart", | ||
value: function onStart(position) { | ||
var props = this.props, | ||
state = this.state; | ||
var bounds = this.getValue(); | ||
props.onBeforeChange(bounds); | ||
var value = this.calcValueByPos(position); | ||
this.startValue = value; | ||
this.startPosition = position; | ||
var closestBound = this.getClosestBound(value); | ||
this.prevMovedHandleIndex = this.getBoundNeedMoving(value, closestBound); | ||
this.setState({ | ||
handle: this.prevMovedHandleIndex, | ||
recent: this.prevMovedHandleIndex | ||
}); | ||
var prevValue = bounds[this.prevMovedHandleIndex]; | ||
if (value === prevValue) return; | ||
nextBounds[this.prevMovedHandleIndex] = value; | ||
this.onChange({ | ||
bounds: nextBounds | ||
}); | ||
} | ||
}, { | ||
key: "onMove", | ||
value: function onMove(e, position) { | ||
utils.pauseEvent(e); | ||
var state = this.state; | ||
var value = this.calcValueByPos(position); | ||
var oldValue = state.bounds[state.handle]; | ||
if (value === oldValue) return; | ||
this.moveTo(value); | ||
} | ||
}, { | ||
key: "onKeyboard", | ||
value: function onKeyboard(e) { | ||
var _this$props2 = this.props, | ||
reverse = _this$props2.reverse, | ||
vertical = _this$props2.vertical; | ||
var valueMutator = utils.getKeyboardValueMutator(e, vertical, reverse); | ||
var nextBounds = _toConsumableArray(state.bounds); | ||
if (valueMutator) { | ||
utils.pauseEvent(e); | ||
var state = this.state, | ||
props = this.props; | ||
var bounds = state.bounds, | ||
handle = state.handle; | ||
var oldValue = bounds[handle === null ? state.recent : handle]; | ||
var mutatedValue = valueMutator(oldValue, props); | ||
nextBounds[this.prevMovedHandleIndex] = value; | ||
this.onChange({ | ||
bounds: nextBounds | ||
var value = _trimAlignValue({ | ||
value: mutatedValue, | ||
handle: handle, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
} | ||
}, { | ||
key: "onMove", | ||
value: function onMove(e, position) { | ||
utils.pauseEvent(e); | ||
var state = this.state; | ||
var value = this.calcValueByPos(position); | ||
var oldValue = state.bounds[state.handle]; | ||
if (value === oldValue) return; | ||
this.moveTo(value); | ||
var isFromKeyboardEvent = true; | ||
this.moveTo(value, isFromKeyboardEvent); | ||
} | ||
}, { | ||
key: "onKeyboard", | ||
value: function onKeyboard(e) { | ||
var _this$props2 = this.props, | ||
reverse = _this$props2.reverse, | ||
vertical = _this$props2.vertical; | ||
var valueMutator = utils.getKeyboardValueMutator(e, vertical, reverse); | ||
} | ||
}, { | ||
key: "getValue", | ||
value: function getValue() { | ||
return this.state.bounds; | ||
} | ||
}, { | ||
key: "getClosestBound", | ||
value: function getClosestBound(value) { | ||
var bounds = this.state.bounds; | ||
var closestBound = 0; | ||
if (valueMutator) { | ||
utils.pauseEvent(e); | ||
var state = this.state, | ||
props = this.props; | ||
var bounds = state.bounds, | ||
handle = state.handle; | ||
var oldValue = bounds[handle === null ? state.recent : handle]; | ||
var mutatedValue = valueMutator(oldValue, props); | ||
var value = _trimAlignValue({ | ||
value: mutatedValue, | ||
handle: handle, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
if (value === oldValue) return; | ||
var isFromKeyboardEvent = true; | ||
this.moveTo(value, isFromKeyboardEvent); | ||
for (var i = 1; i < bounds.length - 1; i += 1) { | ||
if (value >= bounds[i]) { | ||
closestBound = i; | ||
} | ||
} | ||
}, { | ||
key: "getValue", | ||
value: function getValue() { | ||
return this.state.bounds; | ||
if (Math.abs(bounds[closestBound + 1] - value) < Math.abs(bounds[closestBound] - value)) { | ||
closestBound += 1; | ||
} | ||
}, { | ||
key: "getClosestBound", | ||
value: function getClosestBound(value) { | ||
var bounds = this.state.bounds; | ||
var closestBound = 0; | ||
for (var i = 1; i < bounds.length - 1; i += 1) { | ||
if (value >= bounds[i]) { | ||
closestBound = i; | ||
} | ||
} | ||
return closestBound; | ||
} | ||
}, { | ||
key: "getBoundNeedMoving", | ||
value: function getBoundNeedMoving(value, closestBound) { | ||
var _this$state = this.state, | ||
bounds = _this$state.bounds, | ||
recent = _this$state.recent; | ||
var boundNeedMoving = closestBound; | ||
var isAtTheSamePoint = bounds[closestBound + 1] === bounds[closestBound]; | ||
if (Math.abs(bounds[closestBound + 1] - value) < Math.abs(bounds[closestBound] - value)) { | ||
closestBound += 1; | ||
} | ||
if (isAtTheSamePoint && bounds[recent] === bounds[closestBound]) { | ||
boundNeedMoving = recent; | ||
} | ||
return closestBound; | ||
if (isAtTheSamePoint && value !== bounds[closestBound + 1]) { | ||
boundNeedMoving = value < bounds[closestBound + 1] ? closestBound : closestBound + 1; | ||
} | ||
}, { | ||
key: "getBoundNeedMoving", | ||
value: function getBoundNeedMoving(value, closestBound) { | ||
var _this$state = this.state, | ||
bounds = _this$state.bounds, | ||
recent = _this$state.recent; | ||
var boundNeedMoving = closestBound; | ||
var isAtTheSamePoint = bounds[closestBound + 1] === bounds[closestBound]; | ||
if (isAtTheSamePoint && bounds[recent] === bounds[closestBound]) { | ||
boundNeedMoving = recent; | ||
} | ||
return boundNeedMoving; | ||
} | ||
}, { | ||
key: "getLowerBound", | ||
value: function getLowerBound() { | ||
return this.state.bounds[0]; | ||
} | ||
}, { | ||
key: "getUpperBound", | ||
value: function getUpperBound() { | ||
var bounds = this.state.bounds; | ||
return bounds[bounds.length - 1]; | ||
} | ||
/** | ||
* Returns an array of possible slider points, taking into account both | ||
* `marks` and `step`. The result is cached. | ||
*/ | ||
if (isAtTheSamePoint && value !== bounds[closestBound + 1]) { | ||
boundNeedMoving = value < bounds[closestBound + 1] ? closestBound : closestBound + 1; | ||
} | ||
}, { | ||
key: "getPoints", | ||
value: function getPoints() { | ||
var _this$props3 = this.props, | ||
marks = _this$props3.marks, | ||
step = _this$props3.step, | ||
min = _this$props3.min, | ||
max = _this$props3.max; | ||
var cache = this.internalPointsCache; | ||
return boundNeedMoving; | ||
} | ||
}, { | ||
key: "getLowerBound", | ||
value: function getLowerBound() { | ||
return this.state.bounds[0]; | ||
} | ||
}, { | ||
key: "getUpperBound", | ||
value: function getUpperBound() { | ||
var bounds = this.state.bounds; | ||
return bounds[bounds.length - 1]; | ||
} | ||
/** | ||
* Returns an array of possible slider points, taking into account both | ||
* `marks` and `step`. The result is cached. | ||
*/ | ||
if (!cache || cache.marks !== marks || cache.step !== step) { | ||
var pointsObject = _objectSpread({}, marks); | ||
}, { | ||
key: "getPoints", | ||
value: function getPoints() { | ||
var _this$props3 = this.props, | ||
marks = _this$props3.marks, | ||
step = _this$props3.step, | ||
min = _this$props3.min, | ||
max = _this$props3.max; | ||
var cache = this.internalPointsCache; | ||
if (!cache || cache.marks !== marks || cache.step !== step) { | ||
var pointsObject = _objectSpread({}, marks); | ||
if (step !== null) { | ||
for (var point = min; point <= max; point += step) { | ||
pointsObject[point] = point; | ||
} | ||
if (step !== null) { | ||
for (var point = min; point <= max; point += step) { | ||
pointsObject[point] = point; | ||
} | ||
var points = Object.keys(pointsObject).map(parseFloat); | ||
points.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
this.internalPointsCache = { | ||
marks: marks, | ||
step: step, | ||
points: points | ||
}; | ||
} | ||
return this.internalPointsCache.points; | ||
var points = Object.keys(pointsObject).map(parseFloat); | ||
points.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
this.internalPointsCache = { | ||
marks: marks, | ||
step: step, | ||
points: points | ||
}; | ||
} | ||
}, { | ||
key: "moveTo", | ||
value: function moveTo(value, isFromKeyboardEvent) { | ||
var _this3 = this; | ||
var state = this.state, | ||
props = this.props; | ||
return this.internalPointsCache.points; | ||
} | ||
}, { | ||
key: "moveTo", | ||
value: function moveTo(value, isFromKeyboardEvent) { | ||
var _this3 = this; | ||
var nextBounds = _toConsumableArray(state.bounds); | ||
var state = this.state, | ||
props = this.props; | ||
var handle = state.handle === null ? state.recent : state.handle; | ||
nextBounds[handle] = value; | ||
var nextHandle = handle; | ||
var nextBounds = _toConsumableArray(state.bounds); | ||
if (props.pushable !== false) { | ||
this.pushSurroundingHandles(nextBounds, nextHandle); | ||
} else if (props.allowCross) { | ||
nextBounds.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
nextHandle = nextBounds.indexOf(value); | ||
} | ||
var handle = state.handle === null ? state.recent : state.handle; | ||
nextBounds[handle] = value; | ||
var nextHandle = handle; | ||
this.onChange({ | ||
recent: nextHandle, | ||
handle: nextHandle, | ||
bounds: nextBounds | ||
if (props.pushable !== false) { | ||
this.pushSurroundingHandles(nextBounds, nextHandle); | ||
} else if (props.allowCross) { | ||
nextBounds.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
nextHandle = nextBounds.indexOf(value); | ||
} | ||
if (isFromKeyboardEvent) { | ||
// known problem: because setState is async, | ||
// so trigger focus will invoke handler's onEnd and another handler's onStart too early, | ||
// cause onBeforeChange and onAfterChange receive wrong value. | ||
// here use setState callback to hack,but not elegant | ||
this.props.onAfterChange(nextBounds); | ||
this.setState({}, function () { | ||
_this3.handlesRefs[nextHandle].focus(); | ||
}); | ||
this.onEnd(); | ||
} | ||
this.onChange({ | ||
recent: nextHandle, | ||
handle: nextHandle, | ||
bounds: nextBounds | ||
}); | ||
if (isFromKeyboardEvent) { | ||
// known problem: because setState is async, | ||
// so trigger focus will invoke handler's onEnd and another handler's onStart too early, | ||
// cause onBeforeChange and onAfterChange receive wrong value. | ||
// here use setState callback to hack,but not elegant | ||
this.props.onAfterChange(nextBounds); | ||
this.setState({}, function () { | ||
_this3.handlesRefs[nextHandle].focus(); | ||
}); | ||
this.onEnd(); | ||
} | ||
}, { | ||
key: "pushSurroundingHandles", | ||
value: function pushSurroundingHandles(bounds, handle) { | ||
var value = bounds[handle]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var direction = 0; | ||
} | ||
}, { | ||
key: "pushSurroundingHandles", | ||
value: function pushSurroundingHandles(bounds, handle) { | ||
var value = bounds[handle]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var direction = 0; | ||
if (bounds[handle + 1] - value < threshold) { | ||
direction = +1; // push to right | ||
} | ||
if (bounds[handle + 1] - value < threshold) { | ||
direction = +1; // push to right | ||
} | ||
if (value - bounds[handle - 1] < threshold) { | ||
direction = -1; // push to left | ||
} | ||
if (value - bounds[handle - 1] < threshold) { | ||
direction = -1; // push to left | ||
} | ||
if (direction === 0) { | ||
return; | ||
} | ||
if (direction === 0) { | ||
return; | ||
} | ||
var nextHandle = handle + direction; | ||
var diffToNext = direction * (bounds[nextHandle] - value); | ||
var nextHandle = handle + direction; | ||
var diffToNext = direction * (bounds[nextHandle] - value); | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// revert to original value if pushing is impossible | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// revert to original value if pushing is impossible | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = bounds[nextHandle] - direction * threshold; | ||
} | ||
} | ||
}, { | ||
key: "pushHandle", | ||
value: function pushHandle(bounds, handle, direction, amount) { | ||
var originalValue = bounds[handle]; | ||
var currentValue = bounds[handle]; | ||
while (direction * (currentValue - originalValue) < amount) { | ||
if (!this.pushHandleOnePoint(bounds, handle, direction)) { | ||
// can't push handle enough to create the needed `amount` gap, so we | ||
// revert its position to the original value | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = bounds[nextHandle] - direction * threshold; | ||
bounds[handle] = originalValue; | ||
return false; | ||
} | ||
} | ||
}, { | ||
key: "pushHandle", | ||
value: function pushHandle(bounds, handle, direction, amount) { | ||
var originalValue = bounds[handle]; | ||
var currentValue = bounds[handle]; | ||
while (direction * (currentValue - originalValue) < amount) { | ||
if (!this.pushHandleOnePoint(bounds, handle, direction)) { | ||
// can't push handle enough to create the needed `amount` gap, so we | ||
// revert its position to the original value | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = originalValue; | ||
return false; | ||
} | ||
currentValue = bounds[handle]; | ||
} // the handle was pushed enough to create the needed `amount` gap | ||
currentValue = bounds[handle]; | ||
} // the handle was pushed enough to create the needed `amount` gap | ||
return true; | ||
} | ||
}, { | ||
key: "pushHandleOnePoint", | ||
value: function pushHandleOnePoint(bounds, handle, direction) { | ||
var points = this.getPoints(); | ||
var pointIndex = points.indexOf(bounds[handle]); | ||
var nextPointIndex = pointIndex + direction; | ||
return true; | ||
if (nextPointIndex >= points.length || nextPointIndex < 0) { | ||
// reached the minimum or maximum available point, can't push anymore | ||
return false; | ||
} | ||
}, { | ||
key: "pushHandleOnePoint", | ||
value: function pushHandleOnePoint(bounds, handle, direction) { | ||
var points = this.getPoints(); | ||
var pointIndex = points.indexOf(bounds[handle]); | ||
var nextPointIndex = pointIndex + direction; | ||
if (nextPointIndex >= points.length || nextPointIndex < 0) { | ||
// reached the minimum or maximum available point, can't push anymore | ||
return false; | ||
} | ||
var nextHandle = handle + direction; | ||
var nextValue = points[nextPointIndex]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var diffToNext = direction * (bounds[nextHandle] - nextValue); | ||
var nextHandle = handle + direction; | ||
var nextValue = points[nextPointIndex]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var diffToNext = direction * (bounds[nextHandle] - nextValue); | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// couldn't push next handle, so we won't push this one either | ||
return false; | ||
} // push the handle | ||
// eslint-disable-next-line no-param-reassign | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// couldn't push next handle, so we won't push this one either | ||
return false; | ||
} // push the handle | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = nextValue; | ||
return true; | ||
} | ||
}, { | ||
key: "trimAlignValue", | ||
value: function trimAlignValue(value) { | ||
var _this$state2 = this.state, | ||
handle = _this$state2.handle, | ||
bounds = _this$state2.bounds; | ||
return _trimAlignValue({ | ||
value: value, | ||
handle: handle, | ||
bounds: bounds, | ||
props: this.props | ||
}); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this4 = this; | ||
bounds[handle] = nextValue; | ||
return true; | ||
} | ||
}, { | ||
key: "trimAlignValue", | ||
value: function trimAlignValue(value) { | ||
var _this$state2 = this.state, | ||
handle = _this$state2.handle, | ||
bounds = _this$state2.bounds; | ||
return _trimAlignValue({ | ||
value: value, | ||
handle: handle, | ||
bounds: bounds, | ||
props: this.props | ||
}); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this4 = this; | ||
var _this$state3 = this.state, | ||
handle = _this$state3.handle, | ||
bounds = _this$state3.bounds; | ||
var _this$props4 = this.props, | ||
prefixCls = _this$props4.prefixCls, | ||
vertical = _this$props4.vertical, | ||
included = _this$props4.included, | ||
disabled = _this$props4.disabled, | ||
min = _this$props4.min, | ||
max = _this$props4.max, | ||
reverse = _this$props4.reverse, | ||
handleGenerator = _this$props4.handle, | ||
trackStyle = _this$props4.trackStyle, | ||
handleStyle = _this$props4.handleStyle, | ||
tabIndex = _this$props4.tabIndex, | ||
ariaLabelGroupForHandles = _this$props4.ariaLabelGroupForHandles, | ||
ariaLabelledByGroupForHandles = _this$props4.ariaLabelledByGroupForHandles, | ||
ariaValueTextFormatterGroupForHandles = _this$props4.ariaValueTextFormatterGroupForHandles; | ||
var offsets = bounds.map(function (v) { | ||
return _this4.calcOffset(v); | ||
}); | ||
var handleClassName = "".concat(prefixCls, "-handle"); | ||
var handles = bounds.map(function (v, i) { | ||
var _classNames; | ||
var _this$state3 = this.state, | ||
handle = _this$state3.handle, | ||
bounds = _this$state3.bounds; | ||
var _this$props4 = this.props, | ||
prefixCls = _this$props4.prefixCls, | ||
vertical = _this$props4.vertical, | ||
included = _this$props4.included, | ||
disabled = _this$props4.disabled, | ||
min = _this$props4.min, | ||
max = _this$props4.max, | ||
reverse = _this$props4.reverse, | ||
handleGenerator = _this$props4.handle, | ||
trackStyle = _this$props4.trackStyle, | ||
handleStyle = _this$props4.handleStyle, | ||
tabIndex = _this$props4.tabIndex, | ||
ariaLabelGroupForHandles = _this$props4.ariaLabelGroupForHandles, | ||
ariaLabelledByGroupForHandles = _this$props4.ariaLabelledByGroupForHandles, | ||
ariaValueTextFormatterGroupForHandles = _this$props4.ariaValueTextFormatterGroupForHandles; | ||
var offsets = bounds.map(function (v) { | ||
return _this4.calcOffset(v); | ||
}); | ||
var handleClassName = "".concat(prefixCls, "-handle"); | ||
var handles = bounds.map(function (v, i) { | ||
var _classNames; | ||
var mergedTabIndex = tabIndex[i] || 0; | ||
var mergedTabIndex = tabIndex[i] || 0; | ||
if (disabled || tabIndex[i] === null) { | ||
mergedTabIndex = null; | ||
} | ||
if (disabled || tabIndex[i] === null) { | ||
mergedTabIndex = null; | ||
} | ||
var dragging = handle === i; | ||
return handleGenerator({ | ||
className: classNames((_classNames = {}, _defineProperty(_classNames, handleClassName, true), _defineProperty(_classNames, "".concat(handleClassName, "-").concat(i + 1), true), _defineProperty(_classNames, "".concat(handleClassName, "-dragging"), dragging), _classNames)), | ||
prefixCls: prefixCls, | ||
vertical: vertical, | ||
dragging: dragging, | ||
offset: offsets[i], | ||
value: v, | ||
index: i, | ||
tabIndex: mergedTabIndex, | ||
min: min, | ||
max: max, | ||
reverse: reverse, | ||
disabled: disabled, | ||
style: handleStyle[i], | ||
ref: function ref(h) { | ||
return _this4.saveHandle(i, h); | ||
}, | ||
ariaLabel: ariaLabelGroupForHandles[i], | ||
ariaLabelledBy: ariaLabelledByGroupForHandles[i], | ||
ariaValueTextFormatter: ariaValueTextFormatterGroupForHandles[i] | ||
}); | ||
}); | ||
var tracks = bounds.slice(0, -1).map(function (_, index) { | ||
var _classNames2; | ||
var dragging = handle === i; | ||
return handleGenerator({ | ||
className: classNames((_classNames = {}, _defineProperty(_classNames, handleClassName, true), _defineProperty(_classNames, "".concat(handleClassName, "-").concat(i + 1), true), _defineProperty(_classNames, "".concat(handleClassName, "-dragging"), dragging), _classNames)), | ||
prefixCls: prefixCls, | ||
vertical: vertical, | ||
dragging: dragging, | ||
offset: offsets[i], | ||
var i = index + 1; | ||
var trackClassName = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-track"), true), _defineProperty(_classNames2, "".concat(prefixCls, "-track-").concat(i), true), _classNames2)); | ||
return React.createElement(Track, { | ||
className: trackClassName, | ||
vertical: vertical, | ||
reverse: reverse, | ||
included: included, | ||
offset: offsets[i - 1], | ||
length: offsets[i] - offsets[i - 1], | ||
style: trackStyle[index], | ||
key: i | ||
}); | ||
}); | ||
return { | ||
tracks: tracks, | ||
handles: handles | ||
}; | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(props, state) { | ||
if ('value' in props || 'min' in props || 'max' in props) { | ||
var value = props.value || state.bounds; | ||
var nextBounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
index: i, | ||
tabIndex: mergedTabIndex, | ||
min: min, | ||
max: max, | ||
reverse: reverse, | ||
disabled: disabled, | ||
style: handleStyle[i], | ||
ref: function ref(h) { | ||
return _this4.saveHandle(i, h); | ||
}, | ||
ariaLabel: ariaLabelGroupForHandles[i], | ||
ariaLabelledBy: ariaLabelledByGroupForHandles[i], | ||
ariaValueTextFormatter: ariaValueTextFormatterGroupForHandles[i] | ||
handle: i, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
}); | ||
var tracks = bounds.slice(0, -1).map(function (_, index) { | ||
var _classNames2; | ||
var i = index + 1; | ||
var trackClassName = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-track"), true), _defineProperty(_classNames2, "".concat(prefixCls, "-track-").concat(i), true), _classNames2)); | ||
return React.createElement(Track, { | ||
className: trackClassName, | ||
vertical: vertical, | ||
reverse: reverse, | ||
included: included, | ||
offset: offsets[i - 1], | ||
length: offsets[i] - offsets[i - 1], | ||
style: trackStyle[index], | ||
key: i | ||
}); | ||
}); | ||
return { | ||
tracks: tracks, | ||
handles: handles | ||
}; | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(props, state) { | ||
if ('value' in props || 'min' in props || 'max' in props) { | ||
var value = props.value || state.bounds; | ||
var nextBounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
handle: i, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
}); | ||
if (nextBounds.length === state.bounds.length && nextBounds.every(function (v, i) { | ||
return v === state.bounds[i]; | ||
})) { | ||
return null; | ||
} | ||
return _objectSpread(_objectSpread({}, state), {}, { | ||
bounds: nextBounds | ||
}); | ||
if (nextBounds.length === state.bounds.length && nextBounds.every(function (v, i) { | ||
return v === state.bounds[i]; | ||
})) { | ||
return null; | ||
} | ||
return null; | ||
return _objectSpread(_objectSpread({}, state), {}, { | ||
bounds: nextBounds | ||
}); | ||
} | ||
}]); | ||
return Range; | ||
}(React.Component); | ||
/* eslint-enable */ | ||
return null; | ||
} | ||
}]); | ||
Range.displayName = 'Range'; | ||
Range.defaultProps = { | ||
count: 1, | ||
allowCross: true, | ||
pushable: false, | ||
tabIndex: [], | ||
ariaLabelGroupForHandles: [], | ||
ariaLabelledByGroupForHandles: [], | ||
ariaValueTextFormatterGroupForHandles: [] | ||
}; | ||
return Range; | ||
}(); | ||
}(React.Component); | ||
/* eslint-enable */ | ||
Range.displayName = 'Range'; | ||
Range.defaultProps = { | ||
count: 1, | ||
allowCross: true, | ||
pushable: false, | ||
tabIndex: [], | ||
ariaLabelGroupForHandles: [], | ||
ariaLabelledByGroupForHandles: [], | ||
ariaValueTextFormatterGroupForHandles: [] | ||
}; | ||
export default createSlider(Range); |
@@ -33,3 +33,3 @@ import React from 'react'; | ||
handleMouseUp: () => void; | ||
handleMouseDown: () => void; | ||
handleMouseDown: (e: any) => void; | ||
handleBlur: () => void; | ||
@@ -36,0 +36,0 @@ handleKeyDown: () => void; |
@@ -62,4 +62,7 @@ "use strict"; | ||
_this.handleMouseDown = function () { | ||
// fix https://github.com/ant-design/ant-design/issues/15324 | ||
_this.handleMouseDown = function (e) { | ||
// avoid selecting text during drag | ||
// https://github.com/ant-design/ant-design/issues/25010 | ||
e.preventDefault(); // fix https://github.com/ant-design/ant-design/issues/15324 | ||
_this.focus(); | ||
@@ -66,0 +69,0 @@ }; |
909
lib/Range.js
@@ -70,541 +70,536 @@ "use strict"; | ||
var Range = | ||
/** @class */ | ||
function () { | ||
var Range = /*#__PURE__*/function (_React$Component) { | ||
(0, _inherits2.default)(Range, _React$Component); | ||
var Range = /*#__PURE__*/function (_React$Component) { | ||
(0, _inherits2.default)(Range, _React$Component); | ||
var _super = _createSuper(Range); | ||
var _super = _createSuper(Range); | ||
function Range(props) { | ||
var _this; | ||
function Range(props) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, Range); | ||
_this = _super.call(this, props); | ||
(0, _classCallCheck2.default)(this, Range); | ||
_this = _super.call(this, props); | ||
_this.onEnd = function (force) { | ||
var handle = _this.state.handle; | ||
_this.onEnd = function (force) { | ||
var handle = _this.state.handle; | ||
_this.removeDocumentEvents(); | ||
_this.removeDocumentEvents(); | ||
if (handle !== null || force) { | ||
_this.props.onAfterChange(_this.getValue()); | ||
} | ||
if (handle !== null || force) { | ||
_this.props.onAfterChange(_this.getValue()); | ||
} | ||
_this.setState({ | ||
handle: null | ||
}); | ||
}; | ||
_this.setState({ | ||
handle: null | ||
}); | ||
}; | ||
var count = props.count, | ||
min = props.min, | ||
max = props.max; | ||
var initialValue = Array.apply(void 0, (0, _toConsumableArray2.default)(Array(count + 1))).map(function () { | ||
return min; | ||
var count = props.count, | ||
min = props.min, | ||
max = props.max; | ||
var initialValue = Array.apply(void 0, (0, _toConsumableArray2.default)(Array(count + 1))).map(function () { | ||
return min; | ||
}); | ||
var defaultValue = 'defaultValue' in props ? props.defaultValue : initialValue; | ||
var value = props.value !== undefined ? props.value : defaultValue; | ||
var bounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
handle: i, | ||
props: props | ||
}); | ||
var defaultValue = 'defaultValue' in props ? props.defaultValue : initialValue; | ||
var value = props.value !== undefined ? props.value : defaultValue; | ||
var bounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
handle: i, | ||
props: props | ||
}); | ||
}); | ||
var recent = bounds[0] === max ? 0 : bounds.length - 1; | ||
_this.state = { | ||
handle: null, | ||
recent: recent, | ||
bounds: bounds | ||
}; | ||
return _this; | ||
} | ||
/** | ||
* [Legacy] Used for inherit other component. | ||
* It's a bad code style which should be refactor. | ||
*/ | ||
}); | ||
var recent = bounds[0] === max ? 0 : bounds.length - 1; | ||
_this.state = { | ||
handle: null, | ||
recent: recent, | ||
bounds: bounds | ||
}; | ||
return _this; | ||
} | ||
/** | ||
* [Legacy] Used for inherit other component. | ||
* It's a bad code style which should be refactor. | ||
*/ | ||
/* eslint-disable @typescript-eslint/no-unused-vars, class-methods-use-this */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars, class-methods-use-this */ | ||
(0, _createClass2.default)(Range, [{ | ||
key: "calcValueByPos", | ||
value: function calcValueByPos(value) { | ||
return 0; | ||
(0, _createClass2.default)(Range, [{ | ||
key: "calcValueByPos", | ||
value: function calcValueByPos(value) { | ||
return 0; | ||
} | ||
}, { | ||
key: "calcOffset", | ||
value: function calcOffset(value) { | ||
return 0; | ||
} | ||
}, { | ||
key: "saveHandle", | ||
value: function saveHandle(index, h) {} | ||
}, { | ||
key: "removeDocumentEvents", | ||
value: function removeDocumentEvents() {} | ||
}, { | ||
key: "componentDidUpdate", | ||
value: function componentDidUpdate(prevProps, prevState) { | ||
var _this2 = this; | ||
if (!('value' in this.props || 'min' in this.props || 'max' in this.props)) { | ||
return; | ||
} | ||
}, { | ||
key: "calcOffset", | ||
value: function calcOffset(value) { | ||
return 0; | ||
if (this.props.min === prevProps.min && this.props.max === prevProps.max && (0, _shallowequal.default)(this.props.value, prevProps.value)) { | ||
return; | ||
} | ||
}, { | ||
key: "saveHandle", | ||
value: function saveHandle(index, h) {} | ||
}, { | ||
key: "removeDocumentEvents", | ||
value: function removeDocumentEvents() {} | ||
}, { | ||
key: "componentDidUpdate", | ||
value: function componentDidUpdate(prevProps, prevState) { | ||
var _this2 = this; | ||
if (!('value' in this.props || 'min' in this.props || 'max' in this.props)) { | ||
return; | ||
} | ||
var _this$props = this.props, | ||
onChange = _this$props.onChange, | ||
value = _this$props.value; | ||
var currentValue = value || prevState.bounds; | ||
if (this.props.min === prevProps.min && this.props.max === prevProps.max && (0, _shallowequal.default)(this.props.value, prevProps.value)) { | ||
return; | ||
} | ||
if (currentValue.some(function (v) { | ||
return utils.isValueOutOfRange(v, _this2.props); | ||
})) { | ||
var newValues = currentValue.map(function (v) { | ||
return utils.ensureValueInRange(v, _this2.props); | ||
}); | ||
onChange(newValues); | ||
} | ||
} | ||
}, { | ||
key: "onChange", | ||
value: function onChange(state) { | ||
var props = this.props; | ||
var isNotControlled = !('value' in props); | ||
var _this$props = this.props, | ||
onChange = _this$props.onChange, | ||
value = _this$props.value; | ||
var currentValue = value || prevState.bounds; | ||
if (isNotControlled) { | ||
this.setState(state); | ||
} else { | ||
var controlledState = {}; | ||
['handle', 'recent'].forEach(function (item) { | ||
if (state[item] !== undefined) { | ||
controlledState[item] = state[item]; | ||
} | ||
}); | ||
if (currentValue.some(function (v) { | ||
return utils.isValueOutOfRange(v, _this2.props); | ||
})) { | ||
var newValues = currentValue.map(function (v) { | ||
return utils.ensureValueInRange(v, _this2.props); | ||
}); | ||
onChange(newValues); | ||
if (Object.keys(controlledState).length) { | ||
this.setState(controlledState); | ||
} | ||
} | ||
}, { | ||
key: "onChange", | ||
value: function onChange(state) { | ||
var props = this.props; | ||
var isNotControlled = !('value' in props); | ||
if (isNotControlled) { | ||
this.setState(state); | ||
} else { | ||
var controlledState = {}; | ||
['handle', 'recent'].forEach(function (item) { | ||
if (state[item] !== undefined) { | ||
controlledState[item] = state[item]; | ||
} | ||
}); | ||
var data = _objectSpread(_objectSpread({}, this.state), state); | ||
if (Object.keys(controlledState).length) { | ||
this.setState(controlledState); | ||
} | ||
} | ||
var changedValue = data.bounds; | ||
props.onChange(changedValue); | ||
} | ||
}, { | ||
key: "onStart", | ||
value: function onStart(position) { | ||
var props = this.props, | ||
state = this.state; | ||
var bounds = this.getValue(); | ||
props.onBeforeChange(bounds); | ||
var value = this.calcValueByPos(position); | ||
this.startValue = value; | ||
this.startPosition = position; | ||
var closestBound = this.getClosestBound(value); | ||
this.prevMovedHandleIndex = this.getBoundNeedMoving(value, closestBound); | ||
this.setState({ | ||
handle: this.prevMovedHandleIndex, | ||
recent: this.prevMovedHandleIndex | ||
}); | ||
var prevValue = bounds[this.prevMovedHandleIndex]; | ||
if (value === prevValue) return; | ||
var nextBounds = (0, _toConsumableArray2.default)(state.bounds); | ||
nextBounds[this.prevMovedHandleIndex] = value; | ||
this.onChange({ | ||
bounds: nextBounds | ||
}); | ||
} | ||
}, { | ||
key: "onMove", | ||
value: function onMove(e, position) { | ||
utils.pauseEvent(e); | ||
var state = this.state; | ||
var value = this.calcValueByPos(position); | ||
var oldValue = state.bounds[state.handle]; | ||
if (value === oldValue) return; | ||
this.moveTo(value); | ||
} | ||
}, { | ||
key: "onKeyboard", | ||
value: function onKeyboard(e) { | ||
var _this$props2 = this.props, | ||
reverse = _this$props2.reverse, | ||
vertical = _this$props2.vertical; | ||
var valueMutator = utils.getKeyboardValueMutator(e, vertical, reverse); | ||
var data = _objectSpread(_objectSpread({}, this.state), state); | ||
if (valueMutator) { | ||
utils.pauseEvent(e); | ||
var state = this.state, | ||
props = this.props; | ||
var bounds = state.bounds, | ||
handle = state.handle; | ||
var oldValue = bounds[handle === null ? state.recent : handle]; | ||
var mutatedValue = valueMutator(oldValue, props); | ||
var changedValue = data.bounds; | ||
props.onChange(changedValue); | ||
} | ||
}, { | ||
key: "onStart", | ||
value: function onStart(position) { | ||
var props = this.props, | ||
state = this.state; | ||
var bounds = this.getValue(); | ||
props.onBeforeChange(bounds); | ||
var value = this.calcValueByPos(position); | ||
this.startValue = value; | ||
this.startPosition = position; | ||
var closestBound = this.getClosestBound(value); | ||
this.prevMovedHandleIndex = this.getBoundNeedMoving(value, closestBound); | ||
this.setState({ | ||
handle: this.prevMovedHandleIndex, | ||
recent: this.prevMovedHandleIndex | ||
var value = _trimAlignValue({ | ||
value: mutatedValue, | ||
handle: handle, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
var prevValue = bounds[this.prevMovedHandleIndex]; | ||
if (value === prevValue) return; | ||
var nextBounds = (0, _toConsumableArray2.default)(state.bounds); | ||
nextBounds[this.prevMovedHandleIndex] = value; | ||
this.onChange({ | ||
bounds: nextBounds | ||
}); | ||
} | ||
}, { | ||
key: "onMove", | ||
value: function onMove(e, position) { | ||
utils.pauseEvent(e); | ||
var state = this.state; | ||
var value = this.calcValueByPos(position); | ||
var oldValue = state.bounds[state.handle]; | ||
if (value === oldValue) return; | ||
this.moveTo(value); | ||
var isFromKeyboardEvent = true; | ||
this.moveTo(value, isFromKeyboardEvent); | ||
} | ||
}, { | ||
key: "onKeyboard", | ||
value: function onKeyboard(e) { | ||
var _this$props2 = this.props, | ||
reverse = _this$props2.reverse, | ||
vertical = _this$props2.vertical; | ||
var valueMutator = utils.getKeyboardValueMutator(e, vertical, reverse); | ||
} | ||
}, { | ||
key: "getValue", | ||
value: function getValue() { | ||
return this.state.bounds; | ||
} | ||
}, { | ||
key: "getClosestBound", | ||
value: function getClosestBound(value) { | ||
var bounds = this.state.bounds; | ||
var closestBound = 0; | ||
if (valueMutator) { | ||
utils.pauseEvent(e); | ||
var state = this.state, | ||
props = this.props; | ||
var bounds = state.bounds, | ||
handle = state.handle; | ||
var oldValue = bounds[handle === null ? state.recent : handle]; | ||
var mutatedValue = valueMutator(oldValue, props); | ||
var value = _trimAlignValue({ | ||
value: mutatedValue, | ||
handle: handle, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
if (value === oldValue) return; | ||
var isFromKeyboardEvent = true; | ||
this.moveTo(value, isFromKeyboardEvent); | ||
for (var i = 1; i < bounds.length - 1; i += 1) { | ||
if (value >= bounds[i]) { | ||
closestBound = i; | ||
} | ||
} | ||
}, { | ||
key: "getValue", | ||
value: function getValue() { | ||
return this.state.bounds; | ||
if (Math.abs(bounds[closestBound + 1] - value) < Math.abs(bounds[closestBound] - value)) { | ||
closestBound += 1; | ||
} | ||
}, { | ||
key: "getClosestBound", | ||
value: function getClosestBound(value) { | ||
var bounds = this.state.bounds; | ||
var closestBound = 0; | ||
for (var i = 1; i < bounds.length - 1; i += 1) { | ||
if (value >= bounds[i]) { | ||
closestBound = i; | ||
} | ||
} | ||
return closestBound; | ||
} | ||
}, { | ||
key: "getBoundNeedMoving", | ||
value: function getBoundNeedMoving(value, closestBound) { | ||
var _this$state = this.state, | ||
bounds = _this$state.bounds, | ||
recent = _this$state.recent; | ||
var boundNeedMoving = closestBound; | ||
var isAtTheSamePoint = bounds[closestBound + 1] === bounds[closestBound]; | ||
if (Math.abs(bounds[closestBound + 1] - value) < Math.abs(bounds[closestBound] - value)) { | ||
closestBound += 1; | ||
} | ||
if (isAtTheSamePoint && bounds[recent] === bounds[closestBound]) { | ||
boundNeedMoving = recent; | ||
} | ||
return closestBound; | ||
if (isAtTheSamePoint && value !== bounds[closestBound + 1]) { | ||
boundNeedMoving = value < bounds[closestBound + 1] ? closestBound : closestBound + 1; | ||
} | ||
}, { | ||
key: "getBoundNeedMoving", | ||
value: function getBoundNeedMoving(value, closestBound) { | ||
var _this$state = this.state, | ||
bounds = _this$state.bounds, | ||
recent = _this$state.recent; | ||
var boundNeedMoving = closestBound; | ||
var isAtTheSamePoint = bounds[closestBound + 1] === bounds[closestBound]; | ||
if (isAtTheSamePoint && bounds[recent] === bounds[closestBound]) { | ||
boundNeedMoving = recent; | ||
} | ||
return boundNeedMoving; | ||
} | ||
}, { | ||
key: "getLowerBound", | ||
value: function getLowerBound() { | ||
return this.state.bounds[0]; | ||
} | ||
}, { | ||
key: "getUpperBound", | ||
value: function getUpperBound() { | ||
var bounds = this.state.bounds; | ||
return bounds[bounds.length - 1]; | ||
} | ||
/** | ||
* Returns an array of possible slider points, taking into account both | ||
* `marks` and `step`. The result is cached. | ||
*/ | ||
if (isAtTheSamePoint && value !== bounds[closestBound + 1]) { | ||
boundNeedMoving = value < bounds[closestBound + 1] ? closestBound : closestBound + 1; | ||
} | ||
}, { | ||
key: "getPoints", | ||
value: function getPoints() { | ||
var _this$props3 = this.props, | ||
marks = _this$props3.marks, | ||
step = _this$props3.step, | ||
min = _this$props3.min, | ||
max = _this$props3.max; | ||
var cache = this.internalPointsCache; | ||
return boundNeedMoving; | ||
} | ||
}, { | ||
key: "getLowerBound", | ||
value: function getLowerBound() { | ||
return this.state.bounds[0]; | ||
} | ||
}, { | ||
key: "getUpperBound", | ||
value: function getUpperBound() { | ||
var bounds = this.state.bounds; | ||
return bounds[bounds.length - 1]; | ||
} | ||
/** | ||
* Returns an array of possible slider points, taking into account both | ||
* `marks` and `step`. The result is cached. | ||
*/ | ||
if (!cache || cache.marks !== marks || cache.step !== step) { | ||
var pointsObject = _objectSpread({}, marks); | ||
}, { | ||
key: "getPoints", | ||
value: function getPoints() { | ||
var _this$props3 = this.props, | ||
marks = _this$props3.marks, | ||
step = _this$props3.step, | ||
min = _this$props3.min, | ||
max = _this$props3.max; | ||
var cache = this.internalPointsCache; | ||
if (!cache || cache.marks !== marks || cache.step !== step) { | ||
var pointsObject = _objectSpread({}, marks); | ||
if (step !== null) { | ||
for (var point = min; point <= max; point += step) { | ||
pointsObject[point] = point; | ||
} | ||
if (step !== null) { | ||
for (var point = min; point <= max; point += step) { | ||
pointsObject[point] = point; | ||
} | ||
var points = Object.keys(pointsObject).map(parseFloat); | ||
points.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
this.internalPointsCache = { | ||
marks: marks, | ||
step: step, | ||
points: points | ||
}; | ||
} | ||
return this.internalPointsCache.points; | ||
var points = Object.keys(pointsObject).map(parseFloat); | ||
points.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
this.internalPointsCache = { | ||
marks: marks, | ||
step: step, | ||
points: points | ||
}; | ||
} | ||
}, { | ||
key: "moveTo", | ||
value: function moveTo(value, isFromKeyboardEvent) { | ||
var _this3 = this; | ||
var state = this.state, | ||
props = this.props; | ||
var nextBounds = (0, _toConsumableArray2.default)(state.bounds); | ||
var handle = state.handle === null ? state.recent : state.handle; | ||
nextBounds[handle] = value; | ||
var nextHandle = handle; | ||
return this.internalPointsCache.points; | ||
} | ||
}, { | ||
key: "moveTo", | ||
value: function moveTo(value, isFromKeyboardEvent) { | ||
var _this3 = this; | ||
if (props.pushable !== false) { | ||
this.pushSurroundingHandles(nextBounds, nextHandle); | ||
} else if (props.allowCross) { | ||
nextBounds.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
nextHandle = nextBounds.indexOf(value); | ||
} | ||
var state = this.state, | ||
props = this.props; | ||
var nextBounds = (0, _toConsumableArray2.default)(state.bounds); | ||
var handle = state.handle === null ? state.recent : state.handle; | ||
nextBounds[handle] = value; | ||
var nextHandle = handle; | ||
this.onChange({ | ||
recent: nextHandle, | ||
handle: nextHandle, | ||
bounds: nextBounds | ||
if (props.pushable !== false) { | ||
this.pushSurroundingHandles(nextBounds, nextHandle); | ||
} else if (props.allowCross) { | ||
nextBounds.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
nextHandle = nextBounds.indexOf(value); | ||
} | ||
if (isFromKeyboardEvent) { | ||
// known problem: because setState is async, | ||
// so trigger focus will invoke handler's onEnd and another handler's onStart too early, | ||
// cause onBeforeChange and onAfterChange receive wrong value. | ||
// here use setState callback to hack,but not elegant | ||
this.props.onAfterChange(nextBounds); | ||
this.setState({}, function () { | ||
_this3.handlesRefs[nextHandle].focus(); | ||
}); | ||
this.onEnd(); | ||
} | ||
this.onChange({ | ||
recent: nextHandle, | ||
handle: nextHandle, | ||
bounds: nextBounds | ||
}); | ||
if (isFromKeyboardEvent) { | ||
// known problem: because setState is async, | ||
// so trigger focus will invoke handler's onEnd and another handler's onStart too early, | ||
// cause onBeforeChange and onAfterChange receive wrong value. | ||
// here use setState callback to hack,but not elegant | ||
this.props.onAfterChange(nextBounds); | ||
this.setState({}, function () { | ||
_this3.handlesRefs[nextHandle].focus(); | ||
}); | ||
this.onEnd(); | ||
} | ||
}, { | ||
key: "pushSurroundingHandles", | ||
value: function pushSurroundingHandles(bounds, handle) { | ||
var value = bounds[handle]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var direction = 0; | ||
} | ||
}, { | ||
key: "pushSurroundingHandles", | ||
value: function pushSurroundingHandles(bounds, handle) { | ||
var value = bounds[handle]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var direction = 0; | ||
if (bounds[handle + 1] - value < threshold) { | ||
direction = +1; // push to right | ||
} | ||
if (bounds[handle + 1] - value < threshold) { | ||
direction = +1; // push to right | ||
} | ||
if (value - bounds[handle - 1] < threshold) { | ||
direction = -1; // push to left | ||
} | ||
if (value - bounds[handle - 1] < threshold) { | ||
direction = -1; // push to left | ||
} | ||
if (direction === 0) { | ||
return; | ||
} | ||
if (direction === 0) { | ||
return; | ||
} | ||
var nextHandle = handle + direction; | ||
var diffToNext = direction * (bounds[nextHandle] - value); | ||
var nextHandle = handle + direction; | ||
var diffToNext = direction * (bounds[nextHandle] - value); | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// revert to original value if pushing is impossible | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// revert to original value if pushing is impossible | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = bounds[nextHandle] - direction * threshold; | ||
} | ||
} | ||
}, { | ||
key: "pushHandle", | ||
value: function pushHandle(bounds, handle, direction, amount) { | ||
var originalValue = bounds[handle]; | ||
var currentValue = bounds[handle]; | ||
while (direction * (currentValue - originalValue) < amount) { | ||
if (!this.pushHandleOnePoint(bounds, handle, direction)) { | ||
// can't push handle enough to create the needed `amount` gap, so we | ||
// revert its position to the original value | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = bounds[nextHandle] - direction * threshold; | ||
bounds[handle] = originalValue; | ||
return false; | ||
} | ||
} | ||
}, { | ||
key: "pushHandle", | ||
value: function pushHandle(bounds, handle, direction, amount) { | ||
var originalValue = bounds[handle]; | ||
var currentValue = bounds[handle]; | ||
while (direction * (currentValue - originalValue) < amount) { | ||
if (!this.pushHandleOnePoint(bounds, handle, direction)) { | ||
// can't push handle enough to create the needed `amount` gap, so we | ||
// revert its position to the original value | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = originalValue; | ||
return false; | ||
} | ||
currentValue = bounds[handle]; | ||
} // the handle was pushed enough to create the needed `amount` gap | ||
currentValue = bounds[handle]; | ||
} // the handle was pushed enough to create the needed `amount` gap | ||
return true; | ||
} | ||
}, { | ||
key: "pushHandleOnePoint", | ||
value: function pushHandleOnePoint(bounds, handle, direction) { | ||
var points = this.getPoints(); | ||
var pointIndex = points.indexOf(bounds[handle]); | ||
var nextPointIndex = pointIndex + direction; | ||
return true; | ||
if (nextPointIndex >= points.length || nextPointIndex < 0) { | ||
// reached the minimum or maximum available point, can't push anymore | ||
return false; | ||
} | ||
}, { | ||
key: "pushHandleOnePoint", | ||
value: function pushHandleOnePoint(bounds, handle, direction) { | ||
var points = this.getPoints(); | ||
var pointIndex = points.indexOf(bounds[handle]); | ||
var nextPointIndex = pointIndex + direction; | ||
if (nextPointIndex >= points.length || nextPointIndex < 0) { | ||
// reached the minimum or maximum available point, can't push anymore | ||
return false; | ||
} | ||
var nextHandle = handle + direction; | ||
var nextValue = points[nextPointIndex]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var diffToNext = direction * (bounds[nextHandle] - nextValue); | ||
var nextHandle = handle + direction; | ||
var nextValue = points[nextPointIndex]; | ||
var pushable = this.props.pushable; | ||
var threshold = Number(pushable); | ||
var diffToNext = direction * (bounds[nextHandle] - nextValue); | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// couldn't push next handle, so we won't push this one either | ||
return false; | ||
} // push the handle | ||
// eslint-disable-next-line no-param-reassign | ||
if (!this.pushHandle(bounds, nextHandle, direction, threshold - diffToNext)) { | ||
// couldn't push next handle, so we won't push this one either | ||
return false; | ||
} // push the handle | ||
// eslint-disable-next-line no-param-reassign | ||
bounds[handle] = nextValue; | ||
return true; | ||
} | ||
}, { | ||
key: "trimAlignValue", | ||
value: function trimAlignValue(value) { | ||
var _this$state2 = this.state, | ||
handle = _this$state2.handle, | ||
bounds = _this$state2.bounds; | ||
return _trimAlignValue({ | ||
value: value, | ||
handle: handle, | ||
bounds: bounds, | ||
props: this.props | ||
}); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this4 = this; | ||
bounds[handle] = nextValue; | ||
return true; | ||
} | ||
}, { | ||
key: "trimAlignValue", | ||
value: function trimAlignValue(value) { | ||
var _this$state2 = this.state, | ||
handle = _this$state2.handle, | ||
bounds = _this$state2.bounds; | ||
return _trimAlignValue({ | ||
value: value, | ||
handle: handle, | ||
bounds: bounds, | ||
props: this.props | ||
}); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this4 = this; | ||
var _this$state3 = this.state, | ||
handle = _this$state3.handle, | ||
bounds = _this$state3.bounds; | ||
var _this$props4 = this.props, | ||
prefixCls = _this$props4.prefixCls, | ||
vertical = _this$props4.vertical, | ||
included = _this$props4.included, | ||
disabled = _this$props4.disabled, | ||
min = _this$props4.min, | ||
max = _this$props4.max, | ||
reverse = _this$props4.reverse, | ||
handleGenerator = _this$props4.handle, | ||
trackStyle = _this$props4.trackStyle, | ||
handleStyle = _this$props4.handleStyle, | ||
tabIndex = _this$props4.tabIndex, | ||
ariaLabelGroupForHandles = _this$props4.ariaLabelGroupForHandles, | ||
ariaLabelledByGroupForHandles = _this$props4.ariaLabelledByGroupForHandles, | ||
ariaValueTextFormatterGroupForHandles = _this$props4.ariaValueTextFormatterGroupForHandles; | ||
var offsets = bounds.map(function (v) { | ||
return _this4.calcOffset(v); | ||
}); | ||
var handleClassName = "".concat(prefixCls, "-handle"); | ||
var handles = bounds.map(function (v, i) { | ||
var _classNames; | ||
var _this$state3 = this.state, | ||
handle = _this$state3.handle, | ||
bounds = _this$state3.bounds; | ||
var _this$props4 = this.props, | ||
prefixCls = _this$props4.prefixCls, | ||
vertical = _this$props4.vertical, | ||
included = _this$props4.included, | ||
disabled = _this$props4.disabled, | ||
min = _this$props4.min, | ||
max = _this$props4.max, | ||
reverse = _this$props4.reverse, | ||
handleGenerator = _this$props4.handle, | ||
trackStyle = _this$props4.trackStyle, | ||
handleStyle = _this$props4.handleStyle, | ||
tabIndex = _this$props4.tabIndex, | ||
ariaLabelGroupForHandles = _this$props4.ariaLabelGroupForHandles, | ||
ariaLabelledByGroupForHandles = _this$props4.ariaLabelledByGroupForHandles, | ||
ariaValueTextFormatterGroupForHandles = _this$props4.ariaValueTextFormatterGroupForHandles; | ||
var offsets = bounds.map(function (v) { | ||
return _this4.calcOffset(v); | ||
}); | ||
var handleClassName = "".concat(prefixCls, "-handle"); | ||
var handles = bounds.map(function (v, i) { | ||
var _classNames; | ||
var mergedTabIndex = tabIndex[i] || 0; | ||
var mergedTabIndex = tabIndex[i] || 0; | ||
if (disabled || tabIndex[i] === null) { | ||
mergedTabIndex = null; | ||
} | ||
if (disabled || tabIndex[i] === null) { | ||
mergedTabIndex = null; | ||
} | ||
var dragging = handle === i; | ||
return handleGenerator({ | ||
className: (0, _classnames.default)((_classNames = {}, (0, _defineProperty2.default)(_classNames, handleClassName, true), (0, _defineProperty2.default)(_classNames, "".concat(handleClassName, "-").concat(i + 1), true), (0, _defineProperty2.default)(_classNames, "".concat(handleClassName, "-dragging"), dragging), _classNames)), | ||
prefixCls: prefixCls, | ||
vertical: vertical, | ||
dragging: dragging, | ||
offset: offsets[i], | ||
value: v, | ||
index: i, | ||
tabIndex: mergedTabIndex, | ||
min: min, | ||
max: max, | ||
reverse: reverse, | ||
disabled: disabled, | ||
style: handleStyle[i], | ||
ref: function ref(h) { | ||
return _this4.saveHandle(i, h); | ||
}, | ||
ariaLabel: ariaLabelGroupForHandles[i], | ||
ariaLabelledBy: ariaLabelledByGroupForHandles[i], | ||
ariaValueTextFormatter: ariaValueTextFormatterGroupForHandles[i] | ||
}); | ||
}); | ||
var tracks = bounds.slice(0, -1).map(function (_, index) { | ||
var _classNames2; | ||
var dragging = handle === i; | ||
return handleGenerator({ | ||
className: (0, _classnames.default)((_classNames = {}, (0, _defineProperty2.default)(_classNames, handleClassName, true), (0, _defineProperty2.default)(_classNames, "".concat(handleClassName, "-").concat(i + 1), true), (0, _defineProperty2.default)(_classNames, "".concat(handleClassName, "-dragging"), dragging), _classNames)), | ||
prefixCls: prefixCls, | ||
vertical: vertical, | ||
dragging: dragging, | ||
offset: offsets[i], | ||
var i = index + 1; | ||
var trackClassName = (0, _classnames.default)((_classNames2 = {}, (0, _defineProperty2.default)(_classNames2, "".concat(prefixCls, "-track"), true), (0, _defineProperty2.default)(_classNames2, "".concat(prefixCls, "-track-").concat(i), true), _classNames2)); | ||
return _react.default.createElement(_Track.default, { | ||
className: trackClassName, | ||
vertical: vertical, | ||
reverse: reverse, | ||
included: included, | ||
offset: offsets[i - 1], | ||
length: offsets[i] - offsets[i - 1], | ||
style: trackStyle[index], | ||
key: i | ||
}); | ||
}); | ||
return { | ||
tracks: tracks, | ||
handles: handles | ||
}; | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(props, state) { | ||
if ('value' in props || 'min' in props || 'max' in props) { | ||
var value = props.value || state.bounds; | ||
var nextBounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
index: i, | ||
tabIndex: mergedTabIndex, | ||
min: min, | ||
max: max, | ||
reverse: reverse, | ||
disabled: disabled, | ||
style: handleStyle[i], | ||
ref: function ref(h) { | ||
return _this4.saveHandle(i, h); | ||
}, | ||
ariaLabel: ariaLabelGroupForHandles[i], | ||
ariaLabelledBy: ariaLabelledByGroupForHandles[i], | ||
ariaValueTextFormatter: ariaValueTextFormatterGroupForHandles[i] | ||
handle: i, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
}); | ||
var tracks = bounds.slice(0, -1).map(function (_, index) { | ||
var _classNames2; | ||
var i = index + 1; | ||
var trackClassName = (0, _classnames.default)((_classNames2 = {}, (0, _defineProperty2.default)(_classNames2, "".concat(prefixCls, "-track"), true), (0, _defineProperty2.default)(_classNames2, "".concat(prefixCls, "-track-").concat(i), true), _classNames2)); | ||
return _react.default.createElement(_Track.default, { | ||
className: trackClassName, | ||
vertical: vertical, | ||
reverse: reverse, | ||
included: included, | ||
offset: offsets[i - 1], | ||
length: offsets[i] - offsets[i - 1], | ||
style: trackStyle[index], | ||
key: i | ||
}); | ||
if (nextBounds.length === state.bounds.length && nextBounds.every(function (v, i) { | ||
return v === state.bounds[i]; | ||
})) { | ||
return null; | ||
} | ||
return _objectSpread(_objectSpread({}, state), {}, { | ||
bounds: nextBounds | ||
}); | ||
return { | ||
tracks: tracks, | ||
handles: handles | ||
}; | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(props, state) { | ||
if ('value' in props || 'min' in props || 'max' in props) { | ||
var value = props.value || state.bounds; | ||
var nextBounds = value.map(function (v, i) { | ||
return _trimAlignValue({ | ||
value: v, | ||
handle: i, | ||
bounds: state.bounds, | ||
props: props | ||
}); | ||
}); | ||
if (nextBounds.length === state.bounds.length && nextBounds.every(function (v, i) { | ||
return v === state.bounds[i]; | ||
})) { | ||
return null; | ||
} | ||
return null; | ||
} | ||
}]); | ||
return Range; | ||
}(_react.default.Component); | ||
/* eslint-enable */ | ||
return _objectSpread(_objectSpread({}, state), {}, { | ||
bounds: nextBounds | ||
}); | ||
} | ||
return null; | ||
} | ||
}]); | ||
return Range; | ||
}(_react.default.Component); | ||
/* eslint-enable */ | ||
Range.displayName = 'Range'; | ||
Range.defaultProps = { | ||
count: 1, | ||
allowCross: true, | ||
pushable: false, | ||
tabIndex: [], | ||
ariaLabelGroupForHandles: [], | ||
ariaLabelledByGroupForHandles: [], | ||
ariaValueTextFormatterGroupForHandles: [] | ||
}; | ||
Range.displayName = 'Range'; | ||
Range.defaultProps = { | ||
count: 1, | ||
allowCross: true, | ||
pushable: false, | ||
tabIndex: [], | ||
ariaLabelGroupForHandles: [], | ||
ariaLabelledByGroupForHandles: [], | ||
ariaValueTextFormatterGroupForHandles: [] | ||
}; | ||
return Range; | ||
}(); | ||
var _default = (0, _createSlider.default)(Range); | ||
exports.default = _default; |
{ | ||
"name": "rc-slider", | ||
"version": "9.3.0", | ||
"version": "9.3.1", | ||
"description": "Slider UI component for React", | ||
@@ -59,3 +59,3 @@ "engines": { | ||
"@types/classnames": "^2.2.9", | ||
"@types/jest": "^25.1.0", | ||
"@types/jest": "^26.0.0", | ||
"@types/react": "^16.9.2", | ||
@@ -62,0 +62,0 @@ "@types/react-dom": "^16.9.0", |
@@ -8,44 +8,27 @@ # rc-slider | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![david-dm deps][david-dm-image]][david-dm-url] | ||
[![david-dm dev deps][david-dm-dev-image]][david-dm-dev-url] | ||
[![node version][node-image]][node-url] | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![Dependencies][david-image]][david-url] | ||
[![DevDependencies][david-dev-image]][david-dev-url] | ||
[![npm download][download-image]][download-url] | ||
[![bundle size][bundlephobia-image]][bundlephobia-url] | ||
[npm-image]: http://img.shields.io/npm/v/rc-slider.svg?style=flat-square | ||
[npm-url]: http://npmjs.org/package/rc-slider | ||
[travis-image]: https://img.shields.io/travis/react-component/slider.svg?style=flat-square | ||
[travis-image]: https://img.shields.io/travis/react-component/slider/master?style=flat-square | ||
[travis-url]: https://travis-ci.org/react-component/slider | ||
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/slider/master.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/gh/react-component/slider/branch/master | ||
[david-dm-image]: https://david-dm.org/react-component/slider/status.svg | ||
[david-dm-url]: https://david-dm.org/react-component/slider | ||
[david-dm-dev-image]: https://david-dm.org/react-component/slider/dev-status.svg | ||
[david-dm-dev-url]: https://david-dm.org/react-component/slider?type=dev | ||
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square | ||
[node-url]: http://nodejs.org/download/ | ||
[circleci-image]: https://img.shields.io/circleci/react-component/slider/master?style=flat-square | ||
[circleci-url]: https://circleci.com/gh/react-component/slider | ||
[coveralls-image]: https://img.shields.io/coveralls/react-component/slider.svg?style=flat-square | ||
[coveralls-url]: https://coveralls.io/r/react-component/slider?branch=master | ||
[david-url]: https://david-dm.org/react-component/slider | ||
[david-image]: https://david-dm.org/react-component/slider/status.svg?style=flat-square | ||
[david-dev-url]: https://david-dm.org/react-component/slider?type=dev | ||
[david-dev-image]: https://david-dm.org/react-component/slider/dev-status.svg?style=flat-square | ||
[download-image]: https://img.shields.io/npm/dm/rc-slider.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/rc-slider | ||
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-slider | ||
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-slider | ||
## Screenshots | ||
<img src="https://t.alipayobjects.com/images/T1ki8fXeprXXXXXXXX.png" width="550"/> | ||
<img src="https://t.alipayobjects.com/images/T1pPhfXhBqXXXXXXXX.png" width="550"/> | ||
<img src="https://t.alipayobjects.com/images/T1wO8fXd4rXXXXXXXX.png" width="550"/> | ||
<img src="http://i.giphy.com/l46Cs36c9HrHMExoc.gif"/> | ||
## Features | ||
* Supports IE9, IE9+, Chrome, Firefox & Safari | ||
## Install | ||
```bash | ||
npm install --save rc-slider | ||
``` | ||
[![rc-slider](https://nodei.co/npm/rc-slider.png)](https://npmjs.org/package/rc-slider) | ||
@@ -55,20 +38,20 @@ | ||
````js | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
```js | ||
import Slider, { Range } from 'rc-slider'; | ||
// We can just import Slider or Range to reduce bundle size | ||
// import Slider from 'rc-slider/lib/Slider'; | ||
// import Range from 'rc-slider/lib/Range'; | ||
import 'rc-slider/assets/index.css'; | ||
ReactDOM.render( | ||
<div> | ||
export default () => ( | ||
<> | ||
<Slider /> | ||
<Range /> | ||
</div>, | ||
container | ||
</> | ||
); | ||
````` | ||
``` | ||
## Compatibility | ||
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/electron/electron_48x48.png" alt="Electron" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Electron | | ||
| --- | --- | --- | --- | --- | | ||
| IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions | | ||
## API | ||
@@ -75,0 +58,0 @@ |
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
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
0
193595
4382
154