@uiw/react-slider
Advanced tools
Comparing version 4.21.19 to 4.21.20
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"]; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,17 +8,13 @@ value: true | ||
exports["default"] = Dots; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _jsxRuntime = require("react/jsx-runtime"); | ||
function Dots(props) { | ||
var prefixCls = props.prefixCls, | ||
data = props.data, | ||
step = props.step, | ||
min = props.min, | ||
vertical = props.vertical, | ||
marks = props.marks, | ||
markRender = props.markRender; | ||
data = props.data, | ||
step = props.step, | ||
min = props.min, | ||
vertical = props.vertical, | ||
marks = props.marks, | ||
markRender = props.markRender; | ||
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { | ||
@@ -37,4 +32,3 @@ className: "".concat(prefixCls, "-dots"), | ||
} | ||
module.exports = exports.default; | ||
//# sourceMappingURL=Dots.js.map |
123
cjs/index.js
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"]; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"]; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,76 +9,53 @@ value: true | ||
exports["default"] = Slider; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _Dots = _interopRequireDefault(require("./Dots")); | ||
var _jsxRuntime = require("react/jsx-runtime"); | ||
var _excluded = ["prefixCls", "value", "min", "max", "dots", "step", "disabled", "progress", "tooltip", "className", "marks", "renderMarks", "vertical", "onChange"]; | ||
function Slider(props) { | ||
var _objectSpread2; | ||
var _props$prefixCls = props.prefixCls, | ||
prefixCls = _props$prefixCls === void 0 ? 'w-slider' : _props$prefixCls, | ||
_props$value = props.value, | ||
value = _props$value === void 0 ? 0 : _props$value, | ||
_props$min = props.min, | ||
min = _props$min === void 0 ? 0 : _props$min, | ||
_props$max = props.max, | ||
max = _props$max === void 0 ? 100 : _props$max, | ||
_props$dots = props.dots, | ||
dots = _props$dots === void 0 ? false : _props$dots, | ||
_props$step = props.step, | ||
step = _props$step === void 0 ? 1 : _props$step, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$progress = props.progress, | ||
progress = _props$progress === void 0 ? true : _props$progress, | ||
_props$tooltip = props.tooltip, | ||
tooltip = _props$tooltip === void 0 ? false : _props$tooltip, | ||
className = props.className, | ||
marks = props.marks, | ||
renderMarks = props.renderMarks, | ||
vertical = props.vertical, | ||
onChange = props.onChange, | ||
other = (0, _objectWithoutProperties2["default"])(props, _excluded); | ||
prefixCls = _props$prefixCls === void 0 ? 'w-slider' : _props$prefixCls, | ||
_props$value = props.value, | ||
value = _props$value === void 0 ? 0 : _props$value, | ||
_props$min = props.min, | ||
min = _props$min === void 0 ? 0 : _props$min, | ||
_props$max = props.max, | ||
max = _props$max === void 0 ? 100 : _props$max, | ||
_props$dots = props.dots, | ||
dots = _props$dots === void 0 ? false : _props$dots, | ||
_props$step = props.step, | ||
step = _props$step === void 0 ? 1 : _props$step, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$progress = props.progress, | ||
progress = _props$progress === void 0 ? true : _props$progress, | ||
_props$tooltip = props.tooltip, | ||
tooltip = _props$tooltip === void 0 ? false : _props$tooltip, | ||
className = props.className, | ||
marks = props.marks, | ||
renderMarks = props.renderMarks, | ||
vertical = props.vertical, | ||
onChange = props.onChange, | ||
other = (0, _objectWithoutProperties2["default"])(props, _excluded); | ||
var bar = _react["default"].useRef(null); | ||
var slider = _react["default"].useRef(null); | ||
var indexBar = _react["default"].useRef(); | ||
var startX = _react["default"].useRef(); | ||
var curValue = _react["default"].useRef(); | ||
var barWidth = _react["default"].useRef(); | ||
var barOffsetLeft = _react["default"].useRef(); | ||
var move = _react["default"].useRef(); | ||
var _useState = (0, _react.useState)(Array.isArray(value) ? value : [value]), | ||
_useState2 = (0, _slicedToArray2["default"])(_useState, 2), | ||
arrValue = _useState2[0], | ||
setArrValue = _useState2[1]; | ||
_useState2 = (0, _slicedToArray2["default"])(_useState, 2), | ||
arrValue = _useState2[0], | ||
setArrValue = _useState2[1]; | ||
(0, _react.useEffect)(function () { | ||
return setArrValue(Array.isArray(value) ? value : [value]); | ||
}, [value]); | ||
other.onClick = function (evn) { | ||
@@ -90,3 +65,2 @@ if (move.current !== undefined) { | ||
} | ||
var markOffset = slider.current.getBoundingClientRect(); | ||
@@ -97,3 +71,2 @@ var vals = getWidthToValue(evn[vertical ? 'clientY' : 'clientX'] - markOffset[vertical ? 'y' : 'x']); | ||
}; | ||
function getRangeValue(val) { | ||
@@ -103,22 +76,16 @@ if (!Array.isArray(value)) { | ||
} | ||
var newData = (0, _toConsumableArray2["default"])(arrValue); | ||
var val1 = newData[0]; | ||
var val2 = newData[1]; | ||
if (val1 < val2 && val1 > val || val1 > val2 && val1 < val) { | ||
newData[0] = val; | ||
} | ||
if (val1 < val2 && val2 < val || val1 > val2 && val2 > val) { | ||
newData[1] = val; | ||
} | ||
if (val1 > val && val2 < val) { | ||
var half = val2 + (val1 - val2) / 2; | ||
if (half >= val) { | ||
newData[1] = val; | ||
} | ||
if (half < val) { | ||
@@ -128,10 +95,7 @@ newData[0] = val; | ||
} | ||
if (val2 > val && val1 < val) { | ||
var _half = val1 + (val2 - val1) / 2; | ||
if (_half >= val) { | ||
newData[0] = val; | ||
} | ||
if (_half < val) { | ||
@@ -141,6 +105,4 @@ newData[1] = val; | ||
} | ||
return newData; | ||
} | ||
function handleChange(val) { | ||
@@ -150,19 +112,14 @@ setArrValue((0, _toConsumableArray2["default"])(val)); | ||
} | ||
function getWidthToValue(width) { | ||
var equal = (max - min) / step; | ||
var percent = 0; | ||
if (slider.current) { | ||
percent = width / slider.current[vertical ? 'clientHeight' : 'clientWidth'] * 100; | ||
} | ||
if (percent <= 0) { | ||
percent = 0; | ||
} | ||
if (percent >= 100) { | ||
percent = 100; | ||
} | ||
var num = equal * (percent / 100) + 0.5; | ||
@@ -173,3 +130,2 @@ var numFloor = Math.floor(num); | ||
} | ||
function onHandleBtnDown(idx, env) { | ||
@@ -179,7 +135,5 @@ if (disabled) { | ||
} | ||
indexBar.current = idx; | ||
move.current = true; | ||
startX.current = env[vertical ? 'clientY' : 'clientX']; | ||
if (bar.current) { | ||
@@ -189,13 +143,9 @@ barWidth.current = bar.current[vertical ? 'clientHeight' : 'clientWidth']; | ||
} | ||
var vals = (0, _toConsumableArray2["default"])(arrValue); | ||
if (Array.isArray(value)) { | ||
barWidth.current = indexBar.current === 1 && vals[1] > vals[0] || indexBar.current !== 1 && vals[0] > vals[1] ? barWidth.current + barOffsetLeft.current : barOffsetLeft.current; | ||
} | ||
window.addEventListener('mousemove', onDragging); | ||
window.addEventListener('mouseup', onDragEnd); | ||
} | ||
function onDragging(env) { | ||
@@ -205,11 +155,7 @@ if (!move.current) { | ||
} | ||
var vals = (0, _toConsumableArray2["default"])(arrValue); | ||
var valueToWidth = getWidthToValue(env[vertical ? 'clientY' : 'clientX'] - startX.current + barWidth.current); | ||
if (valueToWidth !== curValue.current) { | ||
vals[indexBar.current] = valueToWidth; | ||
var _barStyl = getStyle(vals); | ||
if (bar.current) { | ||
@@ -219,3 +165,2 @@ bar.current.style[vertical ? 'top' : 'left'] = _barStyl.left; | ||
} | ||
handleChange(vals); | ||
@@ -225,3 +170,2 @@ curValue.current = valueToWidth; | ||
} | ||
function onDragEnd() { | ||
@@ -232,3 +176,2 @@ move.current = undefined; | ||
} | ||
var stepArray = function stepArray() { | ||
@@ -238,15 +181,11 @@ var equal = (max - min) / step; | ||
var result = [0]; | ||
for (var i = 1; i < equal; i += 1) { | ||
result.push(i * stepWidth); | ||
} | ||
result.push(100); | ||
return result; | ||
}; | ||
function getValueToPercent(vals) { | ||
return (vals - min) * 100 / (max - min); | ||
} | ||
function getStyle(val) { | ||
@@ -258,3 +197,2 @@ val = val || arrValue; | ||
}; | ||
if (!Array.isArray(value)) { | ||
@@ -268,6 +206,4 @@ barStyl.right = "".concat(100 - getValueToPercent(val[0]), "%"); | ||
} | ||
return barStyl; | ||
} | ||
function getLabelValue(val) { | ||
@@ -281,12 +217,8 @@ if (marks && marks !== true && marks[val] && marks[val].label) { | ||
} | ||
return val; | ||
} | ||
var barStyl = getStyle(); | ||
if (disabled) { | ||
delete other.onClick; | ||
} | ||
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread3["default"])((0, _objectSpread3["default"])({ | ||
@@ -324,3 +256,2 @@ ref: slider, | ||
var mark = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!mark) { | ||
@@ -331,3 +262,2 @@ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { | ||
} | ||
var other = (0, _typeof2["default"])(mark) === 'object' ? mark : {}; | ||
@@ -342,4 +272,3 @@ delete other.label; | ||
} | ||
module.exports = exports.default; | ||
//# sourceMappingURL=index.js.map |
@@ -11,19 +11,18 @@ import _extends from "@babel/runtime/helpers/extends"; | ||
var { | ||
prefixCls = 'w-slider', | ||
value = 0, | ||
min = 0, | ||
max = 100, | ||
dots = false, | ||
step = 1, | ||
disabled = false, | ||
progress = true, | ||
tooltip = false, | ||
className, | ||
marks, | ||
renderMarks, | ||
vertical, | ||
onChange | ||
} = props, | ||
other = _objectWithoutPropertiesLoose(props, _excluded); | ||
prefixCls = 'w-slider', | ||
value = 0, | ||
min = 0, | ||
max = 100, | ||
dots = false, | ||
step = 1, | ||
disabled = false, | ||
progress = true, | ||
tooltip = false, | ||
className, | ||
marks, | ||
renderMarks, | ||
vertical, | ||
onChange | ||
} = props, | ||
other = _objectWithoutPropertiesLoose(props, _excluded); | ||
var bar = React.useRef(null); | ||
@@ -39,3 +38,2 @@ var slider = React.useRef(null); | ||
useEffect(() => setArrValue(Array.isArray(value) ? value : [value]), [value]); | ||
other.onClick = evn => { | ||
@@ -45,3 +43,2 @@ if (move.current !== undefined) { | ||
} | ||
var markOffset = slider.current.getBoundingClientRect(); | ||
@@ -52,3 +49,2 @@ var vals = getWidthToValue(evn[vertical ? 'clientY' : 'clientX'] - markOffset[vertical ? 'y' : 'x']); | ||
}; | ||
function getRangeValue(val) { | ||
@@ -58,22 +54,16 @@ if (!Array.isArray(value)) { | ||
} | ||
var newData = [...arrValue]; | ||
var val1 = newData[0]; | ||
var val2 = newData[1]; | ||
if (val1 < val2 && val1 > val || val1 > val2 && val1 < val) { | ||
newData[0] = val; | ||
} | ||
if (val1 < val2 && val2 < val || val1 > val2 && val2 > val) { | ||
newData[1] = val; | ||
} | ||
if (val1 > val && val2 < val) { | ||
var half = val2 + (val1 - val2) / 2; | ||
if (half >= val) { | ||
newData[1] = val; | ||
} | ||
if (half < val) { | ||
@@ -83,10 +73,7 @@ newData[0] = val; | ||
} | ||
if (val2 > val && val1 < val) { | ||
var _half = val1 + (val2 - val1) / 2; | ||
if (_half >= val) { | ||
newData[0] = val; | ||
} | ||
if (_half < val) { | ||
@@ -96,6 +83,4 @@ newData[1] = val; | ||
} | ||
return newData; | ||
} | ||
function handleChange(val) { | ||
@@ -105,19 +90,14 @@ setArrValue([...val]); | ||
} | ||
function getWidthToValue(width) { | ||
var equal = (max - min) / step; | ||
var percent = 0; | ||
if (slider.current) { | ||
percent = width / slider.current[vertical ? 'clientHeight' : 'clientWidth'] * 100; | ||
} | ||
if (percent <= 0) { | ||
percent = 0; | ||
} | ||
if (percent >= 100) { | ||
percent = 100; | ||
} | ||
var num = equal * (percent / 100) + 0.5; | ||
@@ -128,3 +108,2 @@ var numFloor = Math.floor(num); | ||
} | ||
function onHandleBtnDown(idx, env) { | ||
@@ -134,7 +113,5 @@ if (disabled) { | ||
} | ||
indexBar.current = idx; | ||
move.current = true; | ||
startX.current = env[vertical ? 'clientY' : 'clientX']; | ||
if (bar.current) { | ||
@@ -144,13 +121,9 @@ barWidth.current = bar.current[vertical ? 'clientHeight' : 'clientWidth']; | ||
} | ||
var vals = [...arrValue]; | ||
if (Array.isArray(value)) { | ||
barWidth.current = indexBar.current === 1 && vals[1] > vals[0] || indexBar.current !== 1 && vals[0] > vals[1] ? barWidth.current + barOffsetLeft.current : barOffsetLeft.current; | ||
} | ||
window.addEventListener('mousemove', onDragging); | ||
window.addEventListener('mouseup', onDragEnd); | ||
} | ||
function onDragging(env) { | ||
@@ -160,11 +133,7 @@ if (!move.current) { | ||
} | ||
var vals = [...arrValue]; | ||
var valueToWidth = getWidthToValue(env[vertical ? 'clientY' : 'clientX'] - startX.current + barWidth.current); | ||
if (valueToWidth !== curValue.current) { | ||
vals[indexBar.current] = valueToWidth; | ||
var _barStyl = getStyle(vals); | ||
if (bar.current) { | ||
@@ -174,3 +143,2 @@ bar.current.style[vertical ? 'top' : 'left'] = _barStyl.left; | ||
} | ||
handleChange(vals); | ||
@@ -180,3 +148,2 @@ curValue.current = valueToWidth; | ||
} | ||
function onDragEnd() { | ||
@@ -187,3 +154,2 @@ move.current = undefined; | ||
} | ||
var stepArray = () => { | ||
@@ -193,15 +159,11 @@ var equal = (max - min) / step; | ||
var result = [0]; | ||
for (var i = 1; i < equal; i += 1) { | ||
result.push(i * stepWidth); | ||
} | ||
result.push(100); | ||
return result; | ||
}; | ||
function getValueToPercent(vals) { | ||
return (vals - min) * 100 / (max - min); | ||
} | ||
function getStyle(val) { | ||
@@ -213,3 +175,2 @@ val = val || arrValue; | ||
}; | ||
if (!Array.isArray(value)) { | ||
@@ -223,6 +184,4 @@ barStyl.right = 100 - getValueToPercent(val[0]) + "%"; | ||
} | ||
return barStyl; | ||
} | ||
function getLabelValue(val) { | ||
@@ -236,12 +195,8 @@ if (marks && marks !== true && marks[val] && marks[val].label) { | ||
} | ||
return val; | ||
} | ||
var barStyl = getStyle(); | ||
if (disabled) { | ||
delete other.onClick; | ||
} | ||
return /*#__PURE__*/_jsxs("div", _extends({ | ||
@@ -284,3 +239,2 @@ ref: slider, | ||
} | ||
if (!mark) { | ||
@@ -291,3 +245,2 @@ return /*#__PURE__*/_jsxs("div", { | ||
} | ||
var other = typeof mark === 'object' ? mark : {}; | ||
@@ -294,0 +247,0 @@ delete other.label; |
{ | ||
"name": "@uiw/react-slider", | ||
"version": "4.21.19", | ||
"version": "4.21.20", | ||
"description": "Slider component", | ||
@@ -47,4 +47,4 @@ "author": "Kenny Wong <wowohoo@qq.com>", | ||
"dependencies": { | ||
"@uiw/utils": "^4.21.19" | ||
"@uiw/utils": "^4.21.20" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
102323
Updated@uiw/utils@^4.21.20