@zag-js/radio-group 1.34.1 → 1.35.1
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 +8 -206
- package/dist/index.d.ts +8 -206
- package/dist/index.js +35 -430
- package/dist/index.mjs +9 -425
- package/dist/radio-group.anatomy.d.mts +6 -0
- package/dist/radio-group.anatomy.d.ts +6 -0
- package/dist/radio-group.anatomy.js +41 -0
- package/dist/radio-group.anatomy.mjs +15 -0
- package/dist/radio-group.connect.d.mts +7 -0
- package/dist/radio-group.connect.d.ts +7 -0
- package/dist/radio-group.connect.js +247 -0
- package/dist/radio-group.connect.mjs +212 -0
- package/dist/radio-group.dom.d.mts +30 -0
- package/dist/radio-group.dom.d.ts +30 -0
- package/dist/radio-group.dom.js +92 -0
- package/dist/radio-group.dom.mjs +52 -0
- package/dist/radio-group.machine.d.mts +7 -0
- package/dist/radio-group.machine.d.ts +7 -0
- package/dist/radio-group.machine.js +199 -0
- package/dist/radio-group.machine.mjs +164 -0
- package/dist/radio-group.props.d.mts +10 -0
- package/dist/radio-group.props.d.ts +10 -0
- package/dist/radio-group.props.js +56 -0
- package/dist/radio-group.props.mjs +28 -0
- package/dist/radio-group.types.d.mts +193 -0
- package/dist/radio-group.types.d.ts +193 -0
- package/dist/radio-group.types.js +18 -0
- package/dist/radio-group.types.mjs +0 -0
- package/package.json +18 -8
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/radio-group.connect.ts
|
|
31
|
+
var radio_group_connect_exports = {};
|
|
32
|
+
__export(radio_group_connect_exports, {
|
|
33
|
+
connect: () => connect
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(radio_group_connect_exports);
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var import_focus_visible = require("@zag-js/focus-visible");
|
|
38
|
+
var import_utils = require("@zag-js/utils");
|
|
39
|
+
var import_radio_group = require("./radio-group.anatomy.cjs");
|
|
40
|
+
var dom = __toESM(require("./radio-group.dom.cjs"));
|
|
41
|
+
function connect(service, normalize) {
|
|
42
|
+
const { context, send, computed, prop, scope } = service;
|
|
43
|
+
const groupDisabled = computed("isDisabled");
|
|
44
|
+
const groupInvalid = prop("invalid");
|
|
45
|
+
const readOnly = prop("readOnly");
|
|
46
|
+
function getItemState(props) {
|
|
47
|
+
return {
|
|
48
|
+
value: props.value,
|
|
49
|
+
invalid: !!props.invalid || !!groupInvalid,
|
|
50
|
+
disabled: !!props.disabled || groupDisabled,
|
|
51
|
+
checked: context.get("value") === props.value,
|
|
52
|
+
focused: context.get("focusedValue") === props.value,
|
|
53
|
+
focusVisible: context.get("focusVisibleValue") === props.value,
|
|
54
|
+
hovered: context.get("hoveredValue") === props.value,
|
|
55
|
+
active: context.get("activeValue") === props.value
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function getItemDataAttrs(props) {
|
|
59
|
+
const itemState = getItemState(props);
|
|
60
|
+
return {
|
|
61
|
+
"data-focus": (0, import_dom_query.dataAttr)(itemState.focused),
|
|
62
|
+
"data-focus-visible": (0, import_dom_query.dataAttr)(itemState.focusVisible),
|
|
63
|
+
"data-disabled": (0, import_dom_query.dataAttr)(itemState.disabled),
|
|
64
|
+
"data-readonly": (0, import_dom_query.dataAttr)(readOnly),
|
|
65
|
+
"data-state": itemState.checked ? "checked" : "unchecked",
|
|
66
|
+
"data-hover": (0, import_dom_query.dataAttr)(itemState.hovered),
|
|
67
|
+
"data-invalid": (0, import_dom_query.dataAttr)(itemState.invalid),
|
|
68
|
+
"data-orientation": prop("orientation"),
|
|
69
|
+
"data-ssr": (0, import_dom_query.dataAttr)(context.get("ssr"))
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const focus = () => {
|
|
73
|
+
const nodeToFocus = dom.getFirstEnabledAndCheckedInputEl(scope) ?? dom.getFirstEnabledInputEl(scope);
|
|
74
|
+
nodeToFocus?.focus();
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
focus,
|
|
78
|
+
value: context.get("value"),
|
|
79
|
+
setValue(value) {
|
|
80
|
+
send({ type: "SET_VALUE", value, isTrusted: false });
|
|
81
|
+
},
|
|
82
|
+
clearValue() {
|
|
83
|
+
send({ type: "SET_VALUE", value: null, isTrusted: false });
|
|
84
|
+
},
|
|
85
|
+
getRootProps() {
|
|
86
|
+
return normalize.element({
|
|
87
|
+
...import_radio_group.parts.root.attrs,
|
|
88
|
+
role: "radiogroup",
|
|
89
|
+
id: dom.getRootId(scope),
|
|
90
|
+
"aria-labelledby": dom.getLabelId(scope),
|
|
91
|
+
"aria-required": prop("required") || void 0,
|
|
92
|
+
"aria-disabled": groupDisabled || void 0,
|
|
93
|
+
"aria-readonly": readOnly || void 0,
|
|
94
|
+
"data-orientation": prop("orientation"),
|
|
95
|
+
"data-disabled": (0, import_dom_query.dataAttr)(groupDisabled),
|
|
96
|
+
"data-invalid": (0, import_dom_query.dataAttr)(groupInvalid),
|
|
97
|
+
"data-required": (0, import_dom_query.dataAttr)(prop("required")),
|
|
98
|
+
"aria-orientation": prop("orientation"),
|
|
99
|
+
dir: prop("dir"),
|
|
100
|
+
style: {
|
|
101
|
+
position: "relative"
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
getLabelProps() {
|
|
106
|
+
return normalize.element({
|
|
107
|
+
...import_radio_group.parts.label.attrs,
|
|
108
|
+
dir: prop("dir"),
|
|
109
|
+
"data-orientation": prop("orientation"),
|
|
110
|
+
"data-disabled": (0, import_dom_query.dataAttr)(groupDisabled),
|
|
111
|
+
"data-invalid": (0, import_dom_query.dataAttr)(groupInvalid),
|
|
112
|
+
"data-required": (0, import_dom_query.dataAttr)(prop("required")),
|
|
113
|
+
id: dom.getLabelId(scope),
|
|
114
|
+
onClick: focus
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
getItemState,
|
|
118
|
+
getItemProps(props) {
|
|
119
|
+
const itemState = getItemState(props);
|
|
120
|
+
return normalize.label({
|
|
121
|
+
...import_radio_group.parts.item.attrs,
|
|
122
|
+
dir: prop("dir"),
|
|
123
|
+
id: dom.getItemId(scope, props.value),
|
|
124
|
+
htmlFor: dom.getItemHiddenInputId(scope, props.value),
|
|
125
|
+
...getItemDataAttrs(props),
|
|
126
|
+
onPointerMove() {
|
|
127
|
+
if (itemState.disabled) return;
|
|
128
|
+
if (itemState.hovered) return;
|
|
129
|
+
send({ type: "SET_HOVERED", value: props.value, hovered: true });
|
|
130
|
+
},
|
|
131
|
+
onPointerLeave() {
|
|
132
|
+
if (itemState.disabled) return;
|
|
133
|
+
send({ type: "SET_HOVERED", value: null });
|
|
134
|
+
},
|
|
135
|
+
onPointerDown(event) {
|
|
136
|
+
if (itemState.disabled) return;
|
|
137
|
+
if (!(0, import_dom_query.isLeftClick)(event)) return;
|
|
138
|
+
if (itemState.focused && event.pointerType === "mouse") {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
}
|
|
141
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
142
|
+
},
|
|
143
|
+
onPointerUp() {
|
|
144
|
+
if (itemState.disabled) return;
|
|
145
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
146
|
+
},
|
|
147
|
+
onClick() {
|
|
148
|
+
if (!itemState.disabled && (0, import_dom_query.isSafari)()) {
|
|
149
|
+
dom.getItemHiddenInputEl(scope, props.value)?.focus();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
getItemTextProps(props) {
|
|
155
|
+
return normalize.element({
|
|
156
|
+
...import_radio_group.parts.itemText.attrs,
|
|
157
|
+
dir: prop("dir"),
|
|
158
|
+
id: dom.getItemLabelId(scope, props.value),
|
|
159
|
+
...getItemDataAttrs(props)
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
getItemControlProps(props) {
|
|
163
|
+
const itemState = getItemState(props);
|
|
164
|
+
return normalize.element({
|
|
165
|
+
...import_radio_group.parts.itemControl.attrs,
|
|
166
|
+
dir: prop("dir"),
|
|
167
|
+
id: dom.getItemControlId(scope, props.value),
|
|
168
|
+
"data-active": (0, import_dom_query.dataAttr)(itemState.active),
|
|
169
|
+
"aria-hidden": true,
|
|
170
|
+
...getItemDataAttrs(props)
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
getItemHiddenInputProps(props) {
|
|
174
|
+
const itemState = getItemState(props);
|
|
175
|
+
return normalize.input({
|
|
176
|
+
"data-ownedby": dom.getRootId(scope),
|
|
177
|
+
id: dom.getItemHiddenInputId(scope, props.value),
|
|
178
|
+
type: "radio",
|
|
179
|
+
name: prop("name") || prop("id"),
|
|
180
|
+
form: prop("form"),
|
|
181
|
+
value: props.value,
|
|
182
|
+
required: prop("required"),
|
|
183
|
+
"aria-invalid": itemState.invalid || void 0,
|
|
184
|
+
onClick(event) {
|
|
185
|
+
if (readOnly) {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (event.currentTarget.checked) {
|
|
190
|
+
send({ type: "SET_VALUE", value: props.value, isTrusted: true });
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
onBlur() {
|
|
194
|
+
send({ type: "SET_FOCUSED", value: null, focused: false, focusVisible: false });
|
|
195
|
+
},
|
|
196
|
+
onFocus() {
|
|
197
|
+
const focusVisible = (0, import_focus_visible.isFocusVisible)();
|
|
198
|
+
send({ type: "SET_FOCUSED", value: props.value, focused: true, focusVisible });
|
|
199
|
+
},
|
|
200
|
+
onKeyDown(event) {
|
|
201
|
+
if (event.defaultPrevented) return;
|
|
202
|
+
if (event.key === " ") {
|
|
203
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
onKeyUp(event) {
|
|
207
|
+
if (event.defaultPrevented) return;
|
|
208
|
+
if (event.key === " ") {
|
|
209
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
disabled: itemState.disabled || readOnly,
|
|
213
|
+
defaultChecked: itemState.checked,
|
|
214
|
+
style: import_dom_query.visuallyHiddenStyle
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
getIndicatorProps() {
|
|
218
|
+
const rect = context.get("indicatorRect");
|
|
219
|
+
const rectIsEmpty = rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
|
|
220
|
+
return normalize.element({
|
|
221
|
+
id: dom.getIndicatorId(scope),
|
|
222
|
+
...import_radio_group.parts.indicator.attrs,
|
|
223
|
+
dir: prop("dir"),
|
|
224
|
+
hidden: context.get("value") == null || rectIsEmpty,
|
|
225
|
+
"data-disabled": (0, import_dom_query.dataAttr)(groupDisabled),
|
|
226
|
+
"data-orientation": prop("orientation"),
|
|
227
|
+
style: {
|
|
228
|
+
"--transition-property": "left, top, width, height",
|
|
229
|
+
"--left": (0, import_utils.toPx)(rect?.x),
|
|
230
|
+
"--top": (0, import_utils.toPx)(rect?.y),
|
|
231
|
+
"--width": (0, import_utils.toPx)(rect?.width),
|
|
232
|
+
"--height": (0, import_utils.toPx)(rect?.height),
|
|
233
|
+
position: "absolute",
|
|
234
|
+
willChange: "var(--transition-property)",
|
|
235
|
+
transitionProperty: "var(--transition-property)",
|
|
236
|
+
transitionDuration: "var(--transition-duration, 150ms)",
|
|
237
|
+
transitionTimingFunction: "var(--transition-timing-function)",
|
|
238
|
+
[prop("orientation") === "horizontal" ? "left" : "top"]: prop("orientation") === "horizontal" ? "var(--left)" : "var(--top)"
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
245
|
+
0 && (module.exports = {
|
|
246
|
+
connect
|
|
247
|
+
});
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// src/radio-group.connect.ts
|
|
2
|
+
import { dataAttr, isLeftClick, isSafari, visuallyHiddenStyle } from "@zag-js/dom-query";
|
|
3
|
+
import { isFocusVisible } from "@zag-js/focus-visible";
|
|
4
|
+
import { toPx } from "@zag-js/utils";
|
|
5
|
+
import { parts } from "./radio-group.anatomy.mjs";
|
|
6
|
+
import * as dom from "./radio-group.dom.mjs";
|
|
7
|
+
function connect(service, normalize) {
|
|
8
|
+
const { context, send, computed, prop, scope } = service;
|
|
9
|
+
const groupDisabled = computed("isDisabled");
|
|
10
|
+
const groupInvalid = prop("invalid");
|
|
11
|
+
const readOnly = prop("readOnly");
|
|
12
|
+
function getItemState(props) {
|
|
13
|
+
return {
|
|
14
|
+
value: props.value,
|
|
15
|
+
invalid: !!props.invalid || !!groupInvalid,
|
|
16
|
+
disabled: !!props.disabled || groupDisabled,
|
|
17
|
+
checked: context.get("value") === props.value,
|
|
18
|
+
focused: context.get("focusedValue") === props.value,
|
|
19
|
+
focusVisible: context.get("focusVisibleValue") === props.value,
|
|
20
|
+
hovered: context.get("hoveredValue") === props.value,
|
|
21
|
+
active: context.get("activeValue") === props.value
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getItemDataAttrs(props) {
|
|
25
|
+
const itemState = getItemState(props);
|
|
26
|
+
return {
|
|
27
|
+
"data-focus": dataAttr(itemState.focused),
|
|
28
|
+
"data-focus-visible": dataAttr(itemState.focusVisible),
|
|
29
|
+
"data-disabled": dataAttr(itemState.disabled),
|
|
30
|
+
"data-readonly": dataAttr(readOnly),
|
|
31
|
+
"data-state": itemState.checked ? "checked" : "unchecked",
|
|
32
|
+
"data-hover": dataAttr(itemState.hovered),
|
|
33
|
+
"data-invalid": dataAttr(itemState.invalid),
|
|
34
|
+
"data-orientation": prop("orientation"),
|
|
35
|
+
"data-ssr": dataAttr(context.get("ssr"))
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const focus = () => {
|
|
39
|
+
const nodeToFocus = dom.getFirstEnabledAndCheckedInputEl(scope) ?? dom.getFirstEnabledInputEl(scope);
|
|
40
|
+
nodeToFocus?.focus();
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
focus,
|
|
44
|
+
value: context.get("value"),
|
|
45
|
+
setValue(value) {
|
|
46
|
+
send({ type: "SET_VALUE", value, isTrusted: false });
|
|
47
|
+
},
|
|
48
|
+
clearValue() {
|
|
49
|
+
send({ type: "SET_VALUE", value: null, isTrusted: false });
|
|
50
|
+
},
|
|
51
|
+
getRootProps() {
|
|
52
|
+
return normalize.element({
|
|
53
|
+
...parts.root.attrs,
|
|
54
|
+
role: "radiogroup",
|
|
55
|
+
id: dom.getRootId(scope),
|
|
56
|
+
"aria-labelledby": dom.getLabelId(scope),
|
|
57
|
+
"aria-required": prop("required") || void 0,
|
|
58
|
+
"aria-disabled": groupDisabled || void 0,
|
|
59
|
+
"aria-readonly": readOnly || void 0,
|
|
60
|
+
"data-orientation": prop("orientation"),
|
|
61
|
+
"data-disabled": dataAttr(groupDisabled),
|
|
62
|
+
"data-invalid": dataAttr(groupInvalid),
|
|
63
|
+
"data-required": dataAttr(prop("required")),
|
|
64
|
+
"aria-orientation": prop("orientation"),
|
|
65
|
+
dir: prop("dir"),
|
|
66
|
+
style: {
|
|
67
|
+
position: "relative"
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
getLabelProps() {
|
|
72
|
+
return normalize.element({
|
|
73
|
+
...parts.label.attrs,
|
|
74
|
+
dir: prop("dir"),
|
|
75
|
+
"data-orientation": prop("orientation"),
|
|
76
|
+
"data-disabled": dataAttr(groupDisabled),
|
|
77
|
+
"data-invalid": dataAttr(groupInvalid),
|
|
78
|
+
"data-required": dataAttr(prop("required")),
|
|
79
|
+
id: dom.getLabelId(scope),
|
|
80
|
+
onClick: focus
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
getItemState,
|
|
84
|
+
getItemProps(props) {
|
|
85
|
+
const itemState = getItemState(props);
|
|
86
|
+
return normalize.label({
|
|
87
|
+
...parts.item.attrs,
|
|
88
|
+
dir: prop("dir"),
|
|
89
|
+
id: dom.getItemId(scope, props.value),
|
|
90
|
+
htmlFor: dom.getItemHiddenInputId(scope, props.value),
|
|
91
|
+
...getItemDataAttrs(props),
|
|
92
|
+
onPointerMove() {
|
|
93
|
+
if (itemState.disabled) return;
|
|
94
|
+
if (itemState.hovered) return;
|
|
95
|
+
send({ type: "SET_HOVERED", value: props.value, hovered: true });
|
|
96
|
+
},
|
|
97
|
+
onPointerLeave() {
|
|
98
|
+
if (itemState.disabled) return;
|
|
99
|
+
send({ type: "SET_HOVERED", value: null });
|
|
100
|
+
},
|
|
101
|
+
onPointerDown(event) {
|
|
102
|
+
if (itemState.disabled) return;
|
|
103
|
+
if (!isLeftClick(event)) return;
|
|
104
|
+
if (itemState.focused && event.pointerType === "mouse") {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
}
|
|
107
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
108
|
+
},
|
|
109
|
+
onPointerUp() {
|
|
110
|
+
if (itemState.disabled) return;
|
|
111
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
112
|
+
},
|
|
113
|
+
onClick() {
|
|
114
|
+
if (!itemState.disabled && isSafari()) {
|
|
115
|
+
dom.getItemHiddenInputEl(scope, props.value)?.focus();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
getItemTextProps(props) {
|
|
121
|
+
return normalize.element({
|
|
122
|
+
...parts.itemText.attrs,
|
|
123
|
+
dir: prop("dir"),
|
|
124
|
+
id: dom.getItemLabelId(scope, props.value),
|
|
125
|
+
...getItemDataAttrs(props)
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
getItemControlProps(props) {
|
|
129
|
+
const itemState = getItemState(props);
|
|
130
|
+
return normalize.element({
|
|
131
|
+
...parts.itemControl.attrs,
|
|
132
|
+
dir: prop("dir"),
|
|
133
|
+
id: dom.getItemControlId(scope, props.value),
|
|
134
|
+
"data-active": dataAttr(itemState.active),
|
|
135
|
+
"aria-hidden": true,
|
|
136
|
+
...getItemDataAttrs(props)
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
getItemHiddenInputProps(props) {
|
|
140
|
+
const itemState = getItemState(props);
|
|
141
|
+
return normalize.input({
|
|
142
|
+
"data-ownedby": dom.getRootId(scope),
|
|
143
|
+
id: dom.getItemHiddenInputId(scope, props.value),
|
|
144
|
+
type: "radio",
|
|
145
|
+
name: prop("name") || prop("id"),
|
|
146
|
+
form: prop("form"),
|
|
147
|
+
value: props.value,
|
|
148
|
+
required: prop("required"),
|
|
149
|
+
"aria-invalid": itemState.invalid || void 0,
|
|
150
|
+
onClick(event) {
|
|
151
|
+
if (readOnly) {
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (event.currentTarget.checked) {
|
|
156
|
+
send({ type: "SET_VALUE", value: props.value, isTrusted: true });
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
onBlur() {
|
|
160
|
+
send({ type: "SET_FOCUSED", value: null, focused: false, focusVisible: false });
|
|
161
|
+
},
|
|
162
|
+
onFocus() {
|
|
163
|
+
const focusVisible = isFocusVisible();
|
|
164
|
+
send({ type: "SET_FOCUSED", value: props.value, focused: true, focusVisible });
|
|
165
|
+
},
|
|
166
|
+
onKeyDown(event) {
|
|
167
|
+
if (event.defaultPrevented) return;
|
|
168
|
+
if (event.key === " ") {
|
|
169
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
onKeyUp(event) {
|
|
173
|
+
if (event.defaultPrevented) return;
|
|
174
|
+
if (event.key === " ") {
|
|
175
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
disabled: itemState.disabled || readOnly,
|
|
179
|
+
defaultChecked: itemState.checked,
|
|
180
|
+
style: visuallyHiddenStyle
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
getIndicatorProps() {
|
|
184
|
+
const rect = context.get("indicatorRect");
|
|
185
|
+
const rectIsEmpty = rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
|
|
186
|
+
return normalize.element({
|
|
187
|
+
id: dom.getIndicatorId(scope),
|
|
188
|
+
...parts.indicator.attrs,
|
|
189
|
+
dir: prop("dir"),
|
|
190
|
+
hidden: context.get("value") == null || rectIsEmpty,
|
|
191
|
+
"data-disabled": dataAttr(groupDisabled),
|
|
192
|
+
"data-orientation": prop("orientation"),
|
|
193
|
+
style: {
|
|
194
|
+
"--transition-property": "left, top, width, height",
|
|
195
|
+
"--left": toPx(rect?.x),
|
|
196
|
+
"--top": toPx(rect?.y),
|
|
197
|
+
"--width": toPx(rect?.width),
|
|
198
|
+
"--height": toPx(rect?.height),
|
|
199
|
+
position: "absolute",
|
|
200
|
+
willChange: "var(--transition-property)",
|
|
201
|
+
transitionProperty: "var(--transition-property)",
|
|
202
|
+
transitionDuration: "var(--transition-duration, 150ms)",
|
|
203
|
+
transitionTimingFunction: "var(--transition-timing-function)",
|
|
204
|
+
[prop("orientation") === "horizontal" ? "left" : "top"]: prop("orientation") === "horizontal" ? "var(--left)" : "var(--top)"
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export {
|
|
211
|
+
connect
|
|
212
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
5
|
+
declare const getItemId: (ctx: Scope, value: string) => any;
|
|
6
|
+
declare const getItemHiddenInputId: (ctx: Scope, value: string) => any;
|
|
7
|
+
declare const getItemControlId: (ctx: Scope, value: string) => any;
|
|
8
|
+
declare const getItemLabelId: (ctx: Scope, value: string) => any;
|
|
9
|
+
declare const getIndicatorId: (ctx: Scope) => any;
|
|
10
|
+
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
11
|
+
declare const getItemHiddenInputEl: (ctx: Scope, value: string) => HTMLInputElement | null;
|
|
12
|
+
declare const getIndicatorEl: (ctx: Scope) => HTMLElement | null;
|
|
13
|
+
declare const getFirstEnabledInputEl: (ctx: Scope) => HTMLInputElement | null | undefined;
|
|
14
|
+
declare const getFirstEnabledAndCheckedInputEl: (ctx: Scope) => HTMLInputElement | null | undefined;
|
|
15
|
+
declare const getInputEls: (ctx: Scope) => HTMLInputElement[];
|
|
16
|
+
declare const getRadioEl: (ctx: Scope, value: string | null) => HTMLElement | null | undefined;
|
|
17
|
+
declare const getOffsetRect: (el: HTMLElement | undefined) => {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
declare const getRectById: (ctx: Scope, id: string) => {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
} | undefined;
|
|
29
|
+
|
|
30
|
+
export { getFirstEnabledAndCheckedInputEl, getFirstEnabledInputEl, getIndicatorEl, getIndicatorId, getInputEls, getItemControlId, getItemHiddenInputEl, getItemHiddenInputId, getItemId, getItemLabelId, getLabelId, getOffsetRect, getRadioEl, getRectById, getRootEl, getRootId };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
5
|
+
declare const getItemId: (ctx: Scope, value: string) => any;
|
|
6
|
+
declare const getItemHiddenInputId: (ctx: Scope, value: string) => any;
|
|
7
|
+
declare const getItemControlId: (ctx: Scope, value: string) => any;
|
|
8
|
+
declare const getItemLabelId: (ctx: Scope, value: string) => any;
|
|
9
|
+
declare const getIndicatorId: (ctx: Scope) => any;
|
|
10
|
+
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
11
|
+
declare const getItemHiddenInputEl: (ctx: Scope, value: string) => HTMLInputElement | null;
|
|
12
|
+
declare const getIndicatorEl: (ctx: Scope) => HTMLElement | null;
|
|
13
|
+
declare const getFirstEnabledInputEl: (ctx: Scope) => HTMLInputElement | null | undefined;
|
|
14
|
+
declare const getFirstEnabledAndCheckedInputEl: (ctx: Scope) => HTMLInputElement | null | undefined;
|
|
15
|
+
declare const getInputEls: (ctx: Scope) => HTMLInputElement[];
|
|
16
|
+
declare const getRadioEl: (ctx: Scope, value: string | null) => HTMLElement | null | undefined;
|
|
17
|
+
declare const getOffsetRect: (el: HTMLElement | undefined) => {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
declare const getRectById: (ctx: Scope, id: string) => {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
} | undefined;
|
|
29
|
+
|
|
30
|
+
export { getFirstEnabledAndCheckedInputEl, getFirstEnabledInputEl, getIndicatorEl, getIndicatorId, getInputEls, getItemControlId, getItemHiddenInputEl, getItemHiddenInputId, getItemId, getItemLabelId, getLabelId, getOffsetRect, getRadioEl, getRectById, getRootEl, getRootId };
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
getFirstEnabledAndCheckedInputEl: () => getFirstEnabledAndCheckedInputEl,
|
|
24
|
+
getFirstEnabledInputEl: () => getFirstEnabledInputEl,
|
|
25
|
+
getIndicatorEl: () => getIndicatorEl,
|
|
26
|
+
getIndicatorId: () => getIndicatorId,
|
|
27
|
+
getInputEls: () => getInputEls,
|
|
28
|
+
getItemControlId: () => getItemControlId,
|
|
29
|
+
getItemHiddenInputEl: () => getItemHiddenInputEl,
|
|
30
|
+
getItemHiddenInputId: () => getItemHiddenInputId,
|
|
31
|
+
getItemId: () => getItemId,
|
|
32
|
+
getItemLabelId: () => getItemLabelId,
|
|
33
|
+
getLabelId: () => getLabelId,
|
|
34
|
+
getOffsetRect: () => getOffsetRect,
|
|
35
|
+
getRadioEl: () => getRadioEl,
|
|
36
|
+
getRectById: () => getRectById,
|
|
37
|
+
getRootEl: () => getRootEl,
|
|
38
|
+
getRootId: () => getRootId
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(radio_group_dom_exports);
|
|
41
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
42
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`;
|
|
43
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`;
|
|
44
|
+
var getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `radio-group:${ctx.id}:radio:${value}`;
|
|
45
|
+
var getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`;
|
|
46
|
+
var getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`;
|
|
47
|
+
var getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`;
|
|
48
|
+
var getIndicatorId = (ctx) => ctx.ids?.indicator ?? `radio-group:${ctx.id}:indicator`;
|
|
49
|
+
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
50
|
+
var getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
|
|
51
|
+
var getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
|
|
52
|
+
var getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
|
|
53
|
+
var getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
|
|
54
|
+
var getInputEls = (ctx) => {
|
|
55
|
+
const ownerId = CSS.escape(getRootId(ctx));
|
|
56
|
+
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
57
|
+
return (0, import_dom_query.queryAll)(getRootEl(ctx), selector);
|
|
58
|
+
};
|
|
59
|
+
var getRadioEl = (ctx, value) => {
|
|
60
|
+
if (!value) return;
|
|
61
|
+
return ctx.getById(getItemId(ctx, value));
|
|
62
|
+
};
|
|
63
|
+
var getOffsetRect = (el) => ({
|
|
64
|
+
x: el?.offsetLeft ?? 0,
|
|
65
|
+
y: el?.offsetTop ?? 0,
|
|
66
|
+
width: el?.offsetWidth ?? 0,
|
|
67
|
+
height: el?.offsetHeight ?? 0
|
|
68
|
+
});
|
|
69
|
+
var getRectById = (ctx, id) => {
|
|
70
|
+
const radioEl = ctx.getById(getItemId(ctx, id));
|
|
71
|
+
if (!radioEl) return;
|
|
72
|
+
return getOffsetRect(radioEl);
|
|
73
|
+
};
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
getFirstEnabledAndCheckedInputEl,
|
|
77
|
+
getFirstEnabledInputEl,
|
|
78
|
+
getIndicatorEl,
|
|
79
|
+
getIndicatorId,
|
|
80
|
+
getInputEls,
|
|
81
|
+
getItemControlId,
|
|
82
|
+
getItemHiddenInputEl,
|
|
83
|
+
getItemHiddenInputId,
|
|
84
|
+
getItemId,
|
|
85
|
+
getItemLabelId,
|
|
86
|
+
getLabelId,
|
|
87
|
+
getOffsetRect,
|
|
88
|
+
getRadioEl,
|
|
89
|
+
getRectById,
|
|
90
|
+
getRootEl,
|
|
91
|
+
getRootId
|
|
92
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/radio-group.dom.ts
|
|
2
|
+
import { queryAll } from "@zag-js/dom-query";
|
|
3
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`;
|
|
4
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`;
|
|
5
|
+
var getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `radio-group:${ctx.id}:radio:${value}`;
|
|
6
|
+
var getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`;
|
|
7
|
+
var getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`;
|
|
8
|
+
var getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`;
|
|
9
|
+
var getIndicatorId = (ctx) => ctx.ids?.indicator ?? `radio-group:${ctx.id}:indicator`;
|
|
10
|
+
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
11
|
+
var getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
|
|
12
|
+
var getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
|
|
13
|
+
var getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
|
|
14
|
+
var getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
|
|
15
|
+
var getInputEls = (ctx) => {
|
|
16
|
+
const ownerId = CSS.escape(getRootId(ctx));
|
|
17
|
+
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
18
|
+
return queryAll(getRootEl(ctx), selector);
|
|
19
|
+
};
|
|
20
|
+
var getRadioEl = (ctx, value) => {
|
|
21
|
+
if (!value) return;
|
|
22
|
+
return ctx.getById(getItemId(ctx, value));
|
|
23
|
+
};
|
|
24
|
+
var getOffsetRect = (el) => ({
|
|
25
|
+
x: el?.offsetLeft ?? 0,
|
|
26
|
+
y: el?.offsetTop ?? 0,
|
|
27
|
+
width: el?.offsetWidth ?? 0,
|
|
28
|
+
height: el?.offsetHeight ?? 0
|
|
29
|
+
});
|
|
30
|
+
var getRectById = (ctx, id) => {
|
|
31
|
+
const radioEl = ctx.getById(getItemId(ctx, id));
|
|
32
|
+
if (!radioEl) return;
|
|
33
|
+
return getOffsetRect(radioEl);
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
getFirstEnabledAndCheckedInputEl,
|
|
37
|
+
getFirstEnabledInputEl,
|
|
38
|
+
getIndicatorEl,
|
|
39
|
+
getIndicatorId,
|
|
40
|
+
getInputEls,
|
|
41
|
+
getItemControlId,
|
|
42
|
+
getItemHiddenInputEl,
|
|
43
|
+
getItemHiddenInputId,
|
|
44
|
+
getItemId,
|
|
45
|
+
getItemLabelId,
|
|
46
|
+
getLabelId,
|
|
47
|
+
getOffsetRect,
|
|
48
|
+
getRadioEl,
|
|
49
|
+
getRectById,
|
|
50
|
+
getRootEl,
|
|
51
|
+
getRootId
|
|
52
|
+
};
|