@zag-js/slider 0.23.0 → 0.25.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.ts 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
- hiddenInput: string;
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 value of the slider
31
+ * The aria-label of each slider thumb. Useful for providing an accessible name to the slider
29
32
  */
30
- value: number;
33
+ "aria-label"?: string[];
31
34
  /**
32
- * The name associated with the slider (when used in a form)
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 value is invalid
59
+ * Whether the slider is invalid
49
60
  */
50
61
  invalid?: boolean;
51
62
  /**
52
- * The minimum value of the slider
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
- max: number;
65
+ onValueChange?(details: ValueChangeDetails): void;
59
66
  /**
60
- * The step value of the slider
67
+ * Function invoked when the slider value change is done
61
68
  */
62
- step: number;
69
+ onValueChangeEnd?(details: ValueChangeDetails): void;
63
70
  /**
64
- * The orientation of the slider
71
+ * Function invoked when the slider's focused index changes
65
72
  */
66
- orientation?: "vertical" | "horizontal";
73
+ onFocusChange?(details: FocusChangeDetails): void;
67
74
  /**
68
- * - "start": Useful when the value represents an absolute value
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
- origin?: "start" | "center";
77
+ getAriaValueText?(value: number, index: number): string;
72
78
  /**
73
- * The aria-label of the slider. Useful for providing an accessible name to the slider
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
- "aria-labelledby"?: string;
81
+ min: number;
80
82
  /**
81
- * Whether to focus the slider thumb after interaction (scrub and keyboard)
83
+ * The maximum value of the slider
82
84
  */
83
- focusThumbOnChange?: boolean;
85
+ max: number;
84
86
  /**
85
- * Function that returns a human readable value for the slider
87
+ * The step value of the slider
86
88
  */
87
- getAriaValueText?(value: number): string;
89
+ step: number;
88
90
  /**
89
- * Function invoked when the value of the slider changes
91
+ * The minimum permitted steps between multiple thumbs.
90
92
  */
91
- onValueChange?(details: ValueChangeDetails): void;
93
+ minStepsBetweenThumbs: number;
92
94
  /**
93
- * Function invoked when the slider value change is done
95
+ * The orientation of the slider
94
96
  */
95
- onValueChangeEnd?(details: ValueChangeDetails): void;
97
+ orientation: "vertical" | "horizontal";
96
98
  /**
97
- * Function invoked when the slider value change is started
99
+ * - "start": Useful when the value represents an absolute value
100
+ * - "center": Useful when the value represents an offset (relative)
98
101
  */
99
- onValueChangeStart?(details: ValueChangeDetails): void;
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 thumb dimensions.If not provided, the thumb size will be measured automatically.
110
+ * The slider thumbs dimensions
108
111
  */
109
- thumbSize: Size | null;
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 is interactive
121
+ * Whether the slider thumb has been measured
116
122
  */
117
- isInteractive: boolean;
123
+ hasMeasuredThumbSize: boolean;
118
124
  /**
119
125
  * @computed
120
- * Whether the thumb size has been measured
126
+ * Whether the slider is interactive
121
127
  */
122
- hasMeasuredThumbSize: boolean;
128
+ isInteractive: boolean;
123
129
  /**
124
130
  * @computed
125
- * Whether the slider is horizontal
131
+ * The raw value of the space between each thumb
126
132
  */
127
- isHorizontal: boolean;
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 value of the slider as a percentage
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,135 +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
- * Whether the slider is focused.
176
+ * The value of the slider.
171
177
  */
172
- isFocused: boolean;
178
+ value: number[];
173
179
  /**
174
180
  * Whether the slider is being dragged.
175
181
  */
176
182
  isDragging: boolean;
177
183
  /**
178
- * The value of the slider.
184
+ * Whether the slider is focused.
179
185
  */
180
- value: number;
186
+ isFocused: boolean;
181
187
  /**
182
- * The value of the slider as a percent.
188
+ * Function to set the value of the slider.
183
189
  */
184
- percent: number;
190
+ setValue(value: number[]): void;
185
191
  /**
186
- * Function to set the value of the slider.
192
+ * Returns the value of the thumb at the given index.
187
193
  */
188
- setValue(value: number): void;
194
+ getThumbValue(index: number): number;
189
195
  /**
190
- * Returns the value of the slider at the given percent.
196
+ * Sets the value of the thumb at the given index.
191
197
  */
192
- getPercentValue: (percent: number) => number;
198
+ setThumbValue(index: number, value: number): void;
193
199
  /**
194
- * Returns the percent of the slider at the given value.
200
+ * Returns the percent of the thumb at the given index.
195
201
  */
196
202
  getValuePercent: (value: number) => number;
197
203
  /**
198
- * Function to focus the slider.
204
+ * Returns the value of the thumb at the given percent.
199
205
  */
200
- focus(): void;
206
+ getPercentValue: (percent: number) => number;
201
207
  /**
202
- * Function to increment the value of the slider by the step.
208
+ * Returns the percent of the thumb at the given index.
203
209
  */
204
- increment(): void;
210
+ getThumbPercent(index: number): number;
205
211
  /**
206
- * Function to decrement the value of the slider by the step.
212
+ * Sets the percent of the thumb at the given index.
207
213
  */
208
- decrement(): void;
209
- rootProps: T["element"];
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
- thumbProps: T["element"];
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
- getById: <T extends HTMLElement = HTMLElement>(ctx: {
254
- getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
255
- }, id: string) => T | null;
256
- setValue: <T_1 extends {
257
- value: string;
258
- }>(elem: T_1 | null, value: string | number | null | undefined) => void;
259
- } & {
260
- getRootId: (ctx: MachineContext) => string;
261
- getThumbId: (ctx: MachineContext) => string;
262
- getControlId: (ctx: MachineContext) => string;
263
- getHiddenInputId: (ctx: MachineContext) => string;
264
- getOutputId: (ctx: MachineContext) => string;
265
- getTrackId: (ctx: MachineContext) => string;
266
- getRangeId: (ctx: MachineContext) => string;
267
- getLabelId: (ctx: MachineContext) => string;
268
- getMarkerId: (ctx: MachineContext, value: number) => string;
269
- getRootEl: (ctx: MachineContext) => HTMLElement | null;
270
- getThumbEl: (ctx: MachineContext) => HTMLElement | null;
271
- getControlEl: (ctx: MachineContext) => HTMLElement | null;
272
- getHiddenInputEl: (ctx: MachineContext) => HTMLInputElement | null;
273
- getValueFromPoint(ctx: MachineContext, point: Point): number | undefined;
274
- dispatchChangeEvent(ctx: MachineContext): void;
275
- getThumbOffset: (ctx: SharedContext) => string;
276
- getControlStyle: () => _zag_js_types.JSX.CSSProperties;
277
- getThumbStyle: (ctx: SharedContext) => _zag_js_types.JSX.CSSProperties;
278
- getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) => _zag_js_types.JSX.CSSProperties;
279
- getRootStyle: (ctx: MachineContext) => _zag_js_types.JSX.CSSProperties;
280
- getMarkerStyle: (ctx: Pick<SharedContext, "thumbAlignment" | "hasMeasuredThumbSize" | "isHorizontal" | "isRtl">, value: number) => _zag_js_types.JSX.CSSProperties;
281
- getLabelStyle: () => _zag_js_types.JSX.CSSProperties;
282
- getTrackStyle: () => _zag_js_types.JSX.CSSProperties;
283
- getMarkerGroupStyle: () => _zag_js_types.JSX.CSSProperties;
284
- };
285
-
286
249
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
287
250
 
288
- export { MachineApi as Api, UserDefinedContext as Context, anatomy, connect, machine, dom as unstable__dom };
251
+ export { MachineApi as Api, UserDefinedContext as Context, anatomy, connect, machine };