@zag-js/slider 1.6.2 → 1.7.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 CHANGED
@@ -111,13 +111,15 @@ interface SliderProps extends DirectionProperty, CommonProperties {
111
111
  */
112
112
  orientation?: "vertical" | "horizontal" | undefined;
113
113
  /**
114
- * The origin of the slider range
114
+ * The origin of the slider range. The track is filled from the origin
115
+ * to the thumb for single values.
115
116
  * - "start": Useful when the value represents an absolute value
116
117
  * - "center": Useful when the value represents an offset (relative)
118
+ * - "end": Useful when the value represents an offset from the end
117
119
  *
118
120
  * @default "start"
119
121
  */
120
- origin?: "start" | "center" | undefined;
122
+ origin?: "start" | "center" | "end" | undefined;
121
123
  /**
122
124
  * The alignment of the slider thumb relative to the track
123
125
  * - `center`: the thumb will extend beyond the bounds of the slider track.
package/dist/index.d.ts CHANGED
@@ -111,13 +111,15 @@ interface SliderProps extends DirectionProperty, CommonProperties {
111
111
  */
112
112
  orientation?: "vertical" | "horizontal" | undefined;
113
113
  /**
114
- * The origin of the slider range
114
+ * The origin of the slider range. The track is filled from the origin
115
+ * to the thumb for single values.
115
116
  * - "start": Useful when the value represents an absolute value
116
117
  * - "center": Useful when the value represents an offset (relative)
118
+ * - "end": Useful when the value represents an offset from the end
117
119
  *
118
120
  * @default "start"
119
121
  */
120
- origin?: "start" | "center" | undefined;
122
+ origin?: "start" | "center" | "end" | undefined;
121
123
  /**
122
124
  * The alignment of the slider thumb relative to the track
123
125
  * - `center`: the thumb will extend beyond the bounds of the slider track.
package/dist/index.js CHANGED
@@ -71,6 +71,9 @@ function getRangeOffsets(params) {
71
71
  const end = isNegative ? "50%" : `${100 - valuePercent[0]}%`;
72
72
  return { start, end };
73
73
  }
74
+ if (prop("origin") === "end") {
75
+ return { start: `${lastPercent}%`, end: "0%" };
76
+ }
74
77
  return { start: "0%", end: `${100 - lastPercent}%` };
75
78
  }
76
79
  return { start: `${firstPercent}%`, end: `${100 - lastPercent}%` };
@@ -151,12 +154,15 @@ function getRootStyle(params) {
151
154
  const isVertical = computed("isVertical");
152
155
  const isRtl = computed("isRtl");
153
156
  const range = getRangeOffsets(params);
157
+ const thumbSize = context.get("thumbSize");
154
158
  const offsetStyles = context.get("value").reduce((styles, value, index) => {
155
159
  const offset = getThumbOffset(params, value);
156
160
  return { ...styles, [`--slider-thumb-offset-${index}`]: offset };
157
161
  }, {});
158
162
  return {
159
163
  ...offsetStyles,
164
+ "--slider-thumb-width": utils.toPx(thumbSize?.width),
165
+ "--slider-thumb-height": utils.toPx(thumbSize?.height),
160
166
  "--slider-thumb-transform": isVertical ? "translateY(50%)" : isRtl ? "translateX(50%)" : "translateX(-50%)",
161
167
  "--slider-range-start": range.start,
162
168
  "--slider-range-end": range.end
@@ -709,7 +715,7 @@ var machine = core.createMachine({
709
715
  });
710
716
  },
711
717
  trackThumbsSize({ context, scope, prop }) {
712
- if (prop("thumbAlignment") !== "contain" || context.get("thumbSize")) return;
718
+ if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
713
719
  return elementSize.trackElementsSize({
714
720
  getNodes: () => getElements(scope),
715
721
  observeMutation: true,
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createAnatomy } from '@zag-js/anatomy';
2
2
  import { raf, setElementValue, queryAll, trackPointerMove, trackFormControl, getRelativePoint, dispatchInputValueEvent, dataAttr, isLeftClick, isModifierKey, getEventPoint, ariaAttr, getEventStep, getEventKey } from '@zag-js/dom-query';
3
- import { setValueAtIndex, getValuePercent, isEqual, createSplitProps, snapValueToStep, clampValue, getValueRanges, getNextStepValue, getPreviousStepValue, getPercentValue, getClosestValueIndex, first, last, getValueTransformer } from '@zag-js/utils';
3
+ import { setValueAtIndex, getValuePercent, isEqual, createSplitProps, snapValueToStep, clampValue, getValueRanges, getNextStepValue, getPreviousStepValue, getPercentValue, getClosestValueIndex, first, last, toPx, getValueTransformer } from '@zag-js/utils';
4
4
  import { createMachine } from '@zag-js/core';
5
5
  import { trackElementsSize } from '@zag-js/element-size';
6
6
  import { createProps } from '@zag-js/types';
@@ -69,6 +69,9 @@ function getRangeOffsets(params) {
69
69
  const end = isNegative ? "50%" : `${100 - valuePercent[0]}%`;
70
70
  return { start, end };
71
71
  }
72
+ if (prop("origin") === "end") {
73
+ return { start: `${lastPercent}%`, end: "0%" };
74
+ }
72
75
  return { start: "0%", end: `${100 - lastPercent}%` };
73
76
  }
74
77
  return { start: `${firstPercent}%`, end: `${100 - lastPercent}%` };
@@ -149,12 +152,15 @@ function getRootStyle(params) {
149
152
  const isVertical = computed("isVertical");
150
153
  const isRtl = computed("isRtl");
151
154
  const range = getRangeOffsets(params);
155
+ const thumbSize = context.get("thumbSize");
152
156
  const offsetStyles = context.get("value").reduce((styles, value, index) => {
153
157
  const offset = getThumbOffset(params, value);
154
158
  return { ...styles, [`--slider-thumb-offset-${index}`]: offset };
155
159
  }, {});
156
160
  return {
157
161
  ...offsetStyles,
162
+ "--slider-thumb-width": toPx(thumbSize?.width),
163
+ "--slider-thumb-height": toPx(thumbSize?.height),
158
164
  "--slider-thumb-transform": isVertical ? "translateY(50%)" : isRtl ? "translateX(50%)" : "translateX(-50%)",
159
165
  "--slider-range-start": range.start,
160
166
  "--slider-range-end": range.end
@@ -707,7 +713,7 @@ var machine = createMachine({
707
713
  });
708
714
  },
709
715
  trackThumbsSize({ context, scope, prop }) {
710
- if (prop("thumbAlignment") !== "contain" || context.get("thumbSize")) return;
716
+ if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
711
717
  return trackElementsSize({
712
718
  getNodes: () => getElements(scope),
713
719
  observeMutation: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "1.6.2",
3
+ "version": "1.7.0",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,12 +27,12 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "1.6.2",
31
- "@zag-js/core": "1.6.2",
32
- "@zag-js/dom-query": "1.6.2",
33
- "@zag-js/utils": "1.6.2",
34
- "@zag-js/element-size": "1.6.2",
35
- "@zag-js/types": "1.6.2"
30
+ "@zag-js/anatomy": "1.7.0",
31
+ "@zag-js/core": "1.7.0",
32
+ "@zag-js/dom-query": "1.7.0",
33
+ "@zag-js/utils": "1.7.0",
34
+ "@zag-js/element-size": "1.7.0",
35
+ "@zag-js/types": "1.7.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "clean-package": "2.2.0"