aio-range 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/index.js +38 -23
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -274,31 +274,39 @@ const useRange = (PROPS, type) => {
|
|
|
274
274
|
if (disabled) {
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
|
-
click(p.mousePosition);
|
|
277
|
+
click(p.mousePosition, p.domLimit);
|
|
278
278
|
}
|
|
279
279
|
});
|
|
280
280
|
}, 100);
|
|
281
281
|
}, [changeHandle]);
|
|
282
|
-
function click(mousePosition) {
|
|
282
|
+
function click(mousePosition, domLimit) {
|
|
283
|
+
var _a;
|
|
284
|
+
const exactClick = type === 'slider' && ((_a = props.rangeOption) === null || _a === void 0 ? void 0 : _a.clickMode) === 'exact' && !props.multiple && !props.vertical;
|
|
283
285
|
if (props.disabled === true) {
|
|
284
286
|
return;
|
|
285
287
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
288
|
+
if (!exactClick) {
|
|
289
|
+
let clickedValue;
|
|
290
|
+
//vertical condition
|
|
291
|
+
if (type === "spinner") {
|
|
292
|
+
clickedValue = getValueByAngle(mousePosition.centerAngle);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
clickedValue = getValueByXP(mousePosition[props.vertical ? 'yp' : 'xp']);
|
|
296
|
+
}
|
|
297
|
+
if (clickedValue < values[values.length - 1] && clickedValue > values[0]) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (clickedValue < values[0]) {
|
|
301
|
+
change1Unit(-1);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
change1Unit(1);
|
|
305
|
+
}
|
|
299
306
|
}
|
|
300
307
|
else {
|
|
301
|
-
|
|
308
|
+
const xp = 100 * mousePosition.x / domLimit.width;
|
|
309
|
+
changeByPercent(props.reverse ? 100 - xp : xp);
|
|
302
310
|
}
|
|
303
311
|
}
|
|
304
312
|
function changeHandle(obj) {
|
|
@@ -355,6 +363,20 @@ const useRange = (PROPS, type) => {
|
|
|
355
363
|
newValue = moveAll(newValue, dir * props.step);
|
|
356
364
|
changeValue(newValue);
|
|
357
365
|
}
|
|
366
|
+
function changeByPercent(percent) {
|
|
367
|
+
const { start, end } = props;
|
|
368
|
+
const range = end - start;
|
|
369
|
+
const value = percent * range / 100 + start;
|
|
370
|
+
let newValue = [value];
|
|
371
|
+
changeValue(newValue);
|
|
372
|
+
}
|
|
373
|
+
function moveAll(newValue, offset, ifFailedReturnOriginalValue) {
|
|
374
|
+
let res = newValue.map((o) => o + offset);
|
|
375
|
+
if (res[0] < props.start || res[res.length - 1] > props.end) {
|
|
376
|
+
return ifFailedReturnOriginalValue ? values : newValue;
|
|
377
|
+
}
|
|
378
|
+
return res;
|
|
379
|
+
}
|
|
358
380
|
function changeValue(newValue) {
|
|
359
381
|
if (!props.onChange || props.disabled === true) {
|
|
360
382
|
return;
|
|
@@ -378,13 +400,6 @@ const useRange = (PROPS, type) => {
|
|
|
378
400
|
}
|
|
379
401
|
return { before, after };
|
|
380
402
|
}
|
|
381
|
-
function moveAll(newValue, offset, ifFailedReturnOriginalValue) {
|
|
382
|
-
let res = newValue.map((o) => o + offset);
|
|
383
|
-
if (res[0] < props.start || res[res.length - 1] > props.end) {
|
|
384
|
-
return ifFailedReturnOriginalValue ? values : newValue;
|
|
385
|
-
}
|
|
386
|
-
return res;
|
|
387
|
-
}
|
|
388
403
|
const getFloatLength = (step) => {
|
|
389
404
|
const str = step.toString();
|
|
390
405
|
if (str.indexOf('.') === -1) {
|