@zag-js/slider 1.3.3 → 1.4.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.js CHANGED
@@ -229,7 +229,7 @@ function getClosestIndex(params, pointValue) {
229
229
  }
230
230
 
231
231
  // src/slider.connect.ts
232
- function connect(service, normalize) {
232
+ function connect(service, normalize2) {
233
233
  const { state, send, context, prop, computed, scope } = service;
234
234
  const ariaLabel = prop("aria-label");
235
235
  const ariaLabelledBy = prop("aria-labelledby");
@@ -287,7 +287,7 @@ function connect(service, normalize) {
287
287
  send({ type: "FOCUS", index: 0 });
288
288
  },
289
289
  getLabelProps() {
290
- return normalize.label({
290
+ return normalize2.label({
291
291
  ...parts.label.attrs,
292
292
  dir: prop("dir"),
293
293
  "data-disabled": domQuery.dataAttr(disabled),
@@ -309,7 +309,7 @@ function connect(service, normalize) {
309
309
  });
310
310
  },
311
311
  getRootProps() {
312
- return normalize.element({
312
+ return normalize2.element({
313
313
  ...parts.root.attrs,
314
314
  "data-disabled": domQuery.dataAttr(disabled),
315
315
  "data-orientation": prop("orientation"),
@@ -322,7 +322,7 @@ function connect(service, normalize) {
322
322
  });
323
323
  },
324
324
  getValueTextProps() {
325
- return normalize.element({
325
+ return normalize2.element({
326
326
  ...parts.valueText.attrs,
327
327
  dir: prop("dir"),
328
328
  "data-disabled": domQuery.dataAttr(disabled),
@@ -333,7 +333,7 @@ function connect(service, normalize) {
333
333
  });
334
334
  },
335
335
  getTrackProps() {
336
- return normalize.element({
336
+ return normalize2.element({
337
337
  ...parts.track.attrs,
338
338
  dir: prop("dir"),
339
339
  id: getTrackId(scope),
@@ -352,7 +352,7 @@ function connect(service, normalize) {
352
352
  const valueText = prop("getAriaValueText")?.({ value, index });
353
353
  const _ariaLabel = Array.isArray(ariaLabel) ? ariaLabel[index] : ariaLabel;
354
354
  const _ariaLabelledBy = Array.isArray(ariaLabelledBy) ? ariaLabelledBy[index] : ariaLabelledBy;
355
- return normalize.element({
355
+ return normalize2.element({
356
356
  ...parts.thumb.attrs,
357
357
  dir: prop("dir"),
358
358
  "data-index": index,
@@ -436,7 +436,7 @@ function connect(service, normalize) {
436
436
  },
437
437
  getHiddenInputProps(props2) {
438
438
  const { index = 0, name } = props2;
439
- return normalize.input({
439
+ return normalize2.input({
440
440
  name: name ?? (prop("name") ? prop("name") + (sliderValue.length > 1 ? "[]" : "") : void 0),
441
441
  form: prop("form"),
442
442
  type: "text",
@@ -446,7 +446,7 @@ function connect(service, normalize) {
446
446
  });
447
447
  },
448
448
  getRangeProps() {
449
- return normalize.element({
449
+ return normalize2.element({
450
450
  id: getRangeId(scope),
451
451
  ...parts.range.attrs,
452
452
  dir: prop("dir"),
@@ -459,7 +459,7 @@ function connect(service, normalize) {
459
459
  });
460
460
  },
461
461
  getControlProps() {
462
- return normalize.element({
462
+ return normalize2.element({
463
463
  ...parts.control.attrs,
464
464
  dir: prop("dir"),
465
465
  id: getControlId(scope),
@@ -481,7 +481,7 @@ function connect(service, normalize) {
481
481
  });
482
482
  },
483
483
  getMarkerGroupProps() {
484
- return normalize.element({
484
+ return normalize2.element({
485
485
  ...parts.markerGroup.attrs,
486
486
  role: "presentation",
487
487
  dir: prop("dir"),
@@ -500,7 +500,7 @@ function connect(service, normalize) {
500
500
  } else {
501
501
  markerState = "at-value";
502
502
  }
503
- return normalize.element({
503
+ return normalize2.element({
504
504
  ...parts.marker.attrs,
505
505
  id: getMarkerId(scope, props2.value),
506
506
  role: "presentation",
@@ -515,7 +515,7 @@ function connect(service, normalize) {
515
515
  getDraggingIndicatorProps(props2) {
516
516
  const { index = 0 } = props2;
517
517
  const isDragging = index === focusedIndex && dragging;
518
- return normalize.element({
518
+ return normalize2.element({
519
519
  ...parts.draggingIndicator.attrs,
520
520
  role: "presentation",
521
521
  dir: prop("dir"),
@@ -530,19 +530,31 @@ function connect(service, normalize) {
530
530
  var isEqualSize = (a, b) => {
531
531
  return a?.width === b?.width && a?.height === b?.height;
532
532
  };
533
+ var normalize = (value, min, max, step) => {
534
+ const ranges = utils.getValueRanges(value, min, max, step);
535
+ return ranges.map((range) => {
536
+ const snapValue = utils.snapValueToStep(range.value, range.min, range.max, step);
537
+ return utils.clampValue(snapValue, range.min, range.max);
538
+ });
539
+ };
533
540
  var machine = core.createMachine({
534
541
  props({ props: props2 }) {
542
+ const min = props2.min ?? 0;
543
+ const max = props2.max ?? 100;
544
+ const step = props2.step ?? 1;
545
+ const defaultValue = props2.defaultValue ?? [min];
535
546
  return {
536
547
  dir: "ltr",
537
548
  thumbAlignment: "contain",
538
- min: 0,
539
- max: 100,
540
- step: 1,
541
- defaultValue: [0],
542
549
  origin: "start",
543
550
  orientation: "horizontal",
544
551
  minStepsBetweenThumbs: 0,
545
- ...props2
552
+ ...props2,
553
+ defaultValue: normalize(defaultValue, min, max, step),
554
+ value: props2.value ? normalize(props2.value, min, max, step) : void 0,
555
+ max,
556
+ step,
557
+ min
546
558
  };
547
559
  },
548
560
  initialState() {
package/dist/index.mjs CHANGED
@@ -227,7 +227,7 @@ function getClosestIndex(params, pointValue) {
227
227
  }
228
228
 
229
229
  // src/slider.connect.ts
230
- function connect(service, normalize) {
230
+ function connect(service, normalize2) {
231
231
  const { state, send, context, prop, computed, scope } = service;
232
232
  const ariaLabel = prop("aria-label");
233
233
  const ariaLabelledBy = prop("aria-labelledby");
@@ -285,7 +285,7 @@ function connect(service, normalize) {
285
285
  send({ type: "FOCUS", index: 0 });
286
286
  },
287
287
  getLabelProps() {
288
- return normalize.label({
288
+ return normalize2.label({
289
289
  ...parts.label.attrs,
290
290
  dir: prop("dir"),
291
291
  "data-disabled": dataAttr(disabled),
@@ -307,7 +307,7 @@ function connect(service, normalize) {
307
307
  });
308
308
  },
309
309
  getRootProps() {
310
- return normalize.element({
310
+ return normalize2.element({
311
311
  ...parts.root.attrs,
312
312
  "data-disabled": dataAttr(disabled),
313
313
  "data-orientation": prop("orientation"),
@@ -320,7 +320,7 @@ function connect(service, normalize) {
320
320
  });
321
321
  },
322
322
  getValueTextProps() {
323
- return normalize.element({
323
+ return normalize2.element({
324
324
  ...parts.valueText.attrs,
325
325
  dir: prop("dir"),
326
326
  "data-disabled": dataAttr(disabled),
@@ -331,7 +331,7 @@ function connect(service, normalize) {
331
331
  });
332
332
  },
333
333
  getTrackProps() {
334
- return normalize.element({
334
+ return normalize2.element({
335
335
  ...parts.track.attrs,
336
336
  dir: prop("dir"),
337
337
  id: getTrackId(scope),
@@ -350,7 +350,7 @@ function connect(service, normalize) {
350
350
  const valueText = prop("getAriaValueText")?.({ value, index });
351
351
  const _ariaLabel = Array.isArray(ariaLabel) ? ariaLabel[index] : ariaLabel;
352
352
  const _ariaLabelledBy = Array.isArray(ariaLabelledBy) ? ariaLabelledBy[index] : ariaLabelledBy;
353
- return normalize.element({
353
+ return normalize2.element({
354
354
  ...parts.thumb.attrs,
355
355
  dir: prop("dir"),
356
356
  "data-index": index,
@@ -434,7 +434,7 @@ function connect(service, normalize) {
434
434
  },
435
435
  getHiddenInputProps(props2) {
436
436
  const { index = 0, name } = props2;
437
- return normalize.input({
437
+ return normalize2.input({
438
438
  name: name ?? (prop("name") ? prop("name") + (sliderValue.length > 1 ? "[]" : "") : void 0),
439
439
  form: prop("form"),
440
440
  type: "text",
@@ -444,7 +444,7 @@ function connect(service, normalize) {
444
444
  });
445
445
  },
446
446
  getRangeProps() {
447
- return normalize.element({
447
+ return normalize2.element({
448
448
  id: getRangeId(scope),
449
449
  ...parts.range.attrs,
450
450
  dir: prop("dir"),
@@ -457,7 +457,7 @@ function connect(service, normalize) {
457
457
  });
458
458
  },
459
459
  getControlProps() {
460
- return normalize.element({
460
+ return normalize2.element({
461
461
  ...parts.control.attrs,
462
462
  dir: prop("dir"),
463
463
  id: getControlId(scope),
@@ -479,7 +479,7 @@ function connect(service, normalize) {
479
479
  });
480
480
  },
481
481
  getMarkerGroupProps() {
482
- return normalize.element({
482
+ return normalize2.element({
483
483
  ...parts.markerGroup.attrs,
484
484
  role: "presentation",
485
485
  dir: prop("dir"),
@@ -498,7 +498,7 @@ function connect(service, normalize) {
498
498
  } else {
499
499
  markerState = "at-value";
500
500
  }
501
- return normalize.element({
501
+ return normalize2.element({
502
502
  ...parts.marker.attrs,
503
503
  id: getMarkerId(scope, props2.value),
504
504
  role: "presentation",
@@ -513,7 +513,7 @@ function connect(service, normalize) {
513
513
  getDraggingIndicatorProps(props2) {
514
514
  const { index = 0 } = props2;
515
515
  const isDragging = index === focusedIndex && dragging;
516
- return normalize.element({
516
+ return normalize2.element({
517
517
  ...parts.draggingIndicator.attrs,
518
518
  role: "presentation",
519
519
  dir: prop("dir"),
@@ -528,19 +528,31 @@ function connect(service, normalize) {
528
528
  var isEqualSize = (a, b) => {
529
529
  return a?.width === b?.width && a?.height === b?.height;
530
530
  };
531
+ var normalize = (value, min, max, step) => {
532
+ const ranges = getValueRanges(value, min, max, step);
533
+ return ranges.map((range) => {
534
+ const snapValue = snapValueToStep(range.value, range.min, range.max, step);
535
+ return clampValue(snapValue, range.min, range.max);
536
+ });
537
+ };
531
538
  var machine = createMachine({
532
539
  props({ props: props2 }) {
540
+ const min = props2.min ?? 0;
541
+ const max = props2.max ?? 100;
542
+ const step = props2.step ?? 1;
543
+ const defaultValue = props2.defaultValue ?? [min];
533
544
  return {
534
545
  dir: "ltr",
535
546
  thumbAlignment: "contain",
536
- min: 0,
537
- max: 100,
538
- step: 1,
539
- defaultValue: [0],
540
547
  origin: "start",
541
548
  orientation: "horizontal",
542
549
  minStepsBetweenThumbs: 0,
543
- ...props2
550
+ ...props2,
551
+ defaultValue: normalize(defaultValue, min, max, step),
552
+ value: props2.value ? normalize(props2.value, min, max, step) : void 0,
553
+ max,
554
+ step,
555
+ min
544
556
  };
545
557
  },
546
558
  initialState() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "1.3.3",
3
+ "version": "1.4.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.3.3",
31
- "@zag-js/core": "1.3.3",
32
- "@zag-js/dom-query": "1.3.3",
33
- "@zag-js/utils": "1.3.3",
34
- "@zag-js/types": "1.3.3",
35
- "@zag-js/element-size": "1.3.3"
30
+ "@zag-js/anatomy": "1.4.0",
31
+ "@zag-js/core": "1.4.0",
32
+ "@zag-js/dom-query": "1.4.0",
33
+ "@zag-js/utils": "1.4.0",
34
+ "@zag-js/element-size": "1.4.0",
35
+ "@zag-js/types": "1.4.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "clean-package": "2.2.0"