@zag-js/slider 1.34.0 → 1.35.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 +8 -335
- package/dist/index.d.ts +8 -335
- package/dist/index.js +34 -1055
- package/dist/index.mjs +9 -1049
- package/dist/slider.anatomy.d.mts +6 -0
- package/dist/slider.anatomy.d.ts +6 -0
- package/dist/slider.anatomy.js +45 -0
- package/dist/slider.anatomy.mjs +19 -0
- package/dist/slider.connect.d.mts +7 -0
- package/dist/slider.connect.d.ts +7 -0
- package/dist/slider.connect.js +354 -0
- package/dist/slider.connect.mjs +334 -0
- package/dist/slider.dom.d.mts +30 -0
- package/dist/slider.dom.d.ts +30 -0
- package/dist/slider.dom.js +144 -0
- package/dist/slider.dom.mjs +101 -0
- package/dist/slider.machine.d.mts +7 -0
- package/dist/slider.machine.d.ts +7 -0
- package/dist/slider.machine.js +370 -0
- package/dist/slider.machine.mjs +354 -0
- package/dist/slider.props.d.mts +12 -0
- package/dist/slider.props.d.ts +12 -0
- package/dist/slider.props.js +74 -0
- package/dist/slider.props.mjs +44 -0
- package/dist/slider.style.d.mts +19 -0
- package/dist/slider.style.d.ts +19 -0
- package/dist/slider.style.js +183 -0
- package/dist/slider.style.mjs +150 -0
- package/dist/slider.types.d.mts +320 -0
- package/dist/slider.types.d.ts +320 -0
- package/dist/slider.types.js +18 -0
- package/dist/slider.types.mjs +0 -0
- package/dist/slider.utils.d.mts +25 -0
- package/dist/slider.utils.d.ts +25 -0
- package/dist/slider.utils.js +197 -0
- package/dist/slider.utils.mjs +164 -0
- package/package.json +17 -7
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/slider.style.ts
|
|
21
|
+
var slider_style_exports = {};
|
|
22
|
+
__export(slider_style_exports, {
|
|
23
|
+
getControlStyle: () => getControlStyle,
|
|
24
|
+
getMarkerGroupStyle: () => getMarkerGroupStyle,
|
|
25
|
+
getMarkerStyle: () => getMarkerStyle,
|
|
26
|
+
getRangeOffsets: () => getRangeOffsets,
|
|
27
|
+
getRangeStyle: () => getRangeStyle,
|
|
28
|
+
getRootStyle: () => getRootStyle,
|
|
29
|
+
getThumbOffset: () => getThumbOffset,
|
|
30
|
+
getThumbStyle: () => getThumbStyle,
|
|
31
|
+
getVisibility: () => getVisibility
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(slider_style_exports);
|
|
34
|
+
var import_utils = require("@zag-js/utils");
|
|
35
|
+
function getBounds(value) {
|
|
36
|
+
const firstValue = value[0];
|
|
37
|
+
const lastThumb = value[value.length - 1];
|
|
38
|
+
return [firstValue, lastThumb];
|
|
39
|
+
}
|
|
40
|
+
function getRangeOffsets(params) {
|
|
41
|
+
const { prop, computed } = params;
|
|
42
|
+
const valuePercent = computed("valuePercent");
|
|
43
|
+
const [firstPercent, lastPercent] = getBounds(valuePercent);
|
|
44
|
+
if (valuePercent.length === 1) {
|
|
45
|
+
if (prop("origin") === "center") {
|
|
46
|
+
const isNegative = valuePercent[0] < 50;
|
|
47
|
+
const start = isNegative ? `${valuePercent[0]}%` : "50%";
|
|
48
|
+
const end = isNegative ? "50%" : `${100 - valuePercent[0]}%`;
|
|
49
|
+
return { start, end };
|
|
50
|
+
}
|
|
51
|
+
if (prop("origin") === "end") {
|
|
52
|
+
return { start: `${lastPercent}%`, end: "0%" };
|
|
53
|
+
}
|
|
54
|
+
return { start: "0%", end: `${100 - lastPercent}%` };
|
|
55
|
+
}
|
|
56
|
+
return { start: `${firstPercent}%`, end: `${100 - lastPercent}%` };
|
|
57
|
+
}
|
|
58
|
+
function getRangeStyle(params) {
|
|
59
|
+
const { computed } = params;
|
|
60
|
+
const isVertical = computed("isVertical");
|
|
61
|
+
const isRtl = computed("isRtl");
|
|
62
|
+
if (isVertical) {
|
|
63
|
+
return {
|
|
64
|
+
position: "absolute",
|
|
65
|
+
bottom: "var(--slider-range-start)",
|
|
66
|
+
top: "var(--slider-range-end)"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
position: "absolute",
|
|
71
|
+
[isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
72
|
+
[isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function getVerticalThumbOffset(params, value) {
|
|
76
|
+
const { context, prop } = params;
|
|
77
|
+
const { height = 0 } = context.get("thumbSize") ?? {};
|
|
78
|
+
const getValue = (0, import_utils.getValueTransformer)([prop("min"), prop("max")], [-height / 2, height / 2]);
|
|
79
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
80
|
+
}
|
|
81
|
+
function getHorizontalThumbOffset(params, value) {
|
|
82
|
+
const { computed, context, prop } = params;
|
|
83
|
+
const { width = 0 } = context.get("thumbSize") ?? {};
|
|
84
|
+
const isRtl = computed("isRtl");
|
|
85
|
+
if (isRtl) {
|
|
86
|
+
const getValue2 = (0, import_utils.getValueTransformer)([prop("max"), prop("min")], [-width / 2, width / 2]);
|
|
87
|
+
return -1 * parseFloat(getValue2(value).toFixed(2));
|
|
88
|
+
}
|
|
89
|
+
const getValue = (0, import_utils.getValueTransformer)([prop("min"), prop("max")], [-width / 2, width / 2]);
|
|
90
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
91
|
+
}
|
|
92
|
+
function getOffset(params, percent, value) {
|
|
93
|
+
const { computed, prop } = params;
|
|
94
|
+
if (prop("thumbAlignment") === "center") return `${percent}%`;
|
|
95
|
+
const offset = computed("isVertical") ? getVerticalThumbOffset(params, value) : getHorizontalThumbOffset(params, value);
|
|
96
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
97
|
+
}
|
|
98
|
+
function getThumbOffset(params, value) {
|
|
99
|
+
const { prop } = params;
|
|
100
|
+
const percent = (0, import_utils.getValuePercent)(value, prop("min"), prop("max")) * 100;
|
|
101
|
+
return getOffset(params, percent, value);
|
|
102
|
+
}
|
|
103
|
+
function getVisibility(params) {
|
|
104
|
+
const { computed, prop } = params;
|
|
105
|
+
let visibility = "visible";
|
|
106
|
+
if (prop("thumbAlignment") === "contain" && !computed("hasMeasuredThumbSize")) {
|
|
107
|
+
visibility = "hidden";
|
|
108
|
+
}
|
|
109
|
+
return visibility;
|
|
110
|
+
}
|
|
111
|
+
function getThumbStyle(params, index) {
|
|
112
|
+
const { computed, context } = params;
|
|
113
|
+
const placementProp = computed("isVertical") ? "bottom" : "insetInlineStart";
|
|
114
|
+
const focusedIndex = context.get("focusedIndex");
|
|
115
|
+
return {
|
|
116
|
+
visibility: getVisibility(params),
|
|
117
|
+
position: "absolute",
|
|
118
|
+
transform: "var(--slider-thumb-transform)",
|
|
119
|
+
[placementProp]: `var(--slider-thumb-offset-${index})`,
|
|
120
|
+
zIndex: focusedIndex === index ? 1 : void 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function getControlStyle() {
|
|
124
|
+
return {
|
|
125
|
+
touchAction: "none",
|
|
126
|
+
userSelect: "none",
|
|
127
|
+
WebkitUserSelect: "none",
|
|
128
|
+
position: "relative"
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function getRootStyle(params) {
|
|
132
|
+
const { context, computed } = params;
|
|
133
|
+
const isVertical = computed("isVertical");
|
|
134
|
+
const isRtl = computed("isRtl");
|
|
135
|
+
const range = getRangeOffsets(params);
|
|
136
|
+
const thumbSize = context.get("thumbSize");
|
|
137
|
+
const offsetStyles = context.get("value").reduce((styles, value, index) => {
|
|
138
|
+
const offset = getThumbOffset(params, value);
|
|
139
|
+
return { ...styles, [`--slider-thumb-offset-${index}`]: offset };
|
|
140
|
+
}, {});
|
|
141
|
+
return {
|
|
142
|
+
...offsetStyles,
|
|
143
|
+
"--slider-thumb-width": (0, import_utils.toPx)(thumbSize?.width),
|
|
144
|
+
"--slider-thumb-height": (0, import_utils.toPx)(thumbSize?.height),
|
|
145
|
+
"--slider-thumb-transform": isVertical ? "translateY(50%)" : isRtl ? "translateX(50%)" : "translateX(-50%)",
|
|
146
|
+
"--slider-range-start": range.start,
|
|
147
|
+
"--slider-range-end": range.end
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function getMarkerStyle(params, value) {
|
|
151
|
+
const { computed } = params;
|
|
152
|
+
const isHorizontal = computed("isHorizontal");
|
|
153
|
+
const isRtl = computed("isRtl");
|
|
154
|
+
return {
|
|
155
|
+
visibility: getVisibility(params),
|
|
156
|
+
position: "absolute",
|
|
157
|
+
pointerEvents: "none",
|
|
158
|
+
[isHorizontal ? "insetInlineStart" : "bottom"]: getThumbOffset(params, value),
|
|
159
|
+
translate: "var(--translate-x) var(--translate-y)",
|
|
160
|
+
"--translate-x": isHorizontal ? isRtl ? "50%" : "-50%" : "0%",
|
|
161
|
+
"--translate-y": !isHorizontal ? "50%" : "0%"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function getMarkerGroupStyle() {
|
|
165
|
+
return {
|
|
166
|
+
userSelect: "none",
|
|
167
|
+
WebkitUserSelect: "none",
|
|
168
|
+
pointerEvents: "none",
|
|
169
|
+
position: "relative"
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
173
|
+
0 && (module.exports = {
|
|
174
|
+
getControlStyle,
|
|
175
|
+
getMarkerGroupStyle,
|
|
176
|
+
getMarkerStyle,
|
|
177
|
+
getRangeOffsets,
|
|
178
|
+
getRangeStyle,
|
|
179
|
+
getRootStyle,
|
|
180
|
+
getThumbOffset,
|
|
181
|
+
getThumbStyle,
|
|
182
|
+
getVisibility
|
|
183
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/slider.style.ts
|
|
2
|
+
import { getValuePercent, getValueTransformer, toPx } from "@zag-js/utils";
|
|
3
|
+
function getBounds(value) {
|
|
4
|
+
const firstValue = value[0];
|
|
5
|
+
const lastThumb = value[value.length - 1];
|
|
6
|
+
return [firstValue, lastThumb];
|
|
7
|
+
}
|
|
8
|
+
function getRangeOffsets(params) {
|
|
9
|
+
const { prop, computed } = params;
|
|
10
|
+
const valuePercent = computed("valuePercent");
|
|
11
|
+
const [firstPercent, lastPercent] = getBounds(valuePercent);
|
|
12
|
+
if (valuePercent.length === 1) {
|
|
13
|
+
if (prop("origin") === "center") {
|
|
14
|
+
const isNegative = valuePercent[0] < 50;
|
|
15
|
+
const start = isNegative ? `${valuePercent[0]}%` : "50%";
|
|
16
|
+
const end = isNegative ? "50%" : `${100 - valuePercent[0]}%`;
|
|
17
|
+
return { start, end };
|
|
18
|
+
}
|
|
19
|
+
if (prop("origin") === "end") {
|
|
20
|
+
return { start: `${lastPercent}%`, end: "0%" };
|
|
21
|
+
}
|
|
22
|
+
return { start: "0%", end: `${100 - lastPercent}%` };
|
|
23
|
+
}
|
|
24
|
+
return { start: `${firstPercent}%`, end: `${100 - lastPercent}%` };
|
|
25
|
+
}
|
|
26
|
+
function getRangeStyle(params) {
|
|
27
|
+
const { computed } = params;
|
|
28
|
+
const isVertical = computed("isVertical");
|
|
29
|
+
const isRtl = computed("isRtl");
|
|
30
|
+
if (isVertical) {
|
|
31
|
+
return {
|
|
32
|
+
position: "absolute",
|
|
33
|
+
bottom: "var(--slider-range-start)",
|
|
34
|
+
top: "var(--slider-range-end)"
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
position: "absolute",
|
|
39
|
+
[isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
40
|
+
[isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getVerticalThumbOffset(params, value) {
|
|
44
|
+
const { context, prop } = params;
|
|
45
|
+
const { height = 0 } = context.get("thumbSize") ?? {};
|
|
46
|
+
const getValue = getValueTransformer([prop("min"), prop("max")], [-height / 2, height / 2]);
|
|
47
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
48
|
+
}
|
|
49
|
+
function getHorizontalThumbOffset(params, value) {
|
|
50
|
+
const { computed, context, prop } = params;
|
|
51
|
+
const { width = 0 } = context.get("thumbSize") ?? {};
|
|
52
|
+
const isRtl = computed("isRtl");
|
|
53
|
+
if (isRtl) {
|
|
54
|
+
const getValue2 = getValueTransformer([prop("max"), prop("min")], [-width / 2, width / 2]);
|
|
55
|
+
return -1 * parseFloat(getValue2(value).toFixed(2));
|
|
56
|
+
}
|
|
57
|
+
const getValue = getValueTransformer([prop("min"), prop("max")], [-width / 2, width / 2]);
|
|
58
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
59
|
+
}
|
|
60
|
+
function getOffset(params, percent, value) {
|
|
61
|
+
const { computed, prop } = params;
|
|
62
|
+
if (prop("thumbAlignment") === "center") return `${percent}%`;
|
|
63
|
+
const offset = computed("isVertical") ? getVerticalThumbOffset(params, value) : getHorizontalThumbOffset(params, value);
|
|
64
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
65
|
+
}
|
|
66
|
+
function getThumbOffset(params, value) {
|
|
67
|
+
const { prop } = params;
|
|
68
|
+
const percent = getValuePercent(value, prop("min"), prop("max")) * 100;
|
|
69
|
+
return getOffset(params, percent, value);
|
|
70
|
+
}
|
|
71
|
+
function getVisibility(params) {
|
|
72
|
+
const { computed, prop } = params;
|
|
73
|
+
let visibility = "visible";
|
|
74
|
+
if (prop("thumbAlignment") === "contain" && !computed("hasMeasuredThumbSize")) {
|
|
75
|
+
visibility = "hidden";
|
|
76
|
+
}
|
|
77
|
+
return visibility;
|
|
78
|
+
}
|
|
79
|
+
function getThumbStyle(params, index) {
|
|
80
|
+
const { computed, context } = params;
|
|
81
|
+
const placementProp = computed("isVertical") ? "bottom" : "insetInlineStart";
|
|
82
|
+
const focusedIndex = context.get("focusedIndex");
|
|
83
|
+
return {
|
|
84
|
+
visibility: getVisibility(params),
|
|
85
|
+
position: "absolute",
|
|
86
|
+
transform: "var(--slider-thumb-transform)",
|
|
87
|
+
[placementProp]: `var(--slider-thumb-offset-${index})`,
|
|
88
|
+
zIndex: focusedIndex === index ? 1 : void 0
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getControlStyle() {
|
|
92
|
+
return {
|
|
93
|
+
touchAction: "none",
|
|
94
|
+
userSelect: "none",
|
|
95
|
+
WebkitUserSelect: "none",
|
|
96
|
+
position: "relative"
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function getRootStyle(params) {
|
|
100
|
+
const { context, computed } = params;
|
|
101
|
+
const isVertical = computed("isVertical");
|
|
102
|
+
const isRtl = computed("isRtl");
|
|
103
|
+
const range = getRangeOffsets(params);
|
|
104
|
+
const thumbSize = context.get("thumbSize");
|
|
105
|
+
const offsetStyles = context.get("value").reduce((styles, value, index) => {
|
|
106
|
+
const offset = getThumbOffset(params, value);
|
|
107
|
+
return { ...styles, [`--slider-thumb-offset-${index}`]: offset };
|
|
108
|
+
}, {});
|
|
109
|
+
return {
|
|
110
|
+
...offsetStyles,
|
|
111
|
+
"--slider-thumb-width": toPx(thumbSize?.width),
|
|
112
|
+
"--slider-thumb-height": toPx(thumbSize?.height),
|
|
113
|
+
"--slider-thumb-transform": isVertical ? "translateY(50%)" : isRtl ? "translateX(50%)" : "translateX(-50%)",
|
|
114
|
+
"--slider-range-start": range.start,
|
|
115
|
+
"--slider-range-end": range.end
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function getMarkerStyle(params, value) {
|
|
119
|
+
const { computed } = params;
|
|
120
|
+
const isHorizontal = computed("isHorizontal");
|
|
121
|
+
const isRtl = computed("isRtl");
|
|
122
|
+
return {
|
|
123
|
+
visibility: getVisibility(params),
|
|
124
|
+
position: "absolute",
|
|
125
|
+
pointerEvents: "none",
|
|
126
|
+
[isHorizontal ? "insetInlineStart" : "bottom"]: getThumbOffset(params, value),
|
|
127
|
+
translate: "var(--translate-x) var(--translate-y)",
|
|
128
|
+
"--translate-x": isHorizontal ? isRtl ? "50%" : "-50%" : "0%",
|
|
129
|
+
"--translate-y": !isHorizontal ? "50%" : "0%"
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function getMarkerGroupStyle() {
|
|
133
|
+
return {
|
|
134
|
+
userSelect: "none",
|
|
135
|
+
WebkitUserSelect: "none",
|
|
136
|
+
pointerEvents: "none",
|
|
137
|
+
position: "relative"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
+
getControlStyle,
|
|
142
|
+
getMarkerGroupStyle,
|
|
143
|
+
getMarkerStyle,
|
|
144
|
+
getRangeOffsets,
|
|
145
|
+
getRangeStyle,
|
|
146
|
+
getRootStyle,
|
|
147
|
+
getThumbOffset,
|
|
148
|
+
getThumbStyle,
|
|
149
|
+
getVisibility
|
|
150
|
+
};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { Machine, EventObject, Service } from '@zag-js/core';
|
|
2
|
+
import { PropTypes, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types';
|
|
3
|
+
|
|
4
|
+
type ThumbCollisionBehavior = "none" | "push" | "swap";
|
|
5
|
+
type ThumbAlignment = "contain" | "center";
|
|
6
|
+
interface ValueChangeDetails {
|
|
7
|
+
value: number[];
|
|
8
|
+
}
|
|
9
|
+
interface FocusChangeDetails {
|
|
10
|
+
focusedIndex: number;
|
|
11
|
+
value: number[];
|
|
12
|
+
}
|
|
13
|
+
interface ValueTextDetails {
|
|
14
|
+
value: number;
|
|
15
|
+
index: number;
|
|
16
|
+
}
|
|
17
|
+
type ElementIds = Partial<{
|
|
18
|
+
root: string;
|
|
19
|
+
thumb: (index: number) => string;
|
|
20
|
+
hiddenInput: (index: number) => string;
|
|
21
|
+
control: string;
|
|
22
|
+
track: string;
|
|
23
|
+
range: string;
|
|
24
|
+
label: string;
|
|
25
|
+
valueText: string;
|
|
26
|
+
marker: (index: number) => string;
|
|
27
|
+
}>;
|
|
28
|
+
interface SliderProps extends DirectionProperty, CommonProperties {
|
|
29
|
+
/**
|
|
30
|
+
* The ids of the elements in the slider. Useful for composition.
|
|
31
|
+
*/
|
|
32
|
+
ids?: ElementIds | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The aria-label of each slider thumb. Useful for providing an accessible name to the slider
|
|
35
|
+
*/
|
|
36
|
+
"aria-label"?: string[] | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The `id` of the elements that labels each slider thumb. Useful for providing an accessible name to the slider
|
|
39
|
+
*/
|
|
40
|
+
"aria-labelledby"?: string[] | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The name associated with each slider thumb (when used in a form)
|
|
43
|
+
*/
|
|
44
|
+
name?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The associate form of the underlying input element.
|
|
47
|
+
*/
|
|
48
|
+
form?: string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The controlled value of the slider
|
|
51
|
+
*/
|
|
52
|
+
value?: number[] | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* The initial value of the slider when rendered.
|
|
55
|
+
* Use when you don't need to control the value of the slider.
|
|
56
|
+
*/
|
|
57
|
+
defaultValue?: number[] | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the slider is disabled
|
|
60
|
+
*/
|
|
61
|
+
disabled?: boolean | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the slider is read-only
|
|
64
|
+
*/
|
|
65
|
+
readOnly?: boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the slider is invalid
|
|
68
|
+
*/
|
|
69
|
+
invalid?: boolean | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Function invoked when the value of the slider changes
|
|
72
|
+
*/
|
|
73
|
+
onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Function invoked when the slider value change is done
|
|
76
|
+
*/
|
|
77
|
+
onValueChangeEnd?: ((details: ValueChangeDetails) => void) | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Function invoked when the slider's focused index changes
|
|
80
|
+
*/
|
|
81
|
+
onFocusChange?: ((details: FocusChangeDetails) => void) | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Function that returns a human readable value for the slider thumb
|
|
84
|
+
*/
|
|
85
|
+
getAriaValueText?: ((details: ValueTextDetails) => string) | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* The minimum value of the slider
|
|
88
|
+
* @default 0
|
|
89
|
+
*/
|
|
90
|
+
min?: number | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The maximum value of the slider
|
|
93
|
+
* @default 100
|
|
94
|
+
*/
|
|
95
|
+
max?: number | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The step value of the slider
|
|
98
|
+
* @default 1
|
|
99
|
+
*/
|
|
100
|
+
step?: number | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* The minimum permitted steps between multiple thumbs.
|
|
103
|
+
*
|
|
104
|
+
* `minStepsBetweenThumbs` * `step` should reflect the gap between the thumbs.
|
|
105
|
+
*
|
|
106
|
+
* - `step: 1` and `minStepsBetweenThumbs: 10` => gap is `10`
|
|
107
|
+
* - `step: 10` and `minStepsBetweenThumbs: 2` => gap is `20`
|
|
108
|
+
*
|
|
109
|
+
* @default 0
|
|
110
|
+
*/
|
|
111
|
+
minStepsBetweenThumbs?: number | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* The orientation of the slider
|
|
114
|
+
* @default "horizontal"
|
|
115
|
+
*/
|
|
116
|
+
orientation?: "vertical" | "horizontal" | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The origin of the slider range. The track is filled from the origin
|
|
119
|
+
* to the thumb for single values.
|
|
120
|
+
* - "start": Useful when the value represents an absolute value
|
|
121
|
+
* - "center": Useful when the value represents an offset (relative)
|
|
122
|
+
* - "end": Useful when the value represents an offset from the end
|
|
123
|
+
*
|
|
124
|
+
* @default "start"
|
|
125
|
+
*/
|
|
126
|
+
origin?: "start" | "center" | "end" | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* The alignment of the slider thumb relative to the track
|
|
129
|
+
* - `center`: the thumb will extend beyond the bounds of the slider track.
|
|
130
|
+
* - `contain`: the thumb will be contained within the bounds of the track.
|
|
131
|
+
*
|
|
132
|
+
* @default "contain"
|
|
133
|
+
*/
|
|
134
|
+
thumbAlignment?: "contain" | "center" | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* The slider thumbs dimensions
|
|
137
|
+
*/
|
|
138
|
+
thumbSize?: {
|
|
139
|
+
width: number;
|
|
140
|
+
height: number;
|
|
141
|
+
} | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Controls how thumbs behave when they collide during pointer interactions.
|
|
144
|
+
* - `none` (default): Thumbs cannot move past each other; excess movement is ignored.
|
|
145
|
+
* - `push`: Thumbs push each other without restoring their previous positions when dragged back.
|
|
146
|
+
* - `swap`: Thumbs swap places when dragged past each other.
|
|
147
|
+
*
|
|
148
|
+
* @default "none"
|
|
149
|
+
*/
|
|
150
|
+
thumbCollisionBehavior?: "none" | "push" | "swap" | undefined;
|
|
151
|
+
}
|
|
152
|
+
type PropsWithDefault = "dir" | "min" | "max" | "step" | "orientation" | "defaultValue" | "origin" | "thumbAlignment" | "minStepsBetweenThumbs" | "thumbCollisionBehavior";
|
|
153
|
+
type Computed = Readonly<{
|
|
154
|
+
/**
|
|
155
|
+
* @computed
|
|
156
|
+
* Whether the slider thumb has been measured
|
|
157
|
+
*/
|
|
158
|
+
hasMeasuredThumbSize: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* @computed
|
|
161
|
+
* Whether the slider is interactive
|
|
162
|
+
*/
|
|
163
|
+
isInteractive: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* @computed
|
|
166
|
+
* Whether the slider is vertical
|
|
167
|
+
*/
|
|
168
|
+
isVertical: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* @computed
|
|
171
|
+
* Whether the slider is horizontal
|
|
172
|
+
*/
|
|
173
|
+
isHorizontal: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* @computed
|
|
176
|
+
* Whether the slider is in RTL mode
|
|
177
|
+
*/
|
|
178
|
+
isRtl: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* @computed
|
|
181
|
+
* The percentage of the slider value relative to the slider min/max
|
|
182
|
+
*/
|
|
183
|
+
valuePercent: number[];
|
|
184
|
+
/**
|
|
185
|
+
* @computed
|
|
186
|
+
* Whether the slider is disabled
|
|
187
|
+
*/
|
|
188
|
+
isDisabled: boolean;
|
|
189
|
+
}>;
|
|
190
|
+
interface Context {
|
|
191
|
+
/**
|
|
192
|
+
* The active index of the range slider. This represents
|
|
193
|
+
* the currently dragged/focused thumb.
|
|
194
|
+
*/
|
|
195
|
+
focusedIndex: number;
|
|
196
|
+
/**
|
|
197
|
+
* The value of the range slider
|
|
198
|
+
*/
|
|
199
|
+
value: number[];
|
|
200
|
+
/**
|
|
201
|
+
* The size of the slider thumbs
|
|
202
|
+
*/
|
|
203
|
+
thumbSize: Size | null;
|
|
204
|
+
}
|
|
205
|
+
interface SliderSchema {
|
|
206
|
+
state: "idle" | "dragging" | "focus";
|
|
207
|
+
props: RequiredBy<SliderProps, PropsWithDefault>;
|
|
208
|
+
context: Context;
|
|
209
|
+
refs: {
|
|
210
|
+
/**
|
|
211
|
+
* The offset from the thumb center when pointer down occurs.
|
|
212
|
+
* Used to maintain constant offset during drag.
|
|
213
|
+
*/
|
|
214
|
+
thumbDragOffset: {
|
|
215
|
+
x: number;
|
|
216
|
+
y: number;
|
|
217
|
+
} | null;
|
|
218
|
+
/**
|
|
219
|
+
* The values when a thumb drag starts.
|
|
220
|
+
* Used for swap collision behavior to determine swap direction.
|
|
221
|
+
*/
|
|
222
|
+
thumbDragStartValue: number[] | null;
|
|
223
|
+
};
|
|
224
|
+
computed: Computed;
|
|
225
|
+
event: EventObject;
|
|
226
|
+
action: string;
|
|
227
|
+
effect: string;
|
|
228
|
+
guard: string;
|
|
229
|
+
}
|
|
230
|
+
type SliderService = Service<SliderSchema>;
|
|
231
|
+
type SliderMachine = Machine<SliderSchema>;
|
|
232
|
+
interface Size {
|
|
233
|
+
width: number;
|
|
234
|
+
height: number;
|
|
235
|
+
}
|
|
236
|
+
interface MarkerProps {
|
|
237
|
+
value: number;
|
|
238
|
+
}
|
|
239
|
+
interface ThumbProps {
|
|
240
|
+
index: number;
|
|
241
|
+
name?: string | undefined;
|
|
242
|
+
}
|
|
243
|
+
interface DraggingIndicatorProps {
|
|
244
|
+
index: number;
|
|
245
|
+
}
|
|
246
|
+
interface SliderApi<T extends PropTypes = PropTypes> {
|
|
247
|
+
/**
|
|
248
|
+
* The value of the slider.
|
|
249
|
+
*/
|
|
250
|
+
value: number[];
|
|
251
|
+
/**
|
|
252
|
+
* Whether the slider is being dragged.
|
|
253
|
+
*/
|
|
254
|
+
dragging: boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Whether the slider is focused.
|
|
257
|
+
*/
|
|
258
|
+
focused: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Function to set the value of the slider.
|
|
261
|
+
*/
|
|
262
|
+
setValue: (value: number[]) => void;
|
|
263
|
+
/**
|
|
264
|
+
* Returns the value of the thumb at the given index.
|
|
265
|
+
*/
|
|
266
|
+
getThumbValue: (index: number) => number;
|
|
267
|
+
/**
|
|
268
|
+
* Sets the value of the thumb at the given index.
|
|
269
|
+
*/
|
|
270
|
+
setThumbValue: (index: number, value: number) => void;
|
|
271
|
+
/**
|
|
272
|
+
* Returns the percent of the thumb at the given index.
|
|
273
|
+
*/
|
|
274
|
+
getValuePercent: (value: number) => number;
|
|
275
|
+
/**
|
|
276
|
+
* Returns the value of the thumb at the given percent.
|
|
277
|
+
*/
|
|
278
|
+
getPercentValue: (percent: number) => number;
|
|
279
|
+
/**
|
|
280
|
+
* Returns the percent of the thumb at the given index.
|
|
281
|
+
*/
|
|
282
|
+
getThumbPercent: (index: number) => number;
|
|
283
|
+
/**
|
|
284
|
+
* Sets the percent of the thumb at the given index.
|
|
285
|
+
*/
|
|
286
|
+
setThumbPercent: (index: number, percent: number) => void;
|
|
287
|
+
/**
|
|
288
|
+
* Returns the min value of the thumb at the given index.
|
|
289
|
+
*/
|
|
290
|
+
getThumbMin: (index: number) => number;
|
|
291
|
+
/**
|
|
292
|
+
* Returns the max value of the thumb at the given index.
|
|
293
|
+
*/
|
|
294
|
+
getThumbMax: (index: number) => number;
|
|
295
|
+
/**
|
|
296
|
+
* Function to increment the value of the slider at the given index.
|
|
297
|
+
*/
|
|
298
|
+
increment: (index: number) => void;
|
|
299
|
+
/**
|
|
300
|
+
* Function to decrement the value of the slider at the given index.
|
|
301
|
+
*/
|
|
302
|
+
decrement: (index: number) => void;
|
|
303
|
+
/**
|
|
304
|
+
* Function to focus the slider. This focuses the first thumb.
|
|
305
|
+
*/
|
|
306
|
+
focus: VoidFunction;
|
|
307
|
+
getLabelProps: () => T["label"];
|
|
308
|
+
getRootProps: () => T["element"];
|
|
309
|
+
getValueTextProps: () => T["element"];
|
|
310
|
+
getTrackProps: () => T["element"];
|
|
311
|
+
getThumbProps: (props: ThumbProps) => T["element"];
|
|
312
|
+
getHiddenInputProps: (props: ThumbProps) => T["input"];
|
|
313
|
+
getRangeProps: () => T["element"];
|
|
314
|
+
getControlProps: () => T["element"];
|
|
315
|
+
getMarkerGroupProps: () => T["element"];
|
|
316
|
+
getMarkerProps: (props: MarkerProps) => T["element"];
|
|
317
|
+
getDraggingIndicatorProps: (props: DraggingIndicatorProps) => T["element"];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export type { DraggingIndicatorProps, ElementIds, FocusChangeDetails, MarkerProps, SliderApi, SliderMachine, SliderProps, SliderSchema, SliderService, ThumbAlignment, ThumbCollisionBehavior, ThumbProps, ValueChangeDetails, ValueTextDetails };
|