@zag-js/slider 1.13.1 → 1.15.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/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +12 -3
- package/dist/index.mjs +13 -4
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -102,6 +102,12 @@ interface SliderProps extends DirectionProperty, CommonProperties {
|
|
|
102
102
|
step?: number | undefined;
|
|
103
103
|
/**
|
|
104
104
|
* The minimum permitted steps between multiple thumbs.
|
|
105
|
+
*
|
|
106
|
+
* `minStepsBetweenThumbs` * `step` should reflect the gap between the thumbs.
|
|
107
|
+
*
|
|
108
|
+
* - `step: 1` and `minStepsBetweenThumbs: 10` => gap is `10`
|
|
109
|
+
* - `step: 10` and `minStepsBetweenThumbs: 2` => gap is `20`
|
|
110
|
+
*
|
|
105
111
|
* @default 0
|
|
106
112
|
*/
|
|
107
113
|
minStepsBetweenThumbs?: number | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -102,6 +102,12 @@ interface SliderProps extends DirectionProperty, CommonProperties {
|
|
|
102
102
|
step?: number | undefined;
|
|
103
103
|
/**
|
|
104
104
|
* The minimum permitted steps between multiple thumbs.
|
|
105
|
+
*
|
|
106
|
+
* `minStepsBetweenThumbs` * `step` should reflect the gap between the thumbs.
|
|
107
|
+
*
|
|
108
|
+
* - `step: 1` and `minStepsBetweenThumbs: 10` => gap is `10`
|
|
109
|
+
* - `step: 10` and `minStepsBetweenThumbs: 2` => gap is `20`
|
|
110
|
+
*
|
|
105
111
|
* @default 0
|
|
106
112
|
*/
|
|
107
113
|
minStepsBetweenThumbs?: number | undefined;
|
package/dist/index.js
CHANGED
|
@@ -202,7 +202,8 @@ function normalizeValues(params, nextValues) {
|
|
|
202
202
|
}
|
|
203
203
|
function getRangeAtIndex(params, index) {
|
|
204
204
|
const { context, prop } = params;
|
|
205
|
-
|
|
205
|
+
const step = prop("step") * prop("minStepsBetweenThumbs");
|
|
206
|
+
return utils.getValueRanges(context.get("value"), prop("min"), prop("max"), step)[index];
|
|
206
207
|
}
|
|
207
208
|
function constrainValue(params, value, index) {
|
|
208
209
|
const { prop } = params;
|
|
@@ -545,7 +546,13 @@ var normalize = (value, min, max, step, minStepsBetweenThumbs) => {
|
|
|
545
546
|
const ranges = utils.getValueRanges(value, min, max, minStepsBetweenThumbs * step);
|
|
546
547
|
return ranges.map((range) => {
|
|
547
548
|
const snapValue = utils.snapValueToStep(range.value, range.min, range.max, step);
|
|
548
|
-
|
|
549
|
+
const rangeValue = utils.clampValue(snapValue, range.min, range.max);
|
|
550
|
+
if (!utils.isValueWithinRange(rangeValue, min, max)) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
"[zag-js/slider] The configured `min`, `max`, `step` or `minStepsBetweenThumbs` values are invalid"
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
return rangeValue;
|
|
549
556
|
});
|
|
550
557
|
};
|
|
551
558
|
var machine = core.createMachine({
|
|
@@ -746,7 +753,9 @@ var machine = core.createMachine({
|
|
|
746
753
|
});
|
|
747
754
|
},
|
|
748
755
|
invokeOnChangeEnd({ prop, context }) {
|
|
749
|
-
|
|
756
|
+
queueMicrotask(() => {
|
|
757
|
+
prop("onValueChangeEnd")?.({ value: context.get("value") });
|
|
758
|
+
});
|
|
750
759
|
},
|
|
751
760
|
setClosestThumbIndex(params) {
|
|
752
761
|
const { context, event } = params;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
2
|
import { raf, setElementValue, trackElementRect, queryAll, trackPointerMove, trackFormControl, getRelativePoint, dispatchInputValueEvent, dataAttr, isLeftClick, isModifierKey, getEventPoint, ariaAttr, getEventStep, getEventKey } from '@zag-js/dom-query';
|
|
3
|
-
import { setValueAtIndex, pick, getValuePercent, isEqual, createSplitProps, snapValueToStep, clampValue, getValueRanges, getNextStepValue, getPreviousStepValue, getPercentValue, getClosestValueIndex, first, last, toPx, getValueTransformer } from '@zag-js/utils';
|
|
3
|
+
import { setValueAtIndex, pick, getValuePercent, isEqual, createSplitProps, snapValueToStep, clampValue, getValueRanges, getNextStepValue, getPreviousStepValue, getPercentValue, getClosestValueIndex, isValueWithinRange, first, last, toPx, getValueTransformer } from '@zag-js/utils';
|
|
4
4
|
import { createMachine } from '@zag-js/core';
|
|
5
5
|
import { createProps } from '@zag-js/types';
|
|
6
6
|
|
|
@@ -200,7 +200,8 @@ function normalizeValues(params, nextValues) {
|
|
|
200
200
|
}
|
|
201
201
|
function getRangeAtIndex(params, index) {
|
|
202
202
|
const { context, prop } = params;
|
|
203
|
-
|
|
203
|
+
const step = prop("step") * prop("minStepsBetweenThumbs");
|
|
204
|
+
return getValueRanges(context.get("value"), prop("min"), prop("max"), step)[index];
|
|
204
205
|
}
|
|
205
206
|
function constrainValue(params, value, index) {
|
|
206
207
|
const { prop } = params;
|
|
@@ -543,7 +544,13 @@ var normalize = (value, min, max, step, minStepsBetweenThumbs) => {
|
|
|
543
544
|
const ranges = getValueRanges(value, min, max, minStepsBetweenThumbs * step);
|
|
544
545
|
return ranges.map((range) => {
|
|
545
546
|
const snapValue = snapValueToStep(range.value, range.min, range.max, step);
|
|
546
|
-
|
|
547
|
+
const rangeValue = clampValue(snapValue, range.min, range.max);
|
|
548
|
+
if (!isValueWithinRange(rangeValue, min, max)) {
|
|
549
|
+
throw new Error(
|
|
550
|
+
"[zag-js/slider] The configured `min`, `max`, `step` or `minStepsBetweenThumbs` values are invalid"
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
return rangeValue;
|
|
547
554
|
});
|
|
548
555
|
};
|
|
549
556
|
var machine = createMachine({
|
|
@@ -744,7 +751,9 @@ var machine = createMachine({
|
|
|
744
751
|
});
|
|
745
752
|
},
|
|
746
753
|
invokeOnChangeEnd({ prop, context }) {
|
|
747
|
-
|
|
754
|
+
queueMicrotask(() => {
|
|
755
|
+
prop("onValueChangeEnd")?.({ value: context.get("value") });
|
|
756
|
+
});
|
|
748
757
|
},
|
|
749
758
|
setClosestThumbIndex(params) {
|
|
750
759
|
const { context, event } = params;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/slider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "Core logic for the slider widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/anatomy": "1.
|
|
31
|
-
"@zag-js/core": "1.
|
|
32
|
-
"@zag-js/dom-query": "1.
|
|
33
|
-
"@zag-js/utils": "1.
|
|
34
|
-
"@zag-js/types": "1.
|
|
30
|
+
"@zag-js/anatomy": "1.15.0",
|
|
31
|
+
"@zag-js/core": "1.15.0",
|
|
32
|
+
"@zag-js/dom-query": "1.15.0",
|
|
33
|
+
"@zag-js/utils": "1.15.0",
|
|
34
|
+
"@zag-js/types": "1.15.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"clean-package": "2.2.0"
|