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.
Files changed (3) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +38 -23
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -72,6 +72,7 @@ export type I_Range = {
72
72
  labels?: AI_label[];
73
73
  ranges?: I_range[];
74
74
  rangeOption?: {
75
+ clickMode?: 'step' | 'exact';
75
76
  onStartDrag?: (index: number) => void;
76
77
  onEndDrag?: () => void;
77
78
  pointHtml?: (p: {
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
- let clickedValue;
287
- //vertical condition
288
- if (type === "spinner") {
289
- clickedValue = getValueByAngle(mousePosition.centerAngle);
290
- }
291
- else {
292
- clickedValue = getValueByXP(mousePosition[props.vertical ? 'yp' : 'xp']);
293
- }
294
- if (clickedValue < values[values.length - 1] && clickedValue > values[0]) {
295
- return;
296
- }
297
- if (clickedValue < values[0]) {
298
- change1Unit(-1);
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
- change1Unit(1);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-range",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "linear and circular range input",
5
5
  "main": "index.js",
6
6
  "scripts": {