@zag-js/slider 0.0.0-dev-20220617070002 → 0.0.0-dev-20220626173054
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.js +7 -4
- package/dist/index.mjs +7 -4
- package/dist/slider.types.d.ts +7 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -209,9 +209,7 @@ function trackFieldsetDisabled(el, callback) {
|
|
|
209
209
|
function getDescriptor(el, options) {
|
|
210
210
|
var _a;
|
|
211
211
|
const { type, property } = options;
|
|
212
|
-
const
|
|
213
|
-
const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
|
|
214
|
-
const proto = win[_type].prototype;
|
|
212
|
+
const proto = getOwnerWindow(el)[type].prototype;
|
|
215
213
|
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
216
214
|
}
|
|
217
215
|
function dispatchInputValueEvent(el, value) {
|
|
@@ -219,7 +217,7 @@ function dispatchInputValueEvent(el, value) {
|
|
|
219
217
|
const win = getOwnerWindow(el);
|
|
220
218
|
if (!(el instanceof win.HTMLInputElement))
|
|
221
219
|
return;
|
|
222
|
-
const desc = getDescriptor(el, { type: "
|
|
220
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
223
221
|
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
224
222
|
const event = new win.Event("input", { bubbles: true });
|
|
225
223
|
el.dispatchEvent(event);
|
|
@@ -423,6 +421,8 @@ function getHorizontalThumbOffset(ctx) {
|
|
|
423
421
|
}
|
|
424
422
|
function getThumbOffset(ctx) {
|
|
425
423
|
const percent = valueToPercent(ctx.value, ctx);
|
|
424
|
+
if (ctx.thumbAlignment === "center")
|
|
425
|
+
return `${percent}%`;
|
|
426
426
|
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
427
427
|
return `calc(${percent}% - ${offset}px)`;
|
|
428
428
|
}
|
|
@@ -829,6 +829,7 @@ function machine(ctx = {}) {
|
|
|
829
829
|
initial: "unknown",
|
|
830
830
|
context: __spreadValues({
|
|
831
831
|
thumbSize: null,
|
|
832
|
+
thumbAlignment: "contain",
|
|
832
833
|
uid: "",
|
|
833
834
|
disabled: false,
|
|
834
835
|
threshold: 5,
|
|
@@ -1001,6 +1002,8 @@ function machine(ctx = {}) {
|
|
|
1001
1002
|
dom.dispatchChangeEvent(ctx2);
|
|
1002
1003
|
},
|
|
1003
1004
|
setThumbSize(ctx2) {
|
|
1005
|
+
if (ctx2.thumbAlignment !== "contain")
|
|
1006
|
+
return;
|
|
1004
1007
|
raf(() => {
|
|
1005
1008
|
const el = dom.getThumbEl(ctx2);
|
|
1006
1009
|
if (!el)
|
package/dist/index.mjs
CHANGED
|
@@ -185,9 +185,7 @@ function trackFieldsetDisabled(el, callback) {
|
|
|
185
185
|
function getDescriptor(el, options) {
|
|
186
186
|
var _a;
|
|
187
187
|
const { type, property } = options;
|
|
188
|
-
const
|
|
189
|
-
const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
|
|
190
|
-
const proto = win[_type].prototype;
|
|
188
|
+
const proto = getOwnerWindow(el)[type].prototype;
|
|
191
189
|
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
192
190
|
}
|
|
193
191
|
function dispatchInputValueEvent(el, value) {
|
|
@@ -195,7 +193,7 @@ function dispatchInputValueEvent(el, value) {
|
|
|
195
193
|
const win = getOwnerWindow(el);
|
|
196
194
|
if (!(el instanceof win.HTMLInputElement))
|
|
197
195
|
return;
|
|
198
|
-
const desc = getDescriptor(el, { type: "
|
|
196
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
199
197
|
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
200
198
|
const event = new win.Event("input", { bubbles: true });
|
|
201
199
|
el.dispatchEvent(event);
|
|
@@ -399,6 +397,8 @@ function getHorizontalThumbOffset(ctx) {
|
|
|
399
397
|
}
|
|
400
398
|
function getThumbOffset(ctx) {
|
|
401
399
|
const percent = valueToPercent(ctx.value, ctx);
|
|
400
|
+
if (ctx.thumbAlignment === "center")
|
|
401
|
+
return `${percent}%`;
|
|
402
402
|
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
403
403
|
return `calc(${percent}% - ${offset}px)`;
|
|
404
404
|
}
|
|
@@ -805,6 +805,7 @@ function machine(ctx = {}) {
|
|
|
805
805
|
initial: "unknown",
|
|
806
806
|
context: __spreadValues({
|
|
807
807
|
thumbSize: null,
|
|
808
|
+
thumbAlignment: "contain",
|
|
808
809
|
uid: "",
|
|
809
810
|
disabled: false,
|
|
810
811
|
threshold: 5,
|
|
@@ -977,6 +978,8 @@ function machine(ctx = {}) {
|
|
|
977
978
|
dom.dispatchChangeEvent(ctx2);
|
|
978
979
|
},
|
|
979
980
|
setThumbSize(ctx2) {
|
|
981
|
+
if (ctx2.thumbAlignment !== "contain")
|
|
982
|
+
return;
|
|
980
983
|
raf(() => {
|
|
981
984
|
const el = dom.getThumbEl(ctx2);
|
|
982
985
|
if (!el)
|
package/dist/slider.types.d.ts
CHANGED
|
@@ -89,6 +89,12 @@ declare type PublicContext = DirectionProperty & {
|
|
|
89
89
|
onChangeStart?(details: {
|
|
90
90
|
value: number;
|
|
91
91
|
}): void;
|
|
92
|
+
/**
|
|
93
|
+
* The alignment of the slider thumb relative to the track
|
|
94
|
+
* - `center`: the thumb will extend beyond the bounds of the slider track.
|
|
95
|
+
* - `contain`: the thumb will be contained within the bounds of the track.
|
|
96
|
+
*/
|
|
97
|
+
thumbAlignment?: "contain" | "center";
|
|
92
98
|
};
|
|
93
99
|
export declare type UserDefinedContext = Partial<PublicContext>;
|
|
94
100
|
declare type ComputedContext = Readonly<{
|
|
@@ -156,6 +162,7 @@ export declare type SharedContext = {
|
|
|
156
162
|
width: number;
|
|
157
163
|
height: number;
|
|
158
164
|
} | null;
|
|
165
|
+
thumbAlignment?: "contain" | "center";
|
|
159
166
|
orientation?: "horizontal" | "vertical";
|
|
160
167
|
readonly hasMeasuredThumbSize: boolean;
|
|
161
168
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/slider",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220626173054",
|
|
4
4
|
"description": "Core logic for the slider widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.
|
|
33
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
32
|
+
"@zag-js/core": "0.0.0-dev-20220626173054",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220626173054",
|
|
34
34
|
"@zag-js/number-utils": "0.1.2",
|
|
35
35
|
"@zag-js/rect-utils": "0.1.2",
|
|
36
|
-
"@zag-js/types": "0.
|
|
36
|
+
"@zag-js/types": "0.2.0",
|
|
37
37
|
"@zag-js/utils": "0.1.2"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|