@zag-js/radio-group 0.1.6 → 0.1.8
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/chunk-FMPH6XGK.mjs +197 -0
- package/dist/chunk-JED7REAH.mjs +192 -0
- package/dist/chunk-MGLN5L3R.mjs +16 -0
- package/dist/chunk-WSYVDFNO.mjs +92 -0
- package/dist/index.d.ts +7 -951
- package/dist/index.js +45 -51
- package/dist/index.mjs +10 -476
- package/dist/radio-group.anatomy.d.ts +6 -0
- package/dist/radio-group.anatomy.js +41 -0
- package/dist/radio-group.anatomy.mjs +8 -0
- package/dist/radio-group.connect.d.ts +18 -0
- package/dist/radio-group.connect.js +312 -0
- package/dist/radio-group.connect.mjs +8 -0
- package/dist/radio-group.dom.d.ts +35 -0
- package/dist/radio-group.dom.js +113 -0
- package/dist/radio-group.dom.mjs +6 -0
- package/dist/radio-group.machine.d.ts +7 -0
- package/dist/radio-group.machine.js +299 -0
- package/dist/radio-group.machine.mjs +7 -0
- package/dist/radio-group.types.d.ts +86 -0
- package/dist/radio-group.types.js +18 -0
- package/dist/radio-group.types.mjs +0 -0
- package/package.json +22 -12
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { State, Send, RadioProps, InputProps } from './radio-group.types.js';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
value: string | null;
|
|
7
|
+
setValue(value: string): void;
|
|
8
|
+
focus: () => void;
|
|
9
|
+
blur(): void;
|
|
10
|
+
rootProps: T["element"];
|
|
11
|
+
labelProps: T["element"];
|
|
12
|
+
getRadioProps(props: RadioProps): T["label"];
|
|
13
|
+
getRadioLabelProps(props: RadioProps): T["element"];
|
|
14
|
+
getRadioControlProps(props: RadioProps): T["element"];
|
|
15
|
+
getRadioInputProps(props: InputProps): T["input"];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { connect };
|
|
@@ -0,0 +1,312 @@
|
|
|
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 __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);
|
|
19
|
+
|
|
20
|
+
// src/radio-group.connect.ts
|
|
21
|
+
var radio_group_connect_exports = {};
|
|
22
|
+
__export(radio_group_connect_exports, {
|
|
23
|
+
connect: () => connect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(radio_group_connect_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/attrs.ts
|
|
28
|
+
var dataAttr = (guard) => {
|
|
29
|
+
return guard ? "" : void 0;
|
|
30
|
+
};
|
|
31
|
+
var ariaAttr = (guard) => {
|
|
32
|
+
return guard ? "true" : void 0;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// ../../utilities/dom/src/query.ts
|
|
36
|
+
function isDocument(el) {
|
|
37
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
38
|
+
}
|
|
39
|
+
function isWindow(value) {
|
|
40
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
41
|
+
}
|
|
42
|
+
function getDocument(el) {
|
|
43
|
+
var _a;
|
|
44
|
+
if (isWindow(el))
|
|
45
|
+
return el.document;
|
|
46
|
+
if (isDocument(el))
|
|
47
|
+
return el;
|
|
48
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
49
|
+
}
|
|
50
|
+
function defineDomHelpers(helpers) {
|
|
51
|
+
const dom2 = {
|
|
52
|
+
getRootNode: (ctx) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
55
|
+
},
|
|
56
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
57
|
+
getWin: (ctx) => {
|
|
58
|
+
var _a;
|
|
59
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
60
|
+
},
|
|
61
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
62
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
...dom2,
|
|
66
|
+
...helpers
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
71
|
+
function queryAll(root, selector) {
|
|
72
|
+
var _a;
|
|
73
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ../../utilities/dom/src/visually-hidden.ts
|
|
77
|
+
var visuallyHiddenStyle = {
|
|
78
|
+
border: "0",
|
|
79
|
+
clip: "rect(0 0 0 0)",
|
|
80
|
+
height: "1px",
|
|
81
|
+
margin: "-1px",
|
|
82
|
+
overflow: "hidden",
|
|
83
|
+
padding: "0",
|
|
84
|
+
position: "absolute",
|
|
85
|
+
width: "1px",
|
|
86
|
+
whiteSpace: "nowrap",
|
|
87
|
+
wordWrap: "normal"
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/radio-group.anatomy.ts
|
|
91
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
92
|
+
var anatomy = (0, import_anatomy.createAnatomy)("radio-group").parts(
|
|
93
|
+
"root",
|
|
94
|
+
"label",
|
|
95
|
+
"radio",
|
|
96
|
+
"radioLabel",
|
|
97
|
+
"radioControl",
|
|
98
|
+
"radioInput"
|
|
99
|
+
);
|
|
100
|
+
var parts = anatomy.build();
|
|
101
|
+
|
|
102
|
+
// src/radio-group.dom.ts
|
|
103
|
+
var dom = defineDomHelpers({
|
|
104
|
+
getRootId: (ctx) => {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `radio-group:${ctx.id}`;
|
|
107
|
+
},
|
|
108
|
+
getLabelId: (ctx) => {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
111
|
+
},
|
|
112
|
+
getRadioId: (ctx, value) => {
|
|
113
|
+
var _a, _b, _c;
|
|
114
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radio) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:${value}`;
|
|
115
|
+
},
|
|
116
|
+
getRadioInputId: (ctx, value) => {
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioInput) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:input:${value}`;
|
|
119
|
+
},
|
|
120
|
+
getRadioControlId: (ctx, value) => {
|
|
121
|
+
var _a, _b, _c;
|
|
122
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioControl) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:control:${value}`;
|
|
123
|
+
},
|
|
124
|
+
getRadioLabelId: (ctx, value) => {
|
|
125
|
+
var _a, _b, _c;
|
|
126
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioLabel) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:label:${value}`;
|
|
127
|
+
},
|
|
128
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
129
|
+
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
130
|
+
getFirstEnabledInputEl: (ctx) => {
|
|
131
|
+
var _a;
|
|
132
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
133
|
+
},
|
|
134
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
135
|
+
var _a;
|
|
136
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
137
|
+
},
|
|
138
|
+
getInputEls: (ctx) => {
|
|
139
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
140
|
+
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
141
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// src/radio-group.connect.ts
|
|
146
|
+
function connect(state, send, normalize) {
|
|
147
|
+
const isGroupDisabled = state.context.disabled;
|
|
148
|
+
const isGroupReadOnly = state.context.readOnly;
|
|
149
|
+
function getRadioState(props) {
|
|
150
|
+
const radioState = {
|
|
151
|
+
isReadOnly: props.readOnly || isGroupReadOnly,
|
|
152
|
+
isInvalid: props.invalid,
|
|
153
|
+
isDisabled: props.disabled || isGroupDisabled,
|
|
154
|
+
isChecked: state.context.value === props.value,
|
|
155
|
+
isFocused: state.context.focusedId === props.value,
|
|
156
|
+
isHovered: state.context.hoveredId === props.value,
|
|
157
|
+
isActive: state.context.activeId === props.value
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
...radioState,
|
|
161
|
+
isInteractive: !(radioState.isReadOnly || radioState.isDisabled)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function getRadioDataSet(props) {
|
|
165
|
+
const radioState = getRadioState(props);
|
|
166
|
+
return {
|
|
167
|
+
"data-focus": dataAttr(radioState.isFocused),
|
|
168
|
+
"data-disabled": dataAttr(radioState.isDisabled),
|
|
169
|
+
"data-checked": dataAttr(radioState.isChecked),
|
|
170
|
+
"data-hover": dataAttr(radioState.isHovered),
|
|
171
|
+
"data-invalid": dataAttr(radioState.isInvalid),
|
|
172
|
+
"data-readonly": dataAttr(radioState.isReadOnly)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const focus = () => {
|
|
176
|
+
const firstEnabledAndCheckedInput = dom.getFirstEnabledAndCheckedInputEl(state.context);
|
|
177
|
+
if (firstEnabledAndCheckedInput) {
|
|
178
|
+
firstEnabledAndCheckedInput.focus();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
|
|
182
|
+
firstEnabledInput == null ? void 0 : firstEnabledInput.focus();
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
value: state.context.value,
|
|
186
|
+
setValue(value) {
|
|
187
|
+
send({ type: "SET_VALUE", value, manual: true });
|
|
188
|
+
},
|
|
189
|
+
focus,
|
|
190
|
+
blur() {
|
|
191
|
+
const focusedElement = dom.getActiveElement(state.context);
|
|
192
|
+
const inputEls = dom.getInputEls(state.context);
|
|
193
|
+
const radioInputIsFocused = inputEls.some((el) => el === focusedElement);
|
|
194
|
+
if (radioInputIsFocused)
|
|
195
|
+
focusedElement == null ? void 0 : focusedElement.blur();
|
|
196
|
+
},
|
|
197
|
+
rootProps: normalize.element({
|
|
198
|
+
...parts.root.attrs,
|
|
199
|
+
role: "radiogroup",
|
|
200
|
+
id: dom.getRootId(state.context),
|
|
201
|
+
"data-orientation": state.context.orientation,
|
|
202
|
+
"aria-orientation": state.context.orientation,
|
|
203
|
+
dir: state.context.dir
|
|
204
|
+
}),
|
|
205
|
+
labelProps: normalize.element({
|
|
206
|
+
...parts.label.attrs,
|
|
207
|
+
id: dom.getLabelId(state.context),
|
|
208
|
+
onClick: focus
|
|
209
|
+
}),
|
|
210
|
+
getRadioProps(props) {
|
|
211
|
+
const rootState = getRadioState(props);
|
|
212
|
+
return normalize.label({
|
|
213
|
+
...parts.radio.attrs,
|
|
214
|
+
id: dom.getRadioId(state.context, props.value),
|
|
215
|
+
htmlFor: dom.getRadioInputId(state.context, props.value),
|
|
216
|
+
...getRadioDataSet(props),
|
|
217
|
+
onPointerMove() {
|
|
218
|
+
if (!rootState.isInteractive)
|
|
219
|
+
return;
|
|
220
|
+
send({ type: "SET_HOVERED", value: props.value, hovered: true });
|
|
221
|
+
},
|
|
222
|
+
onPointerLeave() {
|
|
223
|
+
if (!rootState.isInteractive)
|
|
224
|
+
return;
|
|
225
|
+
send({ type: "SET_HOVERED", value: null });
|
|
226
|
+
},
|
|
227
|
+
onPointerDown(event) {
|
|
228
|
+
if (!rootState.isInteractive)
|
|
229
|
+
return;
|
|
230
|
+
if (rootState.isFocused)
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
233
|
+
},
|
|
234
|
+
onPointerUp() {
|
|
235
|
+
if (!rootState.isInteractive)
|
|
236
|
+
return;
|
|
237
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
getRadioLabelProps(props) {
|
|
242
|
+
return normalize.element({
|
|
243
|
+
...parts.radioLabel.attrs,
|
|
244
|
+
id: dom.getRadioLabelId(state.context, props.value),
|
|
245
|
+
...getRadioDataSet(props)
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
getRadioControlProps(props) {
|
|
249
|
+
const controlState = getRadioState(props);
|
|
250
|
+
return normalize.element({
|
|
251
|
+
...parts.radioControl.attrs,
|
|
252
|
+
id: dom.getRadioControlId(state.context, props.value),
|
|
253
|
+
"data-active": dataAttr(controlState.isActive),
|
|
254
|
+
"aria-hidden": true,
|
|
255
|
+
...getRadioDataSet(props)
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
getRadioInputProps(props) {
|
|
259
|
+
const inputState = getRadioState(props);
|
|
260
|
+
const isRequired = props.required;
|
|
261
|
+
const trulyDisabled = inputState.isDisabled && !props.focusable;
|
|
262
|
+
return normalize.input({
|
|
263
|
+
...parts.radioInput.attrs,
|
|
264
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
265
|
+
id: dom.getRadioInputId(state.context, props.value),
|
|
266
|
+
type: "radio",
|
|
267
|
+
name: state.context.name || state.context.id,
|
|
268
|
+
form: state.context.form,
|
|
269
|
+
value: props.value,
|
|
270
|
+
onChange(event) {
|
|
271
|
+
if (inputState.isReadOnly || inputState.isDisabled) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (event.target.checked) {
|
|
275
|
+
send({ type: "SET_VALUE", value: props.value });
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
onBlur() {
|
|
279
|
+
send({ type: "SET_FOCUSED", value: null });
|
|
280
|
+
},
|
|
281
|
+
onFocus() {
|
|
282
|
+
send({ type: "SET_FOCUSED", value: props.value, focused: true });
|
|
283
|
+
},
|
|
284
|
+
onKeyDown(event) {
|
|
285
|
+
if (event.key === " ") {
|
|
286
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
onKeyUp(event) {
|
|
290
|
+
if (event.key === " ") {
|
|
291
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
disabled: trulyDisabled,
|
|
295
|
+
required: isRequired,
|
|
296
|
+
defaultChecked: inputState.isChecked,
|
|
297
|
+
"data-disabled": dataAttr(inputState.isDisabled),
|
|
298
|
+
"aria-required": ariaAttr(isRequired),
|
|
299
|
+
"aria-invalid": ariaAttr(inputState.isInvalid),
|
|
300
|
+
readOnly: inputState.isReadOnly,
|
|
301
|
+
"data-readonly": dataAttr(inputState.isReadOnly),
|
|
302
|
+
"aria-disabled": ariaAttr(trulyDisabled),
|
|
303
|
+
"aria-checked": ariaAttr(inputState.isChecked),
|
|
304
|
+
style: visuallyHiddenStyle
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
310
|
+
0 && (module.exports = {
|
|
311
|
+
connect
|
|
312
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MachineContext } from './radio-group.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const dom: {
|
|
6
|
+
getRootNode: (ctx: {
|
|
7
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
8
|
+
}) => Document | ShadowRoot;
|
|
9
|
+
getDoc: (ctx: {
|
|
10
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
11
|
+
}) => Document;
|
|
12
|
+
getWin: (ctx: {
|
|
13
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
14
|
+
}) => Window & typeof globalThis;
|
|
15
|
+
getActiveElement: (ctx: {
|
|
16
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
17
|
+
}) => HTMLElement | null;
|
|
18
|
+
getById: <T = HTMLElement>(ctx: {
|
|
19
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
20
|
+
}, id: string) => T | null;
|
|
21
|
+
} & {
|
|
22
|
+
getRootId: (ctx: MachineContext) => string;
|
|
23
|
+
getLabelId: (ctx: MachineContext) => string;
|
|
24
|
+
getRadioId: (ctx: MachineContext, value: string) => string;
|
|
25
|
+
getRadioInputId: (ctx: MachineContext, value: string) => string;
|
|
26
|
+
getRadioControlId: (ctx: MachineContext, value: string) => string;
|
|
27
|
+
getRadioLabelId: (ctx: MachineContext, value: string) => string;
|
|
28
|
+
getRootEl: (ctx: MachineContext) => HTMLElement | null;
|
|
29
|
+
getRadioInputEl: (ctx: MachineContext, value: string) => HTMLInputElement | null;
|
|
30
|
+
getFirstEnabledInputEl: (ctx: MachineContext) => HTMLInputElement | null | undefined;
|
|
31
|
+
getFirstEnabledAndCheckedInputEl: (ctx: MachineContext) => HTMLInputElement | null | undefined;
|
|
32
|
+
getInputEls: (ctx: MachineContext) => HTMLElement[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { dom };
|
|
@@ -0,0 +1,113 @@
|
|
|
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 __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);
|
|
19
|
+
|
|
20
|
+
// src/radio-group.dom.ts
|
|
21
|
+
var radio_group_dom_exports = {};
|
|
22
|
+
__export(radio_group_dom_exports, {
|
|
23
|
+
dom: () => dom
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(radio_group_dom_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/query.ts
|
|
28
|
+
function isDocument(el) {
|
|
29
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
30
|
+
}
|
|
31
|
+
function isWindow(value) {
|
|
32
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
33
|
+
}
|
|
34
|
+
function getDocument(el) {
|
|
35
|
+
var _a;
|
|
36
|
+
if (isWindow(el))
|
|
37
|
+
return el.document;
|
|
38
|
+
if (isDocument(el))
|
|
39
|
+
return el;
|
|
40
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
41
|
+
}
|
|
42
|
+
function defineDomHelpers(helpers) {
|
|
43
|
+
const dom2 = {
|
|
44
|
+
getRootNode: (ctx) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
47
|
+
},
|
|
48
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
49
|
+
getWin: (ctx) => {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
52
|
+
},
|
|
53
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
54
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
...dom2,
|
|
58
|
+
...helpers
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
63
|
+
function queryAll(root, selector) {
|
|
64
|
+
var _a;
|
|
65
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/radio-group.dom.ts
|
|
69
|
+
var dom = defineDomHelpers({
|
|
70
|
+
getRootId: (ctx) => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `radio-group:${ctx.id}`;
|
|
73
|
+
},
|
|
74
|
+
getLabelId: (ctx) => {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
77
|
+
},
|
|
78
|
+
getRadioId: (ctx, value) => {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radio) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:${value}`;
|
|
81
|
+
},
|
|
82
|
+
getRadioInputId: (ctx, value) => {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioInput) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:input:${value}`;
|
|
85
|
+
},
|
|
86
|
+
getRadioControlId: (ctx, value) => {
|
|
87
|
+
var _a, _b, _c;
|
|
88
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioControl) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:control:${value}`;
|
|
89
|
+
},
|
|
90
|
+
getRadioLabelId: (ctx, value) => {
|
|
91
|
+
var _a, _b, _c;
|
|
92
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioLabel) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:label:${value}`;
|
|
93
|
+
},
|
|
94
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
95
|
+
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
96
|
+
getFirstEnabledInputEl: (ctx) => {
|
|
97
|
+
var _a;
|
|
98
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
99
|
+
},
|
|
100
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
101
|
+
var _a;
|
|
102
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
103
|
+
},
|
|
104
|
+
getInputEls: (ctx) => {
|
|
105
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
106
|
+
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
107
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
dom
|
|
113
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
2
|
+
import { UserDefinedContext, MachineContext, MachineState } from './radio-group.types.js';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
+
|
|
7
|
+
export { machine };
|