@zag-js/slider 0.24.0 → 0.26.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 +103 -143
- package/dist/index.d.ts +103 -143
- package/dist/index.js +417 -281
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +424 -280
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -11
- package/src/index.ts +1 -2
- package/src/slider.anatomy.ts +1 -0
- package/src/slider.connect.ts +182 -141
- package/src/slider.dom.ts +23 -20
- package/src/slider.machine.ts +144 -72
- package/src/slider.style.ts +57 -58
- package/src/slider.types.ts +105 -76
- package/src/slider.utils.ts +48 -15
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
-
import * as _zag_js_types from '@zag-js/types';
|
|
3
2
|
import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
|
|
4
3
|
import * as _zag_js_core from '@zag-js/core';
|
|
5
4
|
import { StateMachine } from '@zag-js/core';
|
|
@@ -7,35 +6,47 @@ import { StateMachine } from '@zag-js/core';
|
|
|
7
6
|
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "thumb" | "output" | "track" | "range" | "control" | "markerGroup" | "marker">;
|
|
8
7
|
|
|
9
8
|
interface ValueChangeDetails {
|
|
10
|
-
value: number;
|
|
9
|
+
value: number[];
|
|
10
|
+
}
|
|
11
|
+
interface FocusChangeDetails {
|
|
12
|
+
focusedIndex: number;
|
|
13
|
+
value: number[];
|
|
11
14
|
}
|
|
12
15
|
type ElementIds = Partial<{
|
|
13
16
|
root: string;
|
|
14
|
-
thumb: string;
|
|
17
|
+
thumb(index: number): string;
|
|
15
18
|
control: string;
|
|
16
19
|
track: string;
|
|
17
20
|
range: string;
|
|
18
21
|
label: string;
|
|
19
22
|
output: string;
|
|
20
|
-
|
|
23
|
+
marker(index: number): string;
|
|
21
24
|
}>;
|
|
22
25
|
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
23
26
|
/**
|
|
24
|
-
* The ids of the elements in the slider. Useful for composition.
|
|
27
|
+
* The ids of the elements in the range slider. Useful for composition.
|
|
25
28
|
*/
|
|
26
29
|
ids?: ElementIds;
|
|
27
30
|
/**
|
|
28
|
-
* The
|
|
31
|
+
* The aria-label of each slider thumb. Useful for providing an accessible name to the slider
|
|
29
32
|
*/
|
|
30
|
-
|
|
33
|
+
"aria-label"?: string[];
|
|
31
34
|
/**
|
|
32
|
-
* The
|
|
35
|
+
* The `id` of the elements that labels each slider thumb. Useful for providing an accessible name to the slider
|
|
36
|
+
*/
|
|
37
|
+
"aria-labelledby"?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* The name associated with each slider thumb (when used in a form)
|
|
33
40
|
*/
|
|
34
41
|
name?: string;
|
|
35
42
|
/**
|
|
36
43
|
* The associate form of the underlying input element.
|
|
37
44
|
*/
|
|
38
45
|
form?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The value of the range slider
|
|
48
|
+
*/
|
|
49
|
+
value: number[];
|
|
39
50
|
/**
|
|
40
51
|
* Whether the slider is disabled
|
|
41
52
|
*/
|
|
@@ -45,58 +56,50 @@ interface PublicContext extends DirectionProperty, CommonProperties {
|
|
|
45
56
|
*/
|
|
46
57
|
readOnly?: boolean;
|
|
47
58
|
/**
|
|
48
|
-
* Whether the slider
|
|
59
|
+
* Whether the slider is invalid
|
|
49
60
|
*/
|
|
50
61
|
invalid?: boolean;
|
|
51
62
|
/**
|
|
52
|
-
*
|
|
53
|
-
*/
|
|
54
|
-
min: number;
|
|
55
|
-
/**
|
|
56
|
-
* The maximum value of the slider
|
|
63
|
+
* Function invoked when the value of the slider changes
|
|
57
64
|
*/
|
|
58
|
-
|
|
65
|
+
onValueChange?(details: ValueChangeDetails): void;
|
|
59
66
|
/**
|
|
60
|
-
*
|
|
67
|
+
* Function invoked when the slider value change is done
|
|
61
68
|
*/
|
|
62
|
-
|
|
69
|
+
onValueChangeEnd?(details: ValueChangeDetails): void;
|
|
63
70
|
/**
|
|
64
|
-
*
|
|
71
|
+
* Function invoked when the slider's focused index changes
|
|
65
72
|
*/
|
|
66
|
-
|
|
73
|
+
onFocusChange?(details: FocusChangeDetails): void;
|
|
67
74
|
/**
|
|
68
|
-
*
|
|
69
|
-
* - "center": Useful when the value represents an offset (relative)
|
|
75
|
+
* Function that returns a human readable value for the slider thumb
|
|
70
76
|
*/
|
|
71
|
-
|
|
77
|
+
getAriaValueText?(value: number, index: number): string;
|
|
72
78
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*/
|
|
75
|
-
"aria-label"?: string;
|
|
76
|
-
/**
|
|
77
|
-
* The `id` of the element that labels the slider. Useful for providing an accessible name to the slider
|
|
79
|
+
* The minimum value of the slider
|
|
78
80
|
*/
|
|
79
|
-
|
|
81
|
+
min: number;
|
|
80
82
|
/**
|
|
81
|
-
*
|
|
83
|
+
* The maximum value of the slider
|
|
82
84
|
*/
|
|
83
|
-
|
|
85
|
+
max: number;
|
|
84
86
|
/**
|
|
85
|
-
*
|
|
87
|
+
* The step value of the slider
|
|
86
88
|
*/
|
|
87
|
-
|
|
89
|
+
step: number;
|
|
88
90
|
/**
|
|
89
|
-
*
|
|
91
|
+
* The minimum permitted steps between multiple thumbs.
|
|
90
92
|
*/
|
|
91
|
-
|
|
93
|
+
minStepsBetweenThumbs: number;
|
|
92
94
|
/**
|
|
93
|
-
*
|
|
95
|
+
* The orientation of the slider
|
|
94
96
|
*/
|
|
95
|
-
|
|
97
|
+
orientation: "vertical" | "horizontal";
|
|
96
98
|
/**
|
|
97
|
-
*
|
|
99
|
+
* - "start": Useful when the value represents an absolute value
|
|
100
|
+
* - "center": Useful when the value represents an offset (relative)
|
|
98
101
|
*/
|
|
99
|
-
|
|
102
|
+
origin?: "start" | "center";
|
|
100
103
|
/**
|
|
101
104
|
* The alignment of the slider thumb relative to the track
|
|
102
105
|
* - `center`: the thumb will extend beyond the bounds of the slider track.
|
|
@@ -104,32 +107,40 @@ interface PublicContext extends DirectionProperty, CommonProperties {
|
|
|
104
107
|
*/
|
|
105
108
|
thumbAlignment?: "contain" | "center";
|
|
106
109
|
/**
|
|
107
|
-
* The slider
|
|
110
|
+
* The slider thumbs dimensions
|
|
108
111
|
*/
|
|
109
|
-
thumbSize:
|
|
112
|
+
thumbSize: {
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
} | null;
|
|
110
116
|
}
|
|
111
117
|
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
112
118
|
type ComputedContext = Readonly<{
|
|
113
119
|
/**
|
|
114
120
|
* @computed
|
|
115
|
-
* Whether the slider
|
|
121
|
+
* Whether the slider thumb has been measured
|
|
116
122
|
*/
|
|
117
|
-
|
|
123
|
+
hasMeasuredThumbSize: boolean;
|
|
118
124
|
/**
|
|
119
125
|
* @computed
|
|
120
|
-
* Whether the
|
|
126
|
+
* Whether the slider is interactive
|
|
121
127
|
*/
|
|
122
|
-
|
|
128
|
+
isInteractive: boolean;
|
|
123
129
|
/**
|
|
124
130
|
* @computed
|
|
125
|
-
*
|
|
131
|
+
* The raw value of the space between each thumb
|
|
126
132
|
*/
|
|
127
|
-
|
|
133
|
+
spacing: number;
|
|
128
134
|
/**
|
|
129
135
|
* @computed
|
|
130
136
|
* Whether the slider is vertical
|
|
131
137
|
*/
|
|
132
138
|
isVertical: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* @computed
|
|
141
|
+
* Whether the slider is horizontal
|
|
142
|
+
*/
|
|
143
|
+
isHorizontal: boolean;
|
|
133
144
|
/**
|
|
134
145
|
* @computed
|
|
135
146
|
* Whether the slider is in RTL mode
|
|
@@ -137,9 +148,9 @@ type ComputedContext = Readonly<{
|
|
|
137
148
|
isRtl: boolean;
|
|
138
149
|
/**
|
|
139
150
|
* @computed
|
|
140
|
-
* The
|
|
151
|
+
* The percentage of the slider value relative to the slider min/max
|
|
141
152
|
*/
|
|
142
|
-
valuePercent: number;
|
|
153
|
+
valuePercent: number[];
|
|
143
154
|
/**
|
|
144
155
|
* @computed
|
|
145
156
|
* Whether the slider is disabled
|
|
@@ -154,138 +165,87 @@ interface MachineState {
|
|
|
154
165
|
}
|
|
155
166
|
type State = StateMachine.State<MachineContext, MachineState>;
|
|
156
167
|
type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
157
|
-
interface Point {
|
|
158
|
-
x: number;
|
|
159
|
-
y: number;
|
|
160
|
-
}
|
|
161
|
-
interface Size {
|
|
162
|
-
width: number;
|
|
163
|
-
height: number;
|
|
164
|
-
}
|
|
165
168
|
interface MarkerProps {
|
|
166
169
|
value: number;
|
|
167
170
|
}
|
|
171
|
+
interface ThumbProps {
|
|
172
|
+
index: number;
|
|
173
|
+
}
|
|
168
174
|
interface MachineApi<T extends PropTypes = PropTypes> {
|
|
169
175
|
/**
|
|
170
|
-
*
|
|
176
|
+
* The value of the slider.
|
|
171
177
|
*/
|
|
172
|
-
|
|
178
|
+
value: number[];
|
|
173
179
|
/**
|
|
174
180
|
* Whether the slider is being dragged.
|
|
175
181
|
*/
|
|
176
182
|
isDragging: boolean;
|
|
177
183
|
/**
|
|
178
|
-
*
|
|
184
|
+
* Whether the slider is focused.
|
|
179
185
|
*/
|
|
180
|
-
|
|
186
|
+
isFocused: boolean;
|
|
181
187
|
/**
|
|
182
|
-
*
|
|
188
|
+
* Function to set the value of the slider.
|
|
183
189
|
*/
|
|
184
|
-
|
|
190
|
+
setValue(value: number[]): void;
|
|
185
191
|
/**
|
|
186
|
-
*
|
|
192
|
+
* Returns the value of the thumb at the given index.
|
|
187
193
|
*/
|
|
188
|
-
|
|
194
|
+
getThumbValue(index: number): number;
|
|
189
195
|
/**
|
|
190
|
-
*
|
|
196
|
+
* Sets the value of the thumb at the given index.
|
|
191
197
|
*/
|
|
192
|
-
|
|
198
|
+
setThumbValue(index: number, value: number): void;
|
|
193
199
|
/**
|
|
194
|
-
* Returns the percent of the
|
|
200
|
+
* Returns the percent of the thumb at the given index.
|
|
195
201
|
*/
|
|
196
202
|
getValuePercent: (value: number) => number;
|
|
197
203
|
/**
|
|
198
|
-
*
|
|
204
|
+
* Returns the value of the thumb at the given percent.
|
|
199
205
|
*/
|
|
200
|
-
|
|
206
|
+
getPercentValue: (percent: number) => number;
|
|
201
207
|
/**
|
|
202
|
-
*
|
|
208
|
+
* Returns the percent of the thumb at the given index.
|
|
203
209
|
*/
|
|
204
|
-
|
|
210
|
+
getThumbPercent(index: number): number;
|
|
205
211
|
/**
|
|
206
|
-
*
|
|
212
|
+
* Sets the percent of the thumb at the given index.
|
|
207
213
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
214
|
+
setThumbPercent(index: number, percent: number): void;
|
|
215
|
+
/**
|
|
216
|
+
* Returns the min value of the thumb at the given index.
|
|
217
|
+
*/
|
|
218
|
+
getThumbMin(index: number): number;
|
|
219
|
+
/**
|
|
220
|
+
* Returns the max value of the thumb at the given index.
|
|
221
|
+
*/
|
|
222
|
+
getThumbMax(index: number): number;
|
|
223
|
+
/**
|
|
224
|
+
* Function to increment the value of the slider at the given index.
|
|
225
|
+
*/
|
|
226
|
+
increment(index: number): void;
|
|
227
|
+
/**
|
|
228
|
+
* Function to decrement the value of the slider at the given index.
|
|
229
|
+
*/
|
|
230
|
+
decrement(index: number): void;
|
|
231
|
+
/**
|
|
232
|
+
* Function to focus the slider. This focuses the first thumb.
|
|
233
|
+
*/
|
|
234
|
+
focus(): void;
|
|
210
235
|
labelProps: T["label"];
|
|
211
|
-
|
|
212
|
-
hiddenInputProps: T["input"];
|
|
236
|
+
rootProps: T["element"];
|
|
213
237
|
outputProps: T["output"];
|
|
214
238
|
trackProps: T["element"];
|
|
239
|
+
getThumbProps(props: ThumbProps): T["element"];
|
|
240
|
+
getHiddenInputProps(props: ThumbProps): T["input"];
|
|
215
241
|
rangeProps: T["element"];
|
|
216
242
|
controlProps: T["element"];
|
|
217
243
|
markerGroupProps: T["element"];
|
|
218
244
|
getMarkerProps(props: MarkerProps): T["element"];
|
|
219
245
|
}
|
|
220
|
-
interface SharedContext {
|
|
221
|
-
min: number;
|
|
222
|
-
max: number;
|
|
223
|
-
step: number;
|
|
224
|
-
dir?: "ltr" | "rtl";
|
|
225
|
-
isRtl: boolean;
|
|
226
|
-
isVertical: boolean;
|
|
227
|
-
isHorizontal: boolean;
|
|
228
|
-
value: number;
|
|
229
|
-
thumbSize: Size | null;
|
|
230
|
-
thumbAlignment?: "contain" | "center";
|
|
231
|
-
orientation?: "horizontal" | "vertical";
|
|
232
|
-
readonly hasMeasuredThumbSize: boolean;
|
|
233
|
-
}
|
|
234
246
|
|
|
235
247
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
236
248
|
|
|
237
|
-
declare const dom: {
|
|
238
|
-
getRootNode: (ctx: {
|
|
239
|
-
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
240
|
-
}) => Document | ShadowRoot;
|
|
241
|
-
getDoc: (ctx: {
|
|
242
|
-
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
243
|
-
}) => Document;
|
|
244
|
-
getWin: (ctx: {
|
|
245
|
-
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
246
|
-
}) => Window & typeof globalThis;
|
|
247
|
-
getActiveElement: (ctx: {
|
|
248
|
-
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
249
|
-
}) => HTMLElement | null;
|
|
250
|
-
isActiveElement: (ctx: {
|
|
251
|
-
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
252
|
-
}, elem: HTMLElement | null) => boolean;
|
|
253
|
-
focus(ctx: {
|
|
254
|
-
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
255
|
-
}, elem: HTMLElement | null | undefined): void;
|
|
256
|
-
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
257
|
-
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
258
|
-
}, id: string) => T | null;
|
|
259
|
-
setValue: <T_1 extends {
|
|
260
|
-
value: string;
|
|
261
|
-
}>(elem: T_1 | null, value: string | number | null | undefined) => void;
|
|
262
|
-
} & {
|
|
263
|
-
getRootId: (ctx: MachineContext) => string;
|
|
264
|
-
getThumbId: (ctx: MachineContext) => string;
|
|
265
|
-
getControlId: (ctx: MachineContext) => string;
|
|
266
|
-
getHiddenInputId: (ctx: MachineContext) => string;
|
|
267
|
-
getOutputId: (ctx: MachineContext) => string;
|
|
268
|
-
getTrackId: (ctx: MachineContext) => string;
|
|
269
|
-
getRangeId: (ctx: MachineContext) => string;
|
|
270
|
-
getLabelId: (ctx: MachineContext) => string;
|
|
271
|
-
getMarkerId: (ctx: MachineContext, value: number) => string;
|
|
272
|
-
getRootEl: (ctx: MachineContext) => HTMLElement | null;
|
|
273
|
-
getThumbEl: (ctx: MachineContext) => HTMLElement | null;
|
|
274
|
-
getControlEl: (ctx: MachineContext) => HTMLElement | null;
|
|
275
|
-
getHiddenInputEl: (ctx: MachineContext) => HTMLInputElement | null;
|
|
276
|
-
getValueFromPoint(ctx: MachineContext, point: Point): number | undefined;
|
|
277
|
-
dispatchChangeEvent(ctx: MachineContext): void;
|
|
278
|
-
getThumbOffset: (ctx: SharedContext) => string;
|
|
279
|
-
getControlStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
280
|
-
getThumbStyle: (ctx: SharedContext) => _zag_js_types.JSX.CSSProperties;
|
|
281
|
-
getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) => _zag_js_types.JSX.CSSProperties;
|
|
282
|
-
getRootStyle: (ctx: MachineContext) => _zag_js_types.JSX.CSSProperties;
|
|
283
|
-
getMarkerStyle: (ctx: Pick<SharedContext, "thumbAlignment" | "hasMeasuredThumbSize" | "isHorizontal" | "isRtl">, value: number) => _zag_js_types.JSX.CSSProperties;
|
|
284
|
-
getLabelStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
285
|
-
getTrackStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
286
|
-
getMarkerGroupStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
287
|
-
};
|
|
288
|
-
|
|
289
249
|
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
290
250
|
|
|
291
|
-
export { MachineApi as Api, UserDefinedContext as Context, anatomy, connect, machine
|
|
251
|
+
export { MachineApi as Api, UserDefinedContext as Context, MarkerProps, ThumbProps, anatomy, connect, machine };
|