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