@zag-js/radio-group 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 +4 -7
- package/dist/index.js +8 -422
- package/dist/index.mjs +3 -15
- package/dist/radio-group.anatomy.d.ts +3 -6
- package/dist/radio-group.anatomy.js +10 -33
- package/dist/radio-group.anatomy.mjs +14 -8
- package/dist/radio-group.connect.d.ts +3 -7
- package/dist/radio-group.connect.js +43 -125
- package/dist/radio-group.connect.mjs +209 -8
- package/dist/radio-group.dom.d.ts +17 -22
- package/dist/radio-group.dom.js +9 -31
- package/dist/radio-group.dom.mjs +48 -6
- package/dist/radio-group.machine.d.ts +3 -7
- package/dist/radio-group.machine.js +21 -95
- package/dist/radio-group.machine.mjs +124 -7
- package/dist/radio-group.types.d.ts +10 -12
- package/package.json +10 -15
- package/src/radio-group.machine.ts +1 -5
- package/src/radio-group.types.ts +0 -5
- package/dist/chunk-DM5GVJFW.mjs +0 -216
- package/dist/chunk-DVMAGSYZ.mjs +0 -50
- package/dist/chunk-R5YJZPCP.mjs +0 -17
- package/dist/chunk-UMCKI3BN.mjs +0 -133
- package/dist/radio-group.types.js +0 -18
- package/dist/radio-group.types.mjs +0 -0
package/dist/chunk-DVMAGSYZ.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/radio-group.dom.ts
|
|
2
|
-
import { createScope, queryAll } from "@zag-js/dom-query";
|
|
3
|
-
var dom = createScope({
|
|
4
|
-
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
5
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
6
|
-
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
7
|
-
getRadioInputId: (ctx, value) => ctx.ids?.radioInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
|
|
8
|
-
getRadioControlId: (ctx, value) => ctx.ids?.radioControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
|
|
9
|
-
getRadioLabelId: (ctx, value) => ctx.ids?.radioLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
|
|
10
|
-
getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
|
|
11
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
12
|
-
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
13
|
-
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
14
|
-
getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
|
|
15
|
-
getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
|
|
16
|
-
getInputEls: (ctx) => {
|
|
17
|
-
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
18
|
-
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
19
|
-
return queryAll(dom.getRootEl(ctx), selector);
|
|
20
|
-
},
|
|
21
|
-
getActiveRadioEl: (ctx) => {
|
|
22
|
-
if (!ctx.value)
|
|
23
|
-
return;
|
|
24
|
-
return dom.getById(ctx, dom.getRadioId(ctx, ctx.value));
|
|
25
|
-
},
|
|
26
|
-
getOffsetRect: (el) => {
|
|
27
|
-
return {
|
|
28
|
-
left: el?.offsetLeft ?? 0,
|
|
29
|
-
top: el?.offsetTop ?? 0,
|
|
30
|
-
width: el?.offsetWidth ?? 0,
|
|
31
|
-
height: el?.offsetHeight ?? 0
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
getRectById: (ctx, id) => {
|
|
35
|
-
const tab = dom.queryById(ctx, dom.getRadioId(ctx, id));
|
|
36
|
-
return dom.resolveRect(dom.getOffsetRect(tab));
|
|
37
|
-
},
|
|
38
|
-
resolveRect(rect) {
|
|
39
|
-
return {
|
|
40
|
-
width: `${rect.width}px`,
|
|
41
|
-
height: `${rect.height}px`,
|
|
42
|
-
left: `${rect.left}px`,
|
|
43
|
-
top: `${rect.top}px`
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
dom
|
|
50
|
-
};
|
package/dist/chunk-R5YJZPCP.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/radio-group.anatomy.ts
|
|
2
|
-
import { createAnatomy } from "@zag-js/anatomy";
|
|
3
|
-
var anatomy = createAnatomy("radio-group").parts(
|
|
4
|
-
"root",
|
|
5
|
-
"label",
|
|
6
|
-
"radio",
|
|
7
|
-
"radioLabel",
|
|
8
|
-
"radioControl",
|
|
9
|
-
"radioInput",
|
|
10
|
-
"indicator"
|
|
11
|
-
);
|
|
12
|
-
var parts = anatomy.build();
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
anatomy,
|
|
16
|
-
parts
|
|
17
|
-
};
|
package/dist/chunk-UMCKI3BN.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
dom
|
|
3
|
-
} from "./chunk-DVMAGSYZ.mjs";
|
|
4
|
-
|
|
5
|
-
// src/radio-group.machine.ts
|
|
6
|
-
import { createMachine } from "@zag-js/core";
|
|
7
|
-
import { nextTick } from "@zag-js/dom-query";
|
|
8
|
-
import { trackElementRect } from "@zag-js/element-rect";
|
|
9
|
-
import { trackFormControl } from "@zag-js/form-utils";
|
|
10
|
-
import { compact, isString } from "@zag-js/utils";
|
|
11
|
-
function machine(userContext) {
|
|
12
|
-
const ctx = compact(userContext);
|
|
13
|
-
return createMachine(
|
|
14
|
-
{
|
|
15
|
-
id: "radio",
|
|
16
|
-
initial: "idle",
|
|
17
|
-
context: {
|
|
18
|
-
previousValue: null,
|
|
19
|
-
value: null,
|
|
20
|
-
activeId: null,
|
|
21
|
-
focusedId: null,
|
|
22
|
-
hoveredId: null,
|
|
23
|
-
indicatorRect: {},
|
|
24
|
-
canIndicatorTransition: false,
|
|
25
|
-
...ctx
|
|
26
|
-
},
|
|
27
|
-
entry: ["syncIndicatorRect"],
|
|
28
|
-
exit: ["cleanupObserver"],
|
|
29
|
-
activities: ["trackFormControlState"],
|
|
30
|
-
watch: {
|
|
31
|
-
value: [
|
|
32
|
-
"setIndicatorTransition",
|
|
33
|
-
// important to set this after `setIndicatorTransition`
|
|
34
|
-
"setPreviousValue",
|
|
35
|
-
"invokeOnChange",
|
|
36
|
-
"syncIndicatorRect",
|
|
37
|
-
"syncInputElements"
|
|
38
|
-
]
|
|
39
|
-
},
|
|
40
|
-
on: {
|
|
41
|
-
SET_VALUE: {
|
|
42
|
-
actions: ["setValue"]
|
|
43
|
-
},
|
|
44
|
-
SET_HOVERED: {
|
|
45
|
-
actions: "setHovered"
|
|
46
|
-
},
|
|
47
|
-
SET_ACTIVE: {
|
|
48
|
-
actions: "setActive"
|
|
49
|
-
},
|
|
50
|
-
SET_FOCUSED: {
|
|
51
|
-
actions: "setFocused"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
states: {
|
|
55
|
-
idle: {}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
activities: {
|
|
60
|
-
trackFormControlState(ctx2, _evt, { send, initialContext }) {
|
|
61
|
-
return trackFormControl(dom.getRootEl(ctx2), {
|
|
62
|
-
onFieldsetDisabled() {
|
|
63
|
-
ctx2.disabled = true;
|
|
64
|
-
},
|
|
65
|
-
onFormReset() {
|
|
66
|
-
send({ type: "SET_VALUE", value: initialContext.value });
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
actions: {
|
|
72
|
-
setValue(ctx2, evt) {
|
|
73
|
-
ctx2.value = evt.value;
|
|
74
|
-
},
|
|
75
|
-
setHovered(ctx2, evt) {
|
|
76
|
-
ctx2.hoveredId = evt.value;
|
|
77
|
-
},
|
|
78
|
-
setActive(ctx2, evt) {
|
|
79
|
-
ctx2.activeId = evt.value;
|
|
80
|
-
},
|
|
81
|
-
setFocused(ctx2, evt) {
|
|
82
|
-
ctx2.focusedId = evt.value;
|
|
83
|
-
},
|
|
84
|
-
invokeOnChange(ctx2, evt) {
|
|
85
|
-
ctx2.onChange?.({ value: evt.value });
|
|
86
|
-
},
|
|
87
|
-
syncInputElements(ctx2) {
|
|
88
|
-
const inputs = dom.getInputEls(ctx2);
|
|
89
|
-
inputs.forEach((input) => {
|
|
90
|
-
input.checked = input.value === ctx2.value;
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
setPreviousValue(ctx2) {
|
|
94
|
-
ctx2.previousValue = ctx2.value;
|
|
95
|
-
},
|
|
96
|
-
setIndicatorTransition(ctx2) {
|
|
97
|
-
ctx2.canIndicatorTransition = isString(ctx2.previousValue) && isString(ctx2.value);
|
|
98
|
-
},
|
|
99
|
-
cleanupObserver(ctx2) {
|
|
100
|
-
ctx2.indicatorCleanup?.();
|
|
101
|
-
},
|
|
102
|
-
syncIndicatorRect(ctx2) {
|
|
103
|
-
ctx2.indicatorCleanup?.();
|
|
104
|
-
if (!dom.getIndicatorEl(ctx2))
|
|
105
|
-
return;
|
|
106
|
-
const value = ctx2.value;
|
|
107
|
-
if (value == null) {
|
|
108
|
-
ctx2.indicatorRect = {};
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const radioEl = dom.getActiveRadioEl(ctx2);
|
|
112
|
-
if (!radioEl)
|
|
113
|
-
return;
|
|
114
|
-
ctx2.indicatorCleanup = trackElementRect(radioEl, {
|
|
115
|
-
getRect(el) {
|
|
116
|
-
return dom.getOffsetRect(el);
|
|
117
|
-
},
|
|
118
|
-
onChange(rect) {
|
|
119
|
-
ctx2.indicatorRect = dom.resolveRect(rect);
|
|
120
|
-
nextTick(() => {
|
|
121
|
-
ctx2.canIndicatorTransition = false;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export {
|
|
132
|
-
machine
|
|
133
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/radio-group.types.ts
|
|
17
|
-
var radio_group_types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(radio_group_types_exports);
|
|
File without changes
|