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