@zag-js/slider 0.10.2 → 0.10.4
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 +5 -8
- package/dist/index.js +10 -674
- package/dist/index.mjs +4 -20
- package/dist/slider.anatomy.d.ts +3 -6
- package/dist/slider.anatomy.js +10 -33
- package/dist/slider.anatomy.mjs +17 -8
- package/dist/slider.connect.d.ts +3 -7
- package/dist/slider.connect.js +72 -261
- package/dist/slider.connect.mjs +251 -9
- package/dist/slider.dom.d.ts +26 -30
- package/dist/slider.dom.js +14 -149
- package/dist/slider.dom.mjs +39 -7
- package/dist/slider.machine.d.ts +3 -7
- package/dist/slider.machine.js +27 -225
- package/dist/slider.machine.mjs +203 -9
- package/dist/slider.style.d.ts +5 -8
- package/dist/slider.style.js +12 -34
- package/dist/slider.style.mjs +112 -5
- package/dist/slider.types.d.ts +10 -12
- package/dist/slider.utils.d.ts +5 -10
- package/dist/slider.utils.js +13 -42
- package/dist/slider.utils.mjs +26 -12
- package/package.json +11 -16
- package/dist/chunk-3Y7IIPR5.mjs +0 -20
- package/dist/chunk-IJAAAKZQ.mjs +0 -115
- package/dist/chunk-NYN3VIY4.mjs +0 -44
- package/dist/chunk-OCT2YBMN.mjs +0 -212
- package/dist/chunk-T6GXNUP7.mjs +0 -265
- package/dist/chunk-YGFSMEUO.mjs +0 -34
- package/dist/slider.types.js +0 -18
- package/dist/slider.types.mjs +0 -0
package/dist/slider.connect.mjs
CHANGED
|
@@ -1,9 +1,251 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { getEventStep, getEventKey, getNativeEvent, isLeftClick, isModifiedEvent, getEventPoint } from '@zag-js/dom-event';
|
|
2
|
+
import { dataAttr, ariaAttr } from '@zag-js/dom-query';
|
|
3
|
+
import { getValuePercent, getPercentValue } from '@zag-js/numeric-range';
|
|
4
|
+
import { parts } from './slider.anatomy.mjs';
|
|
5
|
+
import { dom } from './slider.dom.mjs';
|
|
6
|
+
|
|
7
|
+
function connect(state, send, normalize) {
|
|
8
|
+
const ariaLabel = state.context["aria-label"];
|
|
9
|
+
const ariaLabelledBy = state.context["aria-labelledby"];
|
|
10
|
+
const ariaValueText = state.context.getAriaValueText?.(state.context.value);
|
|
11
|
+
const isFocused = state.matches("focus");
|
|
12
|
+
const isDragging = state.matches("dragging");
|
|
13
|
+
const isDisabled = state.context.disabled;
|
|
14
|
+
const isInteractive = state.context.isInteractive;
|
|
15
|
+
const isInvalid = state.context.invalid;
|
|
16
|
+
function getPercentValueFn(percent) {
|
|
17
|
+
return getPercentValue(percent, state.context.min, state.context.max, state.context.step);
|
|
18
|
+
}
|
|
19
|
+
function getValuePercentFn(value) {
|
|
20
|
+
return getValuePercent(value, state.context.min, state.context.max);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
/**
|
|
24
|
+
* Whether the slider is focused.
|
|
25
|
+
*/
|
|
26
|
+
isFocused,
|
|
27
|
+
/**
|
|
28
|
+
* Whether the slider is being dragged.
|
|
29
|
+
*/
|
|
30
|
+
isDragging,
|
|
31
|
+
/**
|
|
32
|
+
* The value of the slider.
|
|
33
|
+
*/
|
|
34
|
+
value: state.context.value,
|
|
35
|
+
/**
|
|
36
|
+
* The value of the slider as a percent.
|
|
37
|
+
*/
|
|
38
|
+
percent: getValuePercent(state.context.value, state.context.min, state.context.max),
|
|
39
|
+
/**
|
|
40
|
+
* Function to set the value of the slider.
|
|
41
|
+
*/
|
|
42
|
+
setValue(value) {
|
|
43
|
+
send({ type: "SET_VALUE", value });
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Returns the value of the slider at the given percent.
|
|
47
|
+
*/
|
|
48
|
+
getPercentValue: getPercentValueFn,
|
|
49
|
+
/**
|
|
50
|
+
* Returns the percent of the slider at the given value.
|
|
51
|
+
*/
|
|
52
|
+
getValuePercent: getValuePercentFn,
|
|
53
|
+
/**
|
|
54
|
+
* Function to focus the slider.
|
|
55
|
+
*/
|
|
56
|
+
focus() {
|
|
57
|
+
dom.getThumbEl(state.context)?.focus();
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Function to increment the value of the slider by the step.
|
|
61
|
+
*/
|
|
62
|
+
increment() {
|
|
63
|
+
send("INCREMENT");
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Function to decrement the value of the slider by the step.
|
|
67
|
+
*/
|
|
68
|
+
decrement() {
|
|
69
|
+
send("DECREMENT");
|
|
70
|
+
},
|
|
71
|
+
rootProps: normalize.element({
|
|
72
|
+
...parts.root.attrs,
|
|
73
|
+
"data-disabled": dataAttr(isDisabled),
|
|
74
|
+
"data-focus": dataAttr(isFocused),
|
|
75
|
+
"data-orientation": state.context.orientation,
|
|
76
|
+
"data-invalid": dataAttr(isInvalid),
|
|
77
|
+
id: dom.getRootId(state.context),
|
|
78
|
+
dir: state.context.dir,
|
|
79
|
+
style: dom.getRootStyle(state.context)
|
|
80
|
+
}),
|
|
81
|
+
labelProps: normalize.label({
|
|
82
|
+
...parts.label.attrs,
|
|
83
|
+
"data-disabled": dataAttr(isDisabled),
|
|
84
|
+
"data-invalid": dataAttr(isInvalid),
|
|
85
|
+
"data-focus": dataAttr(isFocused),
|
|
86
|
+
id: dom.getLabelId(state.context),
|
|
87
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
88
|
+
onClick(event) {
|
|
89
|
+
if (!isInteractive)
|
|
90
|
+
return;
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
dom.getThumbEl(state.context)?.focus();
|
|
93
|
+
},
|
|
94
|
+
style: dom.getLabelStyle()
|
|
95
|
+
}),
|
|
96
|
+
thumbProps: normalize.element({
|
|
97
|
+
...parts.thumb.attrs,
|
|
98
|
+
id: dom.getThumbId(state.context),
|
|
99
|
+
"data-disabled": dataAttr(isDisabled),
|
|
100
|
+
"data-orientation": state.context.orientation,
|
|
101
|
+
"data-focus": dataAttr(isFocused),
|
|
102
|
+
draggable: false,
|
|
103
|
+
"aria-invalid": ariaAttr(isInvalid),
|
|
104
|
+
"data-invalid": dataAttr(isInvalid),
|
|
105
|
+
"aria-disabled": ariaAttr(isDisabled),
|
|
106
|
+
"aria-label": ariaLabel,
|
|
107
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state.context),
|
|
108
|
+
"aria-orientation": state.context.orientation,
|
|
109
|
+
"aria-valuemax": state.context.max,
|
|
110
|
+
"aria-valuemin": state.context.min,
|
|
111
|
+
"aria-valuenow": state.context.value,
|
|
112
|
+
"aria-valuetext": ariaValueText,
|
|
113
|
+
role: "slider",
|
|
114
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
115
|
+
onBlur() {
|
|
116
|
+
if (!isInteractive)
|
|
117
|
+
return;
|
|
118
|
+
send("BLUR");
|
|
119
|
+
},
|
|
120
|
+
onFocus() {
|
|
121
|
+
if (!isInteractive)
|
|
122
|
+
return;
|
|
123
|
+
send("FOCUS");
|
|
124
|
+
},
|
|
125
|
+
onKeyDown(event) {
|
|
126
|
+
if (!isInteractive)
|
|
127
|
+
return;
|
|
128
|
+
const step = getEventStep(event) * state.context.step;
|
|
129
|
+
let prevent = true;
|
|
130
|
+
const keyMap = {
|
|
131
|
+
ArrowUp() {
|
|
132
|
+
send({ type: "ARROW_UP", step });
|
|
133
|
+
prevent = state.context.isVertical;
|
|
134
|
+
},
|
|
135
|
+
ArrowDown() {
|
|
136
|
+
send({ type: "ARROW_DOWN", step });
|
|
137
|
+
prevent = state.context.isVertical;
|
|
138
|
+
},
|
|
139
|
+
ArrowLeft() {
|
|
140
|
+
send({ type: "ARROW_LEFT", step });
|
|
141
|
+
prevent = state.context.isHorizontal;
|
|
142
|
+
},
|
|
143
|
+
ArrowRight() {
|
|
144
|
+
send({ type: "ARROW_RIGHT", step });
|
|
145
|
+
prevent = state.context.isHorizontal;
|
|
146
|
+
},
|
|
147
|
+
PageUp() {
|
|
148
|
+
send({ type: "PAGE_UP", step });
|
|
149
|
+
},
|
|
150
|
+
PageDown() {
|
|
151
|
+
send({ type: "PAGE_DOWN", step });
|
|
152
|
+
},
|
|
153
|
+
Home() {
|
|
154
|
+
send("HOME");
|
|
155
|
+
},
|
|
156
|
+
End() {
|
|
157
|
+
send("END");
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const key = getEventKey(event, state.context);
|
|
161
|
+
const exec = keyMap[key];
|
|
162
|
+
if (!exec)
|
|
163
|
+
return;
|
|
164
|
+
exec(event);
|
|
165
|
+
if (prevent) {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
style: dom.getThumbStyle(state.context)
|
|
170
|
+
}),
|
|
171
|
+
hiddenInputProps: normalize.input({
|
|
172
|
+
...parts.hiddenInput.attrs,
|
|
173
|
+
type: "text",
|
|
174
|
+
defaultValue: state.context.value,
|
|
175
|
+
name: state.context.name,
|
|
176
|
+
form: state.context.form,
|
|
177
|
+
id: dom.getHiddenInputId(state.context),
|
|
178
|
+
hidden: true
|
|
179
|
+
}),
|
|
180
|
+
outputProps: normalize.output({
|
|
181
|
+
...parts.output.attrs,
|
|
182
|
+
"data-disabled": dataAttr(isDisabled),
|
|
183
|
+
"data-invalid": dataAttr(isInvalid),
|
|
184
|
+
id: dom.getOutputId(state.context),
|
|
185
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
186
|
+
"aria-live": "off"
|
|
187
|
+
}),
|
|
188
|
+
trackProps: normalize.element({
|
|
189
|
+
...parts.track.attrs,
|
|
190
|
+
id: dom.getTrackId(state.context),
|
|
191
|
+
"data-disabled": dataAttr(isDisabled),
|
|
192
|
+
"data-focus": dataAttr(isFocused),
|
|
193
|
+
"data-invalid": dataAttr(isInvalid),
|
|
194
|
+
"data-orientation": state.context.orientation,
|
|
195
|
+
style: dom.getTrackStyle()
|
|
196
|
+
}),
|
|
197
|
+
rangeProps: normalize.element({
|
|
198
|
+
...parts.range.attrs,
|
|
199
|
+
id: dom.getRangeId(state.context),
|
|
200
|
+
"data-focus": dataAttr(isFocused),
|
|
201
|
+
"data-invalid": dataAttr(isInvalid),
|
|
202
|
+
"data-disabled": dataAttr(isDisabled),
|
|
203
|
+
"data-orientation": state.context.orientation,
|
|
204
|
+
style: dom.getRangeStyle(state.context)
|
|
205
|
+
}),
|
|
206
|
+
controlProps: normalize.element({
|
|
207
|
+
...parts.control.attrs,
|
|
208
|
+
id: dom.getControlId(state.context),
|
|
209
|
+
"data-disabled": dataAttr(isDisabled),
|
|
210
|
+
"data-invalid": dataAttr(isInvalid),
|
|
211
|
+
"data-orientation": state.context.orientation,
|
|
212
|
+
"data-focus": dataAttr(isFocused),
|
|
213
|
+
onPointerDown(event) {
|
|
214
|
+
if (!isInteractive)
|
|
215
|
+
return;
|
|
216
|
+
const evt = getNativeEvent(event);
|
|
217
|
+
if (!isLeftClick(evt) || isModifiedEvent(evt))
|
|
218
|
+
return;
|
|
219
|
+
const point = getEventPoint(evt);
|
|
220
|
+
send({ type: "POINTER_DOWN", point });
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
event.stopPropagation();
|
|
223
|
+
},
|
|
224
|
+
style: dom.getControlStyle()
|
|
225
|
+
}),
|
|
226
|
+
markerGroupProps: normalize.element({
|
|
227
|
+
...parts.markerGroup.attrs,
|
|
228
|
+
role: "presentation",
|
|
229
|
+
"aria-hidden": true,
|
|
230
|
+
"data-orientation": state.context.orientation,
|
|
231
|
+
style: dom.getMarkerGroupStyle()
|
|
232
|
+
}),
|
|
233
|
+
getMarkerProps({ value }) {
|
|
234
|
+
const percent = getValuePercentFn(value);
|
|
235
|
+
const style = dom.getMarkerStyle(state.context, percent);
|
|
236
|
+
const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
|
|
237
|
+
return normalize.element({
|
|
238
|
+
...parts.marker.attrs,
|
|
239
|
+
id: dom.getMarkerId(state.context, value),
|
|
240
|
+
role: "presentation",
|
|
241
|
+
"data-orientation": state.context.orientation,
|
|
242
|
+
"data-value": value,
|
|
243
|
+
"data-disabled": dataAttr(isDisabled),
|
|
244
|
+
"data-state": markerState,
|
|
245
|
+
style
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export { connect };
|
package/dist/slider.dom.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { MachineContext, Point
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const dom: {
|
|
1
|
+
import { JSX } from '@zag-js/types';
|
|
2
|
+
import { SharedContext, MachineContext as Ctx, Point } from './slider.types';
|
|
3
|
+
export declare const dom: {
|
|
6
4
|
getRootNode: (ctx: {
|
|
7
5
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
8
6
|
}) => Document | ShadowRoot;
|
|
@@ -22,30 +20,28 @@ declare const dom: {
|
|
|
22
20
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
23
21
|
}, id: string) => T_1;
|
|
24
22
|
} & {
|
|
25
|
-
getRootId: (ctx:
|
|
26
|
-
getThumbId: (ctx:
|
|
27
|
-
getControlId: (ctx:
|
|
28
|
-
getHiddenInputId: (ctx:
|
|
29
|
-
getOutputId: (ctx:
|
|
30
|
-
getTrackId: (ctx:
|
|
31
|
-
getRangeId: (ctx:
|
|
32
|
-
getLabelId: (ctx:
|
|
33
|
-
getMarkerId: (ctx:
|
|
34
|
-
getRootEl: (ctx:
|
|
35
|
-
getThumbEl: (ctx:
|
|
36
|
-
getControlEl: (ctx:
|
|
37
|
-
getHiddenInputEl: (ctx:
|
|
38
|
-
getValueFromPoint(ctx:
|
|
39
|
-
dispatchChangeEvent(ctx:
|
|
23
|
+
getRootId: (ctx: Ctx) => string;
|
|
24
|
+
getThumbId: (ctx: Ctx) => string;
|
|
25
|
+
getControlId: (ctx: Ctx) => string;
|
|
26
|
+
getHiddenInputId: (ctx: Ctx) => string;
|
|
27
|
+
getOutputId: (ctx: Ctx) => string;
|
|
28
|
+
getTrackId: (ctx: Ctx) => string;
|
|
29
|
+
getRangeId: (ctx: Ctx) => string;
|
|
30
|
+
getLabelId: (ctx: Ctx) => string;
|
|
31
|
+
getMarkerId: (ctx: Ctx, value: number) => string;
|
|
32
|
+
getRootEl: (ctx: Ctx) => HTMLElement | null;
|
|
33
|
+
getThumbEl: (ctx: Ctx) => HTMLElement | null;
|
|
34
|
+
getControlEl: (ctx: Ctx) => HTMLElement;
|
|
35
|
+
getHiddenInputEl: (ctx: Ctx) => HTMLInputElement | null;
|
|
36
|
+
getValueFromPoint(ctx: Ctx, point: Point): number | undefined;
|
|
37
|
+
dispatchChangeEvent(ctx: Ctx): void;
|
|
40
38
|
getThumbOffset: (ctx: SharedContext) => string;
|
|
41
|
-
getControlStyle: () =>
|
|
42
|
-
getThumbStyle: (ctx: SharedContext) =>
|
|
43
|
-
getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) =>
|
|
44
|
-
getRootStyle: (ctx:
|
|
45
|
-
getMarkerStyle: (ctx: Pick<SharedContext, "isHorizontal" | "isRtl">, percent: number) =>
|
|
46
|
-
getLabelStyle: () =>
|
|
47
|
-
getTrackStyle: () =>
|
|
48
|
-
getMarkerGroupStyle: () =>
|
|
39
|
+
getControlStyle: () => JSX.CSSProperties;
|
|
40
|
+
getThumbStyle: (ctx: SharedContext) => JSX.CSSProperties;
|
|
41
|
+
getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) => JSX.CSSProperties;
|
|
42
|
+
getRootStyle: (ctx: Ctx) => JSX.CSSProperties;
|
|
43
|
+
getMarkerStyle: (ctx: Pick<SharedContext, "isHorizontal" | "isRtl">, percent: number) => JSX.CSSProperties;
|
|
44
|
+
getLabelStyle: () => JSX.CSSProperties;
|
|
45
|
+
getTrackStyle: () => JSX.CSSProperties;
|
|
46
|
+
getMarkerGroupStyle: () => JSX.CSSProperties;
|
|
49
47
|
};
|
|
50
|
-
|
|
51
|
-
export { dom };
|
package/dist/slider.dom.js
CHANGED
|
@@ -1,148 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var slider_dom_exports = {};
|
|
22
|
-
__export(slider_dom_exports, {
|
|
23
|
-
dom: () => dom
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(slider_dom_exports);
|
|
26
|
-
var import_dom_event = require("@zag-js/dom-event");
|
|
27
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
28
|
-
var import_form_utils = require("@zag-js/form-utils");
|
|
29
|
-
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
30
4
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
37
|
-
}
|
|
38
|
-
function getHorizontalThumbOffset(ctx) {
|
|
39
|
-
const { width = 0 } = ctx.thumbSize ?? {};
|
|
40
|
-
if (ctx.isRtl) {
|
|
41
|
-
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
42
|
-
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
43
|
-
}
|
|
44
|
-
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
45
|
-
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
46
|
-
}
|
|
47
|
-
function getThumbOffset(ctx) {
|
|
48
|
-
const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
|
|
49
|
-
if (ctx.thumbAlignment === "center") {
|
|
50
|
-
return `${percent}%`;
|
|
51
|
-
}
|
|
52
|
-
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
53
|
-
return `calc(${percent}% - ${offset}px)`;
|
|
54
|
-
}
|
|
55
|
-
function getVisibility(ctx) {
|
|
56
|
-
let visibility = "visible";
|
|
57
|
-
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
58
|
-
visibility = "hidden";
|
|
59
|
-
}
|
|
60
|
-
return visibility;
|
|
61
|
-
}
|
|
62
|
-
function getThumbStyle(ctx) {
|
|
63
|
-
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
64
|
-
return {
|
|
65
|
-
visibility: getVisibility(ctx),
|
|
66
|
-
position: "absolute",
|
|
67
|
-
transform: "var(--slider-thumb-transform)",
|
|
68
|
-
[placementProp]: "var(--slider-thumb-offset)"
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function getRangeOffsets(ctx) {
|
|
72
|
-
let start = "0%";
|
|
73
|
-
let end = `${100 - ctx.valuePercent}%`;
|
|
74
|
-
if (ctx.origin === "center") {
|
|
75
|
-
const isNegative = ctx.valuePercent < 50;
|
|
76
|
-
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
77
|
-
end = isNegative ? "50%" : end;
|
|
78
|
-
}
|
|
79
|
-
return { start, end };
|
|
80
|
-
}
|
|
81
|
-
function getRangeStyle(ctx) {
|
|
82
|
-
if (ctx.isVertical) {
|
|
83
|
-
return {
|
|
84
|
-
position: "absolute",
|
|
85
|
-
bottom: "var(--slider-range-start)",
|
|
86
|
-
top: "var(--slider-range-end)"
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
position: "absolute",
|
|
91
|
-
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
92
|
-
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function getControlStyle() {
|
|
96
|
-
return {
|
|
97
|
-
touchAction: "none",
|
|
98
|
-
userSelect: "none",
|
|
99
|
-
position: "relative"
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function getRootStyle(ctx) {
|
|
103
|
-
const range = getRangeOffsets(ctx);
|
|
104
|
-
return {
|
|
105
|
-
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
106
|
-
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
107
|
-
"--slider-range-start": range.start,
|
|
108
|
-
"--slider-range-end": range.end
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function getMarkerStyle(ctx, percent) {
|
|
112
|
-
return {
|
|
113
|
-
position: "absolute",
|
|
114
|
-
pointerEvents: "none",
|
|
115
|
-
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function getLabelStyle() {
|
|
119
|
-
return { userSelect: "none" };
|
|
120
|
-
}
|
|
121
|
-
function getTrackStyle() {
|
|
122
|
-
return { position: "relative" };
|
|
123
|
-
}
|
|
124
|
-
function getMarkerGroupStyle() {
|
|
125
|
-
return {
|
|
126
|
-
userSelect: "none",
|
|
127
|
-
pointerEvents: "none",
|
|
128
|
-
position: "relative"
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
var styles = {
|
|
132
|
-
getThumbOffset,
|
|
133
|
-
getControlStyle,
|
|
134
|
-
getThumbStyle,
|
|
135
|
-
getRangeStyle,
|
|
136
|
-
getRootStyle,
|
|
137
|
-
getMarkerStyle,
|
|
138
|
-
getLabelStyle,
|
|
139
|
-
getTrackStyle,
|
|
140
|
-
getMarkerGroupStyle
|
|
141
|
-
};
|
|
5
|
+
const domEvent = require('@zag-js/dom-event');
|
|
6
|
+
const domQuery = require('@zag-js/dom-query');
|
|
7
|
+
const formUtils = require('@zag-js/form-utils');
|
|
8
|
+
const numericRange = require('@zag-js/numeric-range');
|
|
9
|
+
const slider_style = require('./slider.style.js');
|
|
142
10
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
...styles,
|
|
11
|
+
const dom = domQuery.createScope({
|
|
12
|
+
...slider_style.styles,
|
|
146
13
|
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
147
14
|
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
148
15
|
getControlId: (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`,
|
|
@@ -157,22 +24,20 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
157
24
|
getControlEl: (ctx) => dom.queryById(ctx, dom.getControlId(ctx)),
|
|
158
25
|
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
159
26
|
getValueFromPoint(ctx, point) {
|
|
160
|
-
const relativePoint =
|
|
27
|
+
const relativePoint = domEvent.getRelativePoint(point, dom.getControlEl(ctx));
|
|
161
28
|
const percent = relativePoint.getPercentValue({
|
|
162
29
|
orientation: ctx.orientation,
|
|
163
30
|
dir: ctx.dir,
|
|
164
31
|
inverted: { y: true }
|
|
165
32
|
});
|
|
166
|
-
return
|
|
33
|
+
return numericRange.getPercentValue(percent, ctx.min, ctx.max, ctx.step);
|
|
167
34
|
},
|
|
168
35
|
dispatchChangeEvent(ctx) {
|
|
169
36
|
const input = dom.getHiddenInputEl(ctx);
|
|
170
37
|
if (!input)
|
|
171
38
|
return;
|
|
172
|
-
|
|
39
|
+
formUtils.dispatchInputValueEvent(input, { value: ctx.value });
|
|
173
40
|
}
|
|
174
41
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
dom
|
|
178
|
-
});
|
|
42
|
+
|
|
43
|
+
exports.dom = dom;
|
package/dist/slider.dom.mjs
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { getRelativePoint } from '@zag-js/dom-event';
|
|
2
|
+
import { createScope } from '@zag-js/dom-query';
|
|
3
|
+
import { dispatchInputValueEvent } from '@zag-js/form-utils';
|
|
4
|
+
import { getPercentValue } from '@zag-js/numeric-range';
|
|
5
|
+
import { styles } from './slider.style.mjs';
|
|
6
|
+
|
|
7
|
+
const dom = createScope({
|
|
8
|
+
...styles,
|
|
9
|
+
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
10
|
+
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
11
|
+
getControlId: (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`,
|
|
12
|
+
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `slider:${ctx.id}:input`,
|
|
13
|
+
getOutputId: (ctx) => ctx.ids?.output ?? `slider:${ctx.id}:output`,
|
|
14
|
+
getTrackId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}track`,
|
|
15
|
+
getRangeId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:range`,
|
|
16
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`,
|
|
17
|
+
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
18
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
19
|
+
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
20
|
+
getControlEl: (ctx) => dom.queryById(ctx, dom.getControlId(ctx)),
|
|
21
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
22
|
+
getValueFromPoint(ctx, point) {
|
|
23
|
+
const relativePoint = getRelativePoint(point, dom.getControlEl(ctx));
|
|
24
|
+
const percent = relativePoint.getPercentValue({
|
|
25
|
+
orientation: ctx.orientation,
|
|
26
|
+
dir: ctx.dir,
|
|
27
|
+
inverted: { y: true }
|
|
28
|
+
});
|
|
29
|
+
return getPercentValue(percent, ctx.min, ctx.max, ctx.step);
|
|
30
|
+
},
|
|
31
|
+
dispatchChangeEvent(ctx) {
|
|
32
|
+
const input = dom.getHiddenInputEl(ctx);
|
|
33
|
+
if (!input)
|
|
34
|
+
return;
|
|
35
|
+
dispatchInputValueEvent(input, { value: ctx.value });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export { dom };
|
package/dist/slider.machine.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
2
|
+
import type { MachineContext, MachineState, UserDefinedContext } from "./slider.types";
|
|
3
|
+
export declare function machine(userContext: UserDefinedContext): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|