@zag-js/radio-group 1.27.0 → 1.28.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 +2 -12
- package/dist/index.d.ts +2 -12
- package/dist/index.js +17 -33
- package/dist/index.mjs +18 -34
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
-
import { RequiredBy, DirectionProperty, CommonProperties, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { RequiredBy, DirectionProperty, CommonProperties, Rect, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
3
3
|
import * as _zag_js_core from '@zag-js/core';
|
|
4
4
|
import { Service, EventObject, Machine } from '@zag-js/core';
|
|
5
5
|
|
|
@@ -57,12 +57,6 @@ interface RadioGroupProps extends DirectionProperty, CommonProperties {
|
|
|
57
57
|
*/
|
|
58
58
|
orientation?: "horizontal" | "vertical" | undefined;
|
|
59
59
|
}
|
|
60
|
-
interface IndicatorRect {
|
|
61
|
-
left: string;
|
|
62
|
-
top: string;
|
|
63
|
-
width: string;
|
|
64
|
-
height: string;
|
|
65
|
-
}
|
|
66
60
|
interface PrivateContext {
|
|
67
61
|
/**
|
|
68
62
|
* The value of the checked radio
|
|
@@ -83,11 +77,7 @@ interface PrivateContext {
|
|
|
83
77
|
/**
|
|
84
78
|
* The active tab indicator's dom rect
|
|
85
79
|
*/
|
|
86
|
-
indicatorRect:
|
|
87
|
-
/**
|
|
88
|
-
* Whether the active tab indicator's rect can transition
|
|
89
|
-
*/
|
|
90
|
-
canIndicatorTransition: boolean;
|
|
80
|
+
indicatorRect: Rect | null;
|
|
91
81
|
/**
|
|
92
82
|
* Whether the radio group's fieldset is disabled
|
|
93
83
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
-
import { RequiredBy, DirectionProperty, CommonProperties, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { RequiredBy, DirectionProperty, CommonProperties, Rect, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
3
3
|
import * as _zag_js_core from '@zag-js/core';
|
|
4
4
|
import { Service, EventObject, Machine } from '@zag-js/core';
|
|
5
5
|
|
|
@@ -57,12 +57,6 @@ interface RadioGroupProps extends DirectionProperty, CommonProperties {
|
|
|
57
57
|
*/
|
|
58
58
|
orientation?: "horizontal" | "vertical" | undefined;
|
|
59
59
|
}
|
|
60
|
-
interface IndicatorRect {
|
|
61
|
-
left: string;
|
|
62
|
-
top: string;
|
|
63
|
-
width: string;
|
|
64
|
-
height: string;
|
|
65
|
-
}
|
|
66
60
|
interface PrivateContext {
|
|
67
61
|
/**
|
|
68
62
|
* The value of the checked radio
|
|
@@ -83,11 +77,7 @@ interface PrivateContext {
|
|
|
83
77
|
/**
|
|
84
78
|
* The active tab indicator's dom rect
|
|
85
79
|
*/
|
|
86
|
-
indicatorRect:
|
|
87
|
-
/**
|
|
88
|
-
* Whether the active tab indicator's rect can transition
|
|
89
|
-
*/
|
|
90
|
-
canIndicatorTransition: boolean;
|
|
80
|
+
indicatorRect: Rect | null;
|
|
91
81
|
/**
|
|
92
82
|
* Whether the radio group's fieldset is disabled
|
|
93
83
|
*/
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var anatomy$1 = require('@zag-js/anatomy');
|
|
4
4
|
var domQuery = require('@zag-js/dom-query');
|
|
5
5
|
var focusVisible = require('@zag-js/focus-visible');
|
|
6
|
-
var core = require('@zag-js/core');
|
|
7
6
|
var utils = require('@zag-js/utils');
|
|
7
|
+
var core = require('@zag-js/core');
|
|
8
8
|
var types = require('@zag-js/types');
|
|
9
9
|
|
|
10
10
|
// src/radio-group.anatomy.ts
|
|
@@ -39,17 +39,11 @@ var getRadioEl = (ctx, value) => {
|
|
|
39
39
|
return ctx.getById(getItemId(ctx, value));
|
|
40
40
|
};
|
|
41
41
|
var getOffsetRect = (el) => ({
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
x: el?.offsetLeft ?? 0,
|
|
43
|
+
y: el?.offsetTop ?? 0,
|
|
44
44
|
width: el?.offsetWidth ?? 0,
|
|
45
45
|
height: el?.offsetHeight ?? 0
|
|
46
46
|
});
|
|
47
|
-
var resolveRect = (rect) => ({
|
|
48
|
-
width: `${rect.width}px`,
|
|
49
|
-
height: `${rect.height}px`,
|
|
50
|
-
left: `${rect.left}px`,
|
|
51
|
-
top: `${rect.top}px`
|
|
52
|
-
});
|
|
53
47
|
|
|
54
48
|
// src/radio-group.connect.ts
|
|
55
49
|
function connect(service, normalize) {
|
|
@@ -224,19 +218,19 @@ function connect(service, normalize) {
|
|
|
224
218
|
id: getIndicatorId(scope),
|
|
225
219
|
...parts.indicator.attrs,
|
|
226
220
|
dir: prop("dir"),
|
|
227
|
-
hidden: context.get("value") == null,
|
|
221
|
+
hidden: context.get("value") == null || rect == null,
|
|
228
222
|
"data-disabled": domQuery.dataAttr(groupDisabled),
|
|
229
223
|
"data-orientation": prop("orientation"),
|
|
230
224
|
style: {
|
|
231
225
|
"--transition-property": "left, top, width, height",
|
|
232
|
-
"--left": rect?.
|
|
233
|
-
"--top": rect?.
|
|
234
|
-
"--width": rect?.width,
|
|
235
|
-
"--height": rect?.height,
|
|
226
|
+
"--left": utils.toPx(rect?.x),
|
|
227
|
+
"--top": utils.toPx(rect?.y),
|
|
228
|
+
"--width": utils.toPx(rect?.width),
|
|
229
|
+
"--height": utils.toPx(rect?.height),
|
|
236
230
|
position: "absolute",
|
|
237
231
|
willChange: "var(--transition-property)",
|
|
238
232
|
transitionProperty: "var(--transition-property)",
|
|
239
|
-
transitionDuration:
|
|
233
|
+
transitionDuration: "var(--transition-duration, 150ms)",
|
|
240
234
|
transitionTimingFunction: "var(--transition-timing-function)",
|
|
241
235
|
[prop("orientation") === "horizontal" ? "left" : "top"]: prop("orientation") === "horizontal" ? "var(--left)" : "var(--top)"
|
|
242
236
|
}
|
|
@@ -274,10 +268,7 @@ var machine = core.createMachine({
|
|
|
274
268
|
defaultValue: null
|
|
275
269
|
})),
|
|
276
270
|
indicatorRect: bindable(() => ({
|
|
277
|
-
defaultValue:
|
|
278
|
-
})),
|
|
279
|
-
canIndicatorTransition: bindable(() => ({
|
|
280
|
-
defaultValue: false
|
|
271
|
+
defaultValue: null
|
|
281
272
|
})),
|
|
282
273
|
fieldsetDisabled: bindable(() => ({
|
|
283
274
|
defaultValue: false
|
|
@@ -301,7 +292,7 @@ var machine = core.createMachine({
|
|
|
301
292
|
effects: ["trackFormControlState", "trackFocusVisible"],
|
|
302
293
|
watch({ track, action, context }) {
|
|
303
294
|
track([() => context.get("value")], () => {
|
|
304
|
-
action(["
|
|
295
|
+
action(["syncIndicatorRect", "syncInputElements"]);
|
|
305
296
|
});
|
|
306
297
|
},
|
|
307
298
|
on: {
|
|
@@ -366,9 +357,6 @@ var machine = core.createMachine({
|
|
|
366
357
|
input.checked = input.value === context.get("value");
|
|
367
358
|
});
|
|
368
359
|
},
|
|
369
|
-
setIndicatorTransition({ context }) {
|
|
370
|
-
context.set("canIndicatorTransition", utils.isString(context.get("value")));
|
|
371
|
-
},
|
|
372
360
|
cleanupObserver({ refs }) {
|
|
373
361
|
refs.get("indicatorCleanup")?.();
|
|
374
362
|
},
|
|
@@ -381,18 +369,14 @@ var machine = core.createMachine({
|
|
|
381
369
|
const value = context.get("value");
|
|
382
370
|
const radioEl = getRadioEl(scope, value);
|
|
383
371
|
if (value == null || !radioEl) {
|
|
384
|
-
context.set("
|
|
385
|
-
context.set("indicatorRect", {});
|
|
372
|
+
context.set("indicatorRect", null);
|
|
386
373
|
return;
|
|
387
374
|
}
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
context.set("indicatorRect", resolveRect(rects[0]));
|
|
394
|
-
}
|
|
395
|
-
});
|
|
375
|
+
const exec = () => {
|
|
376
|
+
context.set("indicatorRect", getOffsetRect(radioEl));
|
|
377
|
+
};
|
|
378
|
+
exec();
|
|
379
|
+
const indicatorCleanup = domQuery.resizeObserverBorderBox.observe(radioEl, exec);
|
|
396
380
|
refs.set("indicatorCleanup", indicatorCleanup);
|
|
397
381
|
},
|
|
398
382
|
dispatchChangeEvent({ context, scope }) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
|
-
import { dispatchInputCheckedEvent,
|
|
2
|
+
import { dispatchInputCheckedEvent, resizeObserverBorderBox, trackFormControl, queryAll, dataAttr, visuallyHiddenStyle, isSafari, isLeftClick } from '@zag-js/dom-query';
|
|
3
3
|
import { trackFocusVisible, isFocusVisible } from '@zag-js/focus-visible';
|
|
4
|
+
import { createSplitProps, toPx } from '@zag-js/utils';
|
|
4
5
|
import { createGuards, createMachine } from '@zag-js/core';
|
|
5
|
-
import { isString, createSplitProps } from '@zag-js/utils';
|
|
6
6
|
import { createProps } from '@zag-js/types';
|
|
7
7
|
|
|
8
8
|
// src/radio-group.anatomy.ts
|
|
@@ -37,17 +37,11 @@ var getRadioEl = (ctx, value) => {
|
|
|
37
37
|
return ctx.getById(getItemId(ctx, value));
|
|
38
38
|
};
|
|
39
39
|
var getOffsetRect = (el) => ({
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
x: el?.offsetLeft ?? 0,
|
|
41
|
+
y: el?.offsetTop ?? 0,
|
|
42
42
|
width: el?.offsetWidth ?? 0,
|
|
43
43
|
height: el?.offsetHeight ?? 0
|
|
44
44
|
});
|
|
45
|
-
var resolveRect = (rect) => ({
|
|
46
|
-
width: `${rect.width}px`,
|
|
47
|
-
height: `${rect.height}px`,
|
|
48
|
-
left: `${rect.left}px`,
|
|
49
|
-
top: `${rect.top}px`
|
|
50
|
-
});
|
|
51
45
|
|
|
52
46
|
// src/radio-group.connect.ts
|
|
53
47
|
function connect(service, normalize) {
|
|
@@ -222,19 +216,19 @@ function connect(service, normalize) {
|
|
|
222
216
|
id: getIndicatorId(scope),
|
|
223
217
|
...parts.indicator.attrs,
|
|
224
218
|
dir: prop("dir"),
|
|
225
|
-
hidden: context.get("value") == null,
|
|
219
|
+
hidden: context.get("value") == null || rect == null,
|
|
226
220
|
"data-disabled": dataAttr(groupDisabled),
|
|
227
221
|
"data-orientation": prop("orientation"),
|
|
228
222
|
style: {
|
|
229
223
|
"--transition-property": "left, top, width, height",
|
|
230
|
-
"--left": rect?.
|
|
231
|
-
"--top": rect?.
|
|
232
|
-
"--width": rect?.width,
|
|
233
|
-
"--height": rect?.height,
|
|
224
|
+
"--left": toPx(rect?.x),
|
|
225
|
+
"--top": toPx(rect?.y),
|
|
226
|
+
"--width": toPx(rect?.width),
|
|
227
|
+
"--height": toPx(rect?.height),
|
|
234
228
|
position: "absolute",
|
|
235
229
|
willChange: "var(--transition-property)",
|
|
236
230
|
transitionProperty: "var(--transition-property)",
|
|
237
|
-
transitionDuration:
|
|
231
|
+
transitionDuration: "var(--transition-duration, 150ms)",
|
|
238
232
|
transitionTimingFunction: "var(--transition-timing-function)",
|
|
239
233
|
[prop("orientation") === "horizontal" ? "left" : "top"]: prop("orientation") === "horizontal" ? "var(--left)" : "var(--top)"
|
|
240
234
|
}
|
|
@@ -272,10 +266,7 @@ var machine = createMachine({
|
|
|
272
266
|
defaultValue: null
|
|
273
267
|
})),
|
|
274
268
|
indicatorRect: bindable(() => ({
|
|
275
|
-
defaultValue:
|
|
276
|
-
})),
|
|
277
|
-
canIndicatorTransition: bindable(() => ({
|
|
278
|
-
defaultValue: false
|
|
269
|
+
defaultValue: null
|
|
279
270
|
})),
|
|
280
271
|
fieldsetDisabled: bindable(() => ({
|
|
281
272
|
defaultValue: false
|
|
@@ -299,7 +290,7 @@ var machine = createMachine({
|
|
|
299
290
|
effects: ["trackFormControlState", "trackFocusVisible"],
|
|
300
291
|
watch({ track, action, context }) {
|
|
301
292
|
track([() => context.get("value")], () => {
|
|
302
|
-
action(["
|
|
293
|
+
action(["syncIndicatorRect", "syncInputElements"]);
|
|
303
294
|
});
|
|
304
295
|
},
|
|
305
296
|
on: {
|
|
@@ -364,9 +355,6 @@ var machine = createMachine({
|
|
|
364
355
|
input.checked = input.value === context.get("value");
|
|
365
356
|
});
|
|
366
357
|
},
|
|
367
|
-
setIndicatorTransition({ context }) {
|
|
368
|
-
context.set("canIndicatorTransition", isString(context.get("value")));
|
|
369
|
-
},
|
|
370
358
|
cleanupObserver({ refs }) {
|
|
371
359
|
refs.get("indicatorCleanup")?.();
|
|
372
360
|
},
|
|
@@ -379,18 +367,14 @@ var machine = createMachine({
|
|
|
379
367
|
const value = context.get("value");
|
|
380
368
|
const radioEl = getRadioEl(scope, value);
|
|
381
369
|
if (value == null || !radioEl) {
|
|
382
|
-
context.set("
|
|
383
|
-
context.set("indicatorRect", {});
|
|
370
|
+
context.set("indicatorRect", null);
|
|
384
371
|
return;
|
|
385
372
|
}
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
context.set("indicatorRect", resolveRect(rects[0]));
|
|
392
|
-
}
|
|
393
|
-
});
|
|
373
|
+
const exec = () => {
|
|
374
|
+
context.set("indicatorRect", getOffsetRect(radioEl));
|
|
375
|
+
};
|
|
376
|
+
exec();
|
|
377
|
+
const indicatorCleanup = resizeObserverBorderBox.observe(radioEl, exec);
|
|
394
378
|
refs.set("indicatorCleanup", indicatorCleanup);
|
|
395
379
|
},
|
|
396
380
|
dispatchChangeEvent({ context, scope }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/radio-group",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "Core logic for the radio group widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/anatomy": "1.
|
|
31
|
-
"@zag-js/dom-query": "1.
|
|
32
|
-
"@zag-js/focus-visible": "1.
|
|
33
|
-
"@zag-js/utils": "1.
|
|
34
|
-
"@zag-js/core": "1.
|
|
35
|
-
"@zag-js/types": "1.
|
|
30
|
+
"@zag-js/anatomy": "1.28.0",
|
|
31
|
+
"@zag-js/dom-query": "1.28.0",
|
|
32
|
+
"@zag-js/focus-visible": "1.28.0",
|
|
33
|
+
"@zag-js/utils": "1.28.0",
|
|
34
|
+
"@zag-js/core": "1.28.0",
|
|
35
|
+
"@zag-js/types": "1.28.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"clean-package": "2.2.0"
|