@zag-js/slider 0.82.1 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
2
+ import { DirectionProperty, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
3
3
  import * as _zag_js_core from '@zag-js/core';
4
- import { Machine, StateMachine } from '@zag-js/core';
4
+ import { Service, EventObject } from '@zag-js/core';
5
5
 
6
6
  declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "thumb" | "valueText" | "track" | "range" | "control" | "markerGroup" | "marker" | "draggingIndicator">;
7
7
 
@@ -27,9 +27,9 @@ type ElementIds = Partial<{
27
27
  valueText: string;
28
28
  marker(index: number): string;
29
29
  }>;
30
- interface PublicContext extends DirectionProperty, CommonProperties {
30
+ interface SliderProps extends DirectionProperty, CommonProperties {
31
31
  /**
32
- * The ids of the elements in the range slider. Useful for composition.
32
+ * The ids of the elements in the slider. Useful for composition.
33
33
  */
34
34
  ids?: ElementIds | undefined;
35
35
  /**
@@ -49,9 +49,14 @@ interface PublicContext extends DirectionProperty, CommonProperties {
49
49
  */
50
50
  form?: string | undefined;
51
51
  /**
52
- * The value of the range slider
52
+ * The controlled value of the slider
53
53
  */
54
- value: number[];
54
+ value?: number[] | undefined;
55
+ /**
56
+ * The initial value of the slider when rendered.
57
+ * Use when you don't need to control the value of the slider.
58
+ */
59
+ defaultValue?: number[] | undefined;
55
60
  /**
56
61
  * Whether the slider is disabled
57
62
  */
@@ -84,27 +89,27 @@ interface PublicContext extends DirectionProperty, CommonProperties {
84
89
  * The minimum value of the slider
85
90
  * @default 0
86
91
  */
87
- min: number;
92
+ min?: number | undefined;
88
93
  /**
89
94
  * The maximum value of the slider
90
95
  * @default 100
91
96
  */
92
- max: number;
97
+ max?: number | undefined;
93
98
  /**
94
99
  * The step value of the slider
95
100
  * @default 1
96
101
  */
97
- step: number;
102
+ step?: number | undefined;
98
103
  /**
99
104
  * The minimum permitted steps between multiple thumbs.
100
105
  * @default 0
101
106
  */
102
- minStepsBetweenThumbs: number;
107
+ minStepsBetweenThumbs?: number | undefined;
103
108
  /**
104
109
  * The orientation of the slider
105
110
  * @default "horizontal"
106
111
  */
107
- orientation: "vertical" | "horizontal";
112
+ orientation?: "vertical" | "horizontal" | undefined;
108
113
  /**
109
114
  * The origin of the slider range
110
115
  * - "start": Useful when the value represents an absolute value
@@ -124,13 +129,13 @@ interface PublicContext extends DirectionProperty, CommonProperties {
124
129
  /**
125
130
  * The slider thumbs dimensions
126
131
  */
127
- thumbSize: {
132
+ thumbSize?: {
128
133
  width: number;
129
134
  height: number;
130
- } | null;
135
+ } | undefined;
131
136
  }
132
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
133
- type ComputedContext = Readonly<{
137
+ type PropsWithDefault = "dir" | "min" | "max" | "step" | "orientation" | "defaultValue" | "origin" | "thumbAlignment" | "minStepsBetweenThumbs";
138
+ type Computed = Readonly<{
134
139
  /**
135
140
  * @computed
136
141
  * Whether the slider thumb has been measured
@@ -167,16 +172,36 @@ type ComputedContext = Readonly<{
167
172
  */
168
173
  isDisabled: boolean;
169
174
  }>;
170
- interface PrivateContext {
175
+ interface Context {
176
+ /**
177
+ * The active index of the range slider. This represents
178
+ * the currently dragged/focused thumb.
179
+ */
180
+ focusedIndex: number;
181
+ /**
182
+ * The value of the range slider
183
+ */
184
+ value: number[];
185
+ /**
186
+ * The size of the slider thumbs
187
+ */
188
+ thumbSize: Size | null;
171
189
  }
172
- interface MachineContext extends PublicContext, ComputedContext, PrivateContext {
190
+ interface SliderSchema {
191
+ state: "idle" | "dragging" | "focus";
192
+ props: RequiredBy<SliderProps, PropsWithDefault>;
193
+ context: Context;
194
+ computed: Computed;
195
+ event: EventObject;
196
+ action: string;
197
+ effect: string;
198
+ guard: string;
173
199
  }
174
- interface MachineState {
175
- value: "idle" | "dragging" | "focus";
200
+ type SliderService = Service<SliderSchema>;
201
+ interface Size {
202
+ width: number;
203
+ height: number;
176
204
  }
177
- type State = StateMachine.State<MachineContext, MachineState>;
178
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
179
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
180
205
  interface MarkerProps {
181
206
  value: number;
182
207
  }
@@ -187,7 +212,7 @@ interface ThumbProps {
187
212
  interface DraggingIndicatorProps {
188
213
  index: number;
189
214
  }
190
- interface MachineApi<T extends PropTypes = PropTypes> {
215
+ interface SliderApi<T extends PropTypes = PropTypes> {
191
216
  /**
192
217
  * The value of the slider.
193
218
  */
@@ -261,13 +286,13 @@ interface MachineApi<T extends PropTypes = PropTypes> {
261
286
  getDraggingIndicatorProps(props: DraggingIndicatorProps): T["element"];
262
287
  }
263
288
 
264
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
289
+ declare function connect<T extends PropTypes>(service: SliderService, normalize: NormalizeProps<T>): SliderApi<T>;
265
290
 
266
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
291
+ declare const machine: _zag_js_core.MachineConfig<SliderSchema>;
267
292
 
268
- declare const props: ("disabled" | "step" | "form" | "dir" | "id" | "aria-label" | "aria-labelledby" | "max" | "min" | "name" | "origin" | "value" | "orientation" | "getRootNode" | "invalid" | "ids" | "readOnly" | "onValueChange" | "onValueChangeEnd" | "onFocusChange" | "getAriaValueText" | "minStepsBetweenThumbs" | "thumbAlignment" | "thumbSize")[];
269
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "disabled" | "step" | "form" | "dir" | "id" | "aria-label" | "aria-labelledby" | "max" | "min" | "name" | "origin" | "value" | "orientation" | "getRootNode" | "invalid" | "ids" | "readOnly" | "onValueChange" | "onValueChangeEnd" | "onFocusChange" | "getAriaValueText" | "minStepsBetweenThumbs" | "thumbAlignment" | "thumbSize">];
293
+ declare const props: (keyof SliderProps)[];
294
+ declare const splitProps: <Props extends Partial<SliderProps>>(props: Props) => [Partial<SliderProps>, Omit<Props, keyof SliderProps>];
270
295
  declare const thumbProps: (keyof ThumbProps)[];
271
296
  declare const splitThumbProps: <Props extends ThumbProps>(props: Props) => [ThumbProps, Omit<Props, keyof ThumbProps>];
272
297
 
273
- export { type MachineApi as Api, type UserDefinedContext as Context, type DraggingIndicatorProps, type ElementIds, type FocusChangeDetails, type MarkerProps, type Service, type ThumbProps, type ValueChangeDetails, type ValueTextDetails, anatomy, connect, machine, props, splitProps, splitThumbProps, thumbProps };
298
+ export { type SliderApi as Api, type DraggingIndicatorProps, type ElementIds, type FocusChangeDetails, type MarkerProps, type SliderProps as Props, type SliderService as Service, type ThumbProps, type ValueChangeDetails, type ValueTextDetails, anatomy, connect, machine, props, splitProps, splitThumbProps, thumbProps };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
2
+ import { DirectionProperty, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
3
3
  import * as _zag_js_core from '@zag-js/core';
4
- import { Machine, StateMachine } from '@zag-js/core';
4
+ import { Service, EventObject } from '@zag-js/core';
5
5
 
6
6
  declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "thumb" | "valueText" | "track" | "range" | "control" | "markerGroup" | "marker" | "draggingIndicator">;
7
7
 
@@ -27,9 +27,9 @@ type ElementIds = Partial<{
27
27
  valueText: string;
28
28
  marker(index: number): string;
29
29
  }>;
30
- interface PublicContext extends DirectionProperty, CommonProperties {
30
+ interface SliderProps extends DirectionProperty, CommonProperties {
31
31
  /**
32
- * The ids of the elements in the range slider. Useful for composition.
32
+ * The ids of the elements in the slider. Useful for composition.
33
33
  */
34
34
  ids?: ElementIds | undefined;
35
35
  /**
@@ -49,9 +49,14 @@ interface PublicContext extends DirectionProperty, CommonProperties {
49
49
  */
50
50
  form?: string | undefined;
51
51
  /**
52
- * The value of the range slider
52
+ * The controlled value of the slider
53
53
  */
54
- value: number[];
54
+ value?: number[] | undefined;
55
+ /**
56
+ * The initial value of the slider when rendered.
57
+ * Use when you don't need to control the value of the slider.
58
+ */
59
+ defaultValue?: number[] | undefined;
55
60
  /**
56
61
  * Whether the slider is disabled
57
62
  */
@@ -84,27 +89,27 @@ interface PublicContext extends DirectionProperty, CommonProperties {
84
89
  * The minimum value of the slider
85
90
  * @default 0
86
91
  */
87
- min: number;
92
+ min?: number | undefined;
88
93
  /**
89
94
  * The maximum value of the slider
90
95
  * @default 100
91
96
  */
92
- max: number;
97
+ max?: number | undefined;
93
98
  /**
94
99
  * The step value of the slider
95
100
  * @default 1
96
101
  */
97
- step: number;
102
+ step?: number | undefined;
98
103
  /**
99
104
  * The minimum permitted steps between multiple thumbs.
100
105
  * @default 0
101
106
  */
102
- minStepsBetweenThumbs: number;
107
+ minStepsBetweenThumbs?: number | undefined;
103
108
  /**
104
109
  * The orientation of the slider
105
110
  * @default "horizontal"
106
111
  */
107
- orientation: "vertical" | "horizontal";
112
+ orientation?: "vertical" | "horizontal" | undefined;
108
113
  /**
109
114
  * The origin of the slider range
110
115
  * - "start": Useful when the value represents an absolute value
@@ -124,13 +129,13 @@ interface PublicContext extends DirectionProperty, CommonProperties {
124
129
  /**
125
130
  * The slider thumbs dimensions
126
131
  */
127
- thumbSize: {
132
+ thumbSize?: {
128
133
  width: number;
129
134
  height: number;
130
- } | null;
135
+ } | undefined;
131
136
  }
132
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
133
- type ComputedContext = Readonly<{
137
+ type PropsWithDefault = "dir" | "min" | "max" | "step" | "orientation" | "defaultValue" | "origin" | "thumbAlignment" | "minStepsBetweenThumbs";
138
+ type Computed = Readonly<{
134
139
  /**
135
140
  * @computed
136
141
  * Whether the slider thumb has been measured
@@ -167,16 +172,36 @@ type ComputedContext = Readonly<{
167
172
  */
168
173
  isDisabled: boolean;
169
174
  }>;
170
- interface PrivateContext {
175
+ interface Context {
176
+ /**
177
+ * The active index of the range slider. This represents
178
+ * the currently dragged/focused thumb.
179
+ */
180
+ focusedIndex: number;
181
+ /**
182
+ * The value of the range slider
183
+ */
184
+ value: number[];
185
+ /**
186
+ * The size of the slider thumbs
187
+ */
188
+ thumbSize: Size | null;
171
189
  }
172
- interface MachineContext extends PublicContext, ComputedContext, PrivateContext {
190
+ interface SliderSchema {
191
+ state: "idle" | "dragging" | "focus";
192
+ props: RequiredBy<SliderProps, PropsWithDefault>;
193
+ context: Context;
194
+ computed: Computed;
195
+ event: EventObject;
196
+ action: string;
197
+ effect: string;
198
+ guard: string;
173
199
  }
174
- interface MachineState {
175
- value: "idle" | "dragging" | "focus";
200
+ type SliderService = Service<SliderSchema>;
201
+ interface Size {
202
+ width: number;
203
+ height: number;
176
204
  }
177
- type State = StateMachine.State<MachineContext, MachineState>;
178
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
179
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
180
205
  interface MarkerProps {
181
206
  value: number;
182
207
  }
@@ -187,7 +212,7 @@ interface ThumbProps {
187
212
  interface DraggingIndicatorProps {
188
213
  index: number;
189
214
  }
190
- interface MachineApi<T extends PropTypes = PropTypes> {
215
+ interface SliderApi<T extends PropTypes = PropTypes> {
191
216
  /**
192
217
  * The value of the slider.
193
218
  */
@@ -261,13 +286,13 @@ interface MachineApi<T extends PropTypes = PropTypes> {
261
286
  getDraggingIndicatorProps(props: DraggingIndicatorProps): T["element"];
262
287
  }
263
288
 
264
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
289
+ declare function connect<T extends PropTypes>(service: SliderService, normalize: NormalizeProps<T>): SliderApi<T>;
265
290
 
266
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
291
+ declare const machine: _zag_js_core.MachineConfig<SliderSchema>;
267
292
 
268
- declare const props: ("disabled" | "step" | "form" | "dir" | "id" | "aria-label" | "aria-labelledby" | "max" | "min" | "name" | "origin" | "value" | "orientation" | "getRootNode" | "invalid" | "ids" | "readOnly" | "onValueChange" | "onValueChangeEnd" | "onFocusChange" | "getAriaValueText" | "minStepsBetweenThumbs" | "thumbAlignment" | "thumbSize")[];
269
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "disabled" | "step" | "form" | "dir" | "id" | "aria-label" | "aria-labelledby" | "max" | "min" | "name" | "origin" | "value" | "orientation" | "getRootNode" | "invalid" | "ids" | "readOnly" | "onValueChange" | "onValueChangeEnd" | "onFocusChange" | "getAriaValueText" | "minStepsBetweenThumbs" | "thumbAlignment" | "thumbSize">];
293
+ declare const props: (keyof SliderProps)[];
294
+ declare const splitProps: <Props extends Partial<SliderProps>>(props: Props) => [Partial<SliderProps>, Omit<Props, keyof SliderProps>];
270
295
  declare const thumbProps: (keyof ThumbProps)[];
271
296
  declare const splitThumbProps: <Props extends ThumbProps>(props: Props) => [ThumbProps, Omit<Props, keyof ThumbProps>];
272
297
 
273
- export { type MachineApi as Api, type UserDefinedContext as Context, type DraggingIndicatorProps, type ElementIds, type FocusChangeDetails, type MarkerProps, type Service, type ThumbProps, type ValueChangeDetails, type ValueTextDetails, anatomy, connect, machine, props, splitProps, splitThumbProps, thumbProps };
298
+ export { type SliderApi as Api, type DraggingIndicatorProps, type ElementIds, type FocusChangeDetails, type MarkerProps, type SliderProps as Props, type SliderService as Service, type ThumbProps, type ValueChangeDetails, type ValueTextDetails, anatomy, connect, machine, props, splitProps, splitThumbProps, thumbProps };