@zag-js/radio-group 0.10.2 → 0.10.3
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 +24 -29
- 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 -91
- package/dist/radio-group.machine.mjs +128 -7
- package/dist/radio-group.types.d.ts +10 -12
- package/package.json +10 -15
- 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
|
@@ -1,92 +1,12 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
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
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
27
|
-
var import_visually_hidden = require("@zag-js/visually-hidden");
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"label",
|
|
34
|
-
"radio",
|
|
35
|
-
"radioLabel",
|
|
36
|
-
"radioControl",
|
|
37
|
-
"radioInput",
|
|
38
|
-
"indicator"
|
|
39
|
-
);
|
|
40
|
-
var parts = anatomy.build();
|
|
5
|
+
const domQuery = require('@zag-js/dom-query');
|
|
6
|
+
const visuallyHidden = require('@zag-js/visually-hidden');
|
|
7
|
+
const radioGroup_anatomy = require('./radio-group.anatomy.js');
|
|
8
|
+
const radioGroup_dom = require('./radio-group.dom.js');
|
|
41
9
|
|
|
42
|
-
// src/radio-group.dom.ts
|
|
43
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
44
|
-
var dom = (0, import_dom_query.createScope)({
|
|
45
|
-
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
46
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
47
|
-
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
48
|
-
getRadioInputId: (ctx, value) => ctx.ids?.radioInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
|
|
49
|
-
getRadioControlId: (ctx, value) => ctx.ids?.radioControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
|
|
50
|
-
getRadioLabelId: (ctx, value) => ctx.ids?.radioLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
|
|
51
|
-
getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
|
|
52
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
53
|
-
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
54
|
-
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
55
|
-
getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
|
|
56
|
-
getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
|
|
57
|
-
getInputEls: (ctx) => {
|
|
58
|
-
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
59
|
-
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
60
|
-
return (0, import_dom_query.queryAll)(dom.getRootEl(ctx), selector);
|
|
61
|
-
},
|
|
62
|
-
getActiveRadioEl: (ctx) => {
|
|
63
|
-
if (!ctx.value)
|
|
64
|
-
return;
|
|
65
|
-
return dom.getById(ctx, dom.getRadioId(ctx, ctx.value));
|
|
66
|
-
},
|
|
67
|
-
getOffsetRect: (el) => {
|
|
68
|
-
return {
|
|
69
|
-
left: el?.offsetLeft ?? 0,
|
|
70
|
-
top: el?.offsetTop ?? 0,
|
|
71
|
-
width: el?.offsetWidth ?? 0,
|
|
72
|
-
height: el?.offsetHeight ?? 0
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
getRectById: (ctx, id) => {
|
|
76
|
-
const tab = dom.queryById(ctx, dom.getRadioId(ctx, id));
|
|
77
|
-
return dom.resolveRect(dom.getOffsetRect(tab));
|
|
78
|
-
},
|
|
79
|
-
resolveRect(rect) {
|
|
80
|
-
return {
|
|
81
|
-
width: `${rect.width}px`,
|
|
82
|
-
height: `${rect.height}px`,
|
|
83
|
-
left: `${rect.left}px`,
|
|
84
|
-
top: `${rect.top}px`
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// src/radio-group.connect.ts
|
|
90
10
|
function connect(state, send, normalize) {
|
|
91
11
|
const isGroupDisabled = state.context.disabled;
|
|
92
12
|
const isGroupReadOnly = state.context.readOnly;
|
|
@@ -108,21 +28,21 @@ function connect(state, send, normalize) {
|
|
|
108
28
|
function getRadioDataAttrs(props) {
|
|
109
29
|
const radioState = getRadioState(props);
|
|
110
30
|
return {
|
|
111
|
-
"data-focus":
|
|
112
|
-
"data-disabled":
|
|
113
|
-
"data-checked":
|
|
114
|
-
"data-hover":
|
|
115
|
-
"data-invalid":
|
|
116
|
-
"data-readonly":
|
|
31
|
+
"data-focus": domQuery.dataAttr(radioState.isFocused),
|
|
32
|
+
"data-disabled": domQuery.dataAttr(radioState.isDisabled),
|
|
33
|
+
"data-checked": domQuery.dataAttr(radioState.isChecked),
|
|
34
|
+
"data-hover": domQuery.dataAttr(radioState.isHovered),
|
|
35
|
+
"data-invalid": domQuery.dataAttr(radioState.isInvalid),
|
|
36
|
+
"data-readonly": domQuery.dataAttr(radioState.isReadOnly)
|
|
117
37
|
};
|
|
118
38
|
}
|
|
119
39
|
const focus = () => {
|
|
120
|
-
const firstEnabledAndCheckedInput = dom.getFirstEnabledAndCheckedInputEl(state.context);
|
|
40
|
+
const firstEnabledAndCheckedInput = radioGroup_dom.dom.getFirstEnabledAndCheckedInputEl(state.context);
|
|
121
41
|
if (firstEnabledAndCheckedInput) {
|
|
122
42
|
firstEnabledAndCheckedInput.focus();
|
|
123
43
|
return;
|
|
124
44
|
}
|
|
125
|
-
const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
|
|
45
|
+
const firstEnabledInput = radioGroup_dom.dom.getFirstEnabledInputEl(state.context);
|
|
126
46
|
firstEnabledInput?.focus();
|
|
127
47
|
};
|
|
128
48
|
return {
|
|
@@ -150,8 +70,8 @@ function connect(state, send, normalize) {
|
|
|
150
70
|
* Function to blur the currently focused radio input in the radio group
|
|
151
71
|
*/
|
|
152
72
|
blur() {
|
|
153
|
-
const focusedElement = dom.getActiveElement(state.context);
|
|
154
|
-
const inputEls = dom.getInputEls(state.context);
|
|
73
|
+
const focusedElement = radioGroup_dom.dom.getActiveElement(state.context);
|
|
74
|
+
const inputEls = radioGroup_dom.dom.getInputEls(state.context);
|
|
155
75
|
const radioInputIsFocused = inputEls.some((el) => el === focusedElement);
|
|
156
76
|
if (radioInputIsFocused)
|
|
157
77
|
focusedElement?.blur();
|
|
@@ -161,25 +81,25 @@ function connect(state, send, normalize) {
|
|
|
161
81
|
*/
|
|
162
82
|
getRadioState,
|
|
163
83
|
rootProps: normalize.element({
|
|
164
|
-
...parts.root.attrs,
|
|
84
|
+
...radioGroup_anatomy.parts.root.attrs,
|
|
165
85
|
role: "radiogroup",
|
|
166
|
-
id: dom.getRootId(state.context),
|
|
167
|
-
"aria-labelledby": dom.getLabelId(state.context),
|
|
86
|
+
id: radioGroup_dom.dom.getRootId(state.context),
|
|
87
|
+
"aria-labelledby": radioGroup_dom.dom.getLabelId(state.context),
|
|
168
88
|
"data-orientation": state.context.orientation,
|
|
169
89
|
"aria-orientation": state.context.orientation,
|
|
170
90
|
dir: state.context.dir
|
|
171
91
|
}),
|
|
172
92
|
labelProps: normalize.element({
|
|
173
|
-
...parts.label.attrs,
|
|
174
|
-
id: dom.getLabelId(state.context),
|
|
93
|
+
...radioGroup_anatomy.parts.label.attrs,
|
|
94
|
+
id: radioGroup_dom.dom.getLabelId(state.context),
|
|
175
95
|
onClick: focus
|
|
176
96
|
}),
|
|
177
97
|
getRadioProps(props) {
|
|
178
98
|
const rootState = getRadioState(props);
|
|
179
99
|
return normalize.label({
|
|
180
|
-
...parts.radio.attrs,
|
|
181
|
-
id: dom.getRadioId(state.context, props.value),
|
|
182
|
-
htmlFor: dom.getRadioInputId(state.context, props.value),
|
|
100
|
+
...radioGroup_anatomy.parts.radio.attrs,
|
|
101
|
+
id: radioGroup_dom.dom.getRadioId(state.context, props.value),
|
|
102
|
+
htmlFor: radioGroup_dom.dom.getRadioInputId(state.context, props.value),
|
|
183
103
|
...getRadioDataAttrs(props),
|
|
184
104
|
onPointerMove() {
|
|
185
105
|
if (!rootState.isInteractive)
|
|
@@ -208,17 +128,17 @@ function connect(state, send, normalize) {
|
|
|
208
128
|
},
|
|
209
129
|
getRadioLabelProps(props) {
|
|
210
130
|
return normalize.element({
|
|
211
|
-
...parts.radioLabel.attrs,
|
|
212
|
-
id: dom.getRadioLabelId(state.context, props.value),
|
|
131
|
+
...radioGroup_anatomy.parts.radioLabel.attrs,
|
|
132
|
+
id: radioGroup_dom.dom.getRadioLabelId(state.context, props.value),
|
|
213
133
|
...getRadioDataAttrs(props)
|
|
214
134
|
});
|
|
215
135
|
},
|
|
216
136
|
getRadioControlProps(props) {
|
|
217
137
|
const controlState = getRadioState(props);
|
|
218
138
|
return normalize.element({
|
|
219
|
-
...parts.radioControl.attrs,
|
|
220
|
-
id: dom.getRadioControlId(state.context, props.value),
|
|
221
|
-
"data-active":
|
|
139
|
+
...radioGroup_anatomy.parts.radioControl.attrs,
|
|
140
|
+
id: radioGroup_dom.dom.getRadioControlId(state.context, props.value),
|
|
141
|
+
"data-active": domQuery.dataAttr(controlState.isActive),
|
|
222
142
|
"aria-hidden": true,
|
|
223
143
|
...getRadioDataAttrs(props)
|
|
224
144
|
});
|
|
@@ -228,9 +148,9 @@ function connect(state, send, normalize) {
|
|
|
228
148
|
const isRequired = props.required;
|
|
229
149
|
const trulyDisabled = inputState.isDisabled && !props.focusable;
|
|
230
150
|
return normalize.input({
|
|
231
|
-
...parts.radioInput.attrs,
|
|
232
|
-
"data-ownedby": dom.getRootId(state.context),
|
|
233
|
-
id: dom.getRadioInputId(state.context, props.value),
|
|
151
|
+
...radioGroup_anatomy.parts.radioInput.attrs,
|
|
152
|
+
"data-ownedby": radioGroup_dom.dom.getRootId(state.context),
|
|
153
|
+
id: radioGroup_dom.dom.getRadioInputId(state.context, props.value),
|
|
234
154
|
type: "radio",
|
|
235
155
|
name: state.context.name || state.context.id,
|
|
236
156
|
form: state.context.form,
|
|
@@ -262,19 +182,19 @@ function connect(state, send, normalize) {
|
|
|
262
182
|
disabled: trulyDisabled,
|
|
263
183
|
required: isRequired,
|
|
264
184
|
defaultChecked: inputState.isChecked,
|
|
265
|
-
"data-disabled":
|
|
266
|
-
"aria-required":
|
|
267
|
-
"aria-invalid":
|
|
185
|
+
"data-disabled": domQuery.dataAttr(inputState.isDisabled),
|
|
186
|
+
"aria-required": domQuery.ariaAttr(isRequired),
|
|
187
|
+
"aria-invalid": domQuery.ariaAttr(inputState.isInvalid),
|
|
268
188
|
readOnly: inputState.isReadOnly,
|
|
269
|
-
"data-readonly":
|
|
270
|
-
"aria-disabled":
|
|
271
|
-
"aria-checked":
|
|
272
|
-
style:
|
|
189
|
+
"data-readonly": domQuery.dataAttr(inputState.isReadOnly),
|
|
190
|
+
"aria-disabled": domQuery.ariaAttr(trulyDisabled),
|
|
191
|
+
"aria-checked": domQuery.ariaAttr(inputState.isChecked),
|
|
192
|
+
style: visuallyHidden.visuallyHiddenStyle
|
|
273
193
|
});
|
|
274
194
|
},
|
|
275
195
|
indicatorProps: normalize.element({
|
|
276
|
-
id: dom.getIndicatorId(state.context),
|
|
277
|
-
...parts.indicator.attrs,
|
|
196
|
+
id: radioGroup_dom.dom.getIndicatorId(state.context),
|
|
197
|
+
...radioGroup_anatomy.parts.indicator.attrs,
|
|
278
198
|
"data-orientation": state.context.orientation,
|
|
279
199
|
style: {
|
|
280
200
|
"--transition-duration": "150ms",
|
|
@@ -289,7 +209,5 @@ function connect(state, send, normalize) {
|
|
|
289
209
|
})
|
|
290
210
|
};
|
|
291
211
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
connect
|
|
295
|
-
});
|
|
212
|
+
|
|
213
|
+
exports.connect = connect;
|
|
@@ -1,8 +1,209 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { dataAttr, ariaAttr } from '@zag-js/dom-query';
|
|
2
|
+
import { visuallyHiddenStyle } from '@zag-js/visually-hidden';
|
|
3
|
+
import { parts } from './radio-group.anatomy.mjs';
|
|
4
|
+
import { dom } from './radio-group.dom.mjs';
|
|
5
|
+
|
|
6
|
+
function connect(state, send, normalize) {
|
|
7
|
+
const isGroupDisabled = state.context.disabled;
|
|
8
|
+
const isGroupReadOnly = state.context.readOnly;
|
|
9
|
+
function getRadioState(props) {
|
|
10
|
+
const radioState = {
|
|
11
|
+
isReadOnly: props.readOnly || isGroupReadOnly,
|
|
12
|
+
isInvalid: props.invalid,
|
|
13
|
+
isDisabled: props.disabled || isGroupDisabled,
|
|
14
|
+
isChecked: state.context.value === props.value,
|
|
15
|
+
isFocused: state.context.focusedId === props.value,
|
|
16
|
+
isHovered: state.context.hoveredId === props.value,
|
|
17
|
+
isActive: state.context.activeId === props.value
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
...radioState,
|
|
21
|
+
isInteractive: !(radioState.isReadOnly || radioState.isDisabled)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getRadioDataAttrs(props) {
|
|
25
|
+
const radioState = getRadioState(props);
|
|
26
|
+
return {
|
|
27
|
+
"data-focus": dataAttr(radioState.isFocused),
|
|
28
|
+
"data-disabled": dataAttr(radioState.isDisabled),
|
|
29
|
+
"data-checked": dataAttr(radioState.isChecked),
|
|
30
|
+
"data-hover": dataAttr(radioState.isHovered),
|
|
31
|
+
"data-invalid": dataAttr(radioState.isInvalid),
|
|
32
|
+
"data-readonly": dataAttr(radioState.isReadOnly)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const focus = () => {
|
|
36
|
+
const firstEnabledAndCheckedInput = dom.getFirstEnabledAndCheckedInputEl(state.context);
|
|
37
|
+
if (firstEnabledAndCheckedInput) {
|
|
38
|
+
firstEnabledAndCheckedInput.focus();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
|
|
42
|
+
firstEnabledInput?.focus();
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
/**
|
|
46
|
+
* The current value of the radio group
|
|
47
|
+
*/
|
|
48
|
+
value: state.context.value,
|
|
49
|
+
/**
|
|
50
|
+
* Function to set the value of the radio group
|
|
51
|
+
*/
|
|
52
|
+
setValue(value) {
|
|
53
|
+
send({ type: "SET_VALUE", value, manual: true });
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Function to clear the value of the radio group
|
|
57
|
+
*/
|
|
58
|
+
clearValue() {
|
|
59
|
+
send({ type: "SET_VALUE", value: null, manual: true });
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Function to focus the radio group
|
|
63
|
+
*/
|
|
64
|
+
focus,
|
|
65
|
+
/**
|
|
66
|
+
* Function to blur the currently focused radio input in the radio group
|
|
67
|
+
*/
|
|
68
|
+
blur() {
|
|
69
|
+
const focusedElement = dom.getActiveElement(state.context);
|
|
70
|
+
const inputEls = dom.getInputEls(state.context);
|
|
71
|
+
const radioInputIsFocused = inputEls.some((el) => el === focusedElement);
|
|
72
|
+
if (radioInputIsFocused)
|
|
73
|
+
focusedElement?.blur();
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Returns the state details of a radio input
|
|
77
|
+
*/
|
|
78
|
+
getRadioState,
|
|
79
|
+
rootProps: normalize.element({
|
|
80
|
+
...parts.root.attrs,
|
|
81
|
+
role: "radiogroup",
|
|
82
|
+
id: dom.getRootId(state.context),
|
|
83
|
+
"aria-labelledby": dom.getLabelId(state.context),
|
|
84
|
+
"data-orientation": state.context.orientation,
|
|
85
|
+
"aria-orientation": state.context.orientation,
|
|
86
|
+
dir: state.context.dir
|
|
87
|
+
}),
|
|
88
|
+
labelProps: normalize.element({
|
|
89
|
+
...parts.label.attrs,
|
|
90
|
+
id: dom.getLabelId(state.context),
|
|
91
|
+
onClick: focus
|
|
92
|
+
}),
|
|
93
|
+
getRadioProps(props) {
|
|
94
|
+
const rootState = getRadioState(props);
|
|
95
|
+
return normalize.label({
|
|
96
|
+
...parts.radio.attrs,
|
|
97
|
+
id: dom.getRadioId(state.context, props.value),
|
|
98
|
+
htmlFor: dom.getRadioInputId(state.context, props.value),
|
|
99
|
+
...getRadioDataAttrs(props),
|
|
100
|
+
onPointerMove() {
|
|
101
|
+
if (!rootState.isInteractive)
|
|
102
|
+
return;
|
|
103
|
+
send({ type: "SET_HOVERED", value: props.value, hovered: true });
|
|
104
|
+
},
|
|
105
|
+
onPointerLeave() {
|
|
106
|
+
if (!rootState.isInteractive)
|
|
107
|
+
return;
|
|
108
|
+
send({ type: "SET_HOVERED", value: null });
|
|
109
|
+
},
|
|
110
|
+
onPointerDown(event) {
|
|
111
|
+
if (!rootState.isInteractive)
|
|
112
|
+
return;
|
|
113
|
+
if (rootState.isFocused && event.pointerType === "mouse") {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
}
|
|
116
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
117
|
+
},
|
|
118
|
+
onPointerUp() {
|
|
119
|
+
if (!rootState.isInteractive)
|
|
120
|
+
return;
|
|
121
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
getRadioLabelProps(props) {
|
|
126
|
+
return normalize.element({
|
|
127
|
+
...parts.radioLabel.attrs,
|
|
128
|
+
id: dom.getRadioLabelId(state.context, props.value),
|
|
129
|
+
...getRadioDataAttrs(props)
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
getRadioControlProps(props) {
|
|
133
|
+
const controlState = getRadioState(props);
|
|
134
|
+
return normalize.element({
|
|
135
|
+
...parts.radioControl.attrs,
|
|
136
|
+
id: dom.getRadioControlId(state.context, props.value),
|
|
137
|
+
"data-active": dataAttr(controlState.isActive),
|
|
138
|
+
"aria-hidden": true,
|
|
139
|
+
...getRadioDataAttrs(props)
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
getRadioInputProps(props) {
|
|
143
|
+
const inputState = getRadioState(props);
|
|
144
|
+
const isRequired = props.required;
|
|
145
|
+
const trulyDisabled = inputState.isDisabled && !props.focusable;
|
|
146
|
+
return normalize.input({
|
|
147
|
+
...parts.radioInput.attrs,
|
|
148
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
149
|
+
id: dom.getRadioInputId(state.context, props.value),
|
|
150
|
+
type: "radio",
|
|
151
|
+
name: state.context.name || state.context.id,
|
|
152
|
+
form: state.context.form,
|
|
153
|
+
value: props.value,
|
|
154
|
+
onChange(event) {
|
|
155
|
+
if (inputState.isReadOnly || inputState.isDisabled) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (event.target.checked) {
|
|
159
|
+
send({ type: "SET_VALUE", value: props.value });
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
onBlur() {
|
|
163
|
+
send({ type: "SET_FOCUSED", value: null });
|
|
164
|
+
},
|
|
165
|
+
onFocus() {
|
|
166
|
+
send({ type: "SET_FOCUSED", value: props.value, focused: true });
|
|
167
|
+
},
|
|
168
|
+
onKeyDown(event) {
|
|
169
|
+
if (event.key === " ") {
|
|
170
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
onKeyUp(event) {
|
|
174
|
+
if (event.key === " ") {
|
|
175
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
disabled: trulyDisabled,
|
|
179
|
+
required: isRequired,
|
|
180
|
+
defaultChecked: inputState.isChecked,
|
|
181
|
+
"data-disabled": dataAttr(inputState.isDisabled),
|
|
182
|
+
"aria-required": ariaAttr(isRequired),
|
|
183
|
+
"aria-invalid": ariaAttr(inputState.isInvalid),
|
|
184
|
+
readOnly: inputState.isReadOnly,
|
|
185
|
+
"data-readonly": dataAttr(inputState.isReadOnly),
|
|
186
|
+
"aria-disabled": ariaAttr(trulyDisabled),
|
|
187
|
+
"aria-checked": ariaAttr(inputState.isChecked),
|
|
188
|
+
style: visuallyHiddenStyle
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
indicatorProps: normalize.element({
|
|
192
|
+
id: dom.getIndicatorId(state.context),
|
|
193
|
+
...parts.indicator.attrs,
|
|
194
|
+
"data-orientation": state.context.orientation,
|
|
195
|
+
style: {
|
|
196
|
+
"--transition-duration": "150ms",
|
|
197
|
+
"--transition-property": "left, top, width, height",
|
|
198
|
+
position: "absolute",
|
|
199
|
+
willChange: "var(--transition-property)",
|
|
200
|
+
transitionProperty: "var(--transition-property)",
|
|
201
|
+
transitionDuration: state.context.canIndicatorTransition ? "var(--transition-duration)" : "0ms",
|
|
202
|
+
transitionTimingFunction: "var(--transition-timing-function)",
|
|
203
|
+
...state.context.indicatorRect
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { connect };
|
|
@@ -1,48 +1,45 @@
|
|
|
1
|
-
import { MachineContext } from
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
|
|
5
|
-
declare const dom: {
|
|
1
|
+
import type { MachineContext as Ctx } from "./radio-group.types";
|
|
2
|
+
export declare const dom: {
|
|
6
3
|
getRootNode: (ctx: {
|
|
7
|
-
getRootNode?: (() => Node |
|
|
8
|
-
}) =>
|
|
4
|
+
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
5
|
+
}) => ShadowRoot | Document;
|
|
9
6
|
getDoc: (ctx: {
|
|
10
|
-
getRootNode?: (() => Node |
|
|
7
|
+
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
11
8
|
}) => Document;
|
|
12
9
|
getWin: (ctx: {
|
|
13
|
-
getRootNode?: (() => Node |
|
|
10
|
+
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
14
11
|
}) => Window & typeof globalThis;
|
|
15
12
|
getActiveElement: (ctx: {
|
|
16
|
-
getRootNode?: (() => Node |
|
|
13
|
+
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
17
14
|
}) => HTMLElement | null;
|
|
18
15
|
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
19
|
-
getRootNode?: (() => Node |
|
|
16
|
+
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
20
17
|
}, id: string) => T | null;
|
|
21
18
|
queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
|
|
22
|
-
getRootNode?: (() => Node |
|
|
19
|
+
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
23
20
|
}, id: string) => T_1;
|
|
24
21
|
} & {
|
|
25
|
-
getRootId: (ctx:
|
|
26
|
-
getLabelId: (ctx:
|
|
27
|
-
getRadioId: (ctx:
|
|
28
|
-
getRadioInputId: (ctx:
|
|
29
|
-
getRadioControlId: (ctx:
|
|
30
|
-
getRadioLabelId: (ctx:
|
|
31
|
-
getIndicatorId: (ctx:
|
|
32
|
-
getRootEl: (ctx:
|
|
33
|
-
getRadioInputEl: (ctx:
|
|
34
|
-
getIndicatorEl: (ctx:
|
|
35
|
-
getFirstEnabledInputEl: (ctx:
|
|
36
|
-
getFirstEnabledAndCheckedInputEl: (ctx:
|
|
37
|
-
getInputEls: (ctx:
|
|
38
|
-
getActiveRadioEl: (ctx:
|
|
22
|
+
getRootId: (ctx: Ctx) => string;
|
|
23
|
+
getLabelId: (ctx: Ctx) => string;
|
|
24
|
+
getRadioId: (ctx: Ctx, value: string) => string;
|
|
25
|
+
getRadioInputId: (ctx: Ctx, value: string) => string;
|
|
26
|
+
getRadioControlId: (ctx: Ctx, value: string) => string;
|
|
27
|
+
getRadioLabelId: (ctx: Ctx, value: string) => string;
|
|
28
|
+
getIndicatorId: (ctx: Ctx) => string;
|
|
29
|
+
getRootEl: (ctx: Ctx) => HTMLElement | null;
|
|
30
|
+
getRadioInputEl: (ctx: Ctx, value: string) => HTMLInputElement | null;
|
|
31
|
+
getIndicatorEl: (ctx: Ctx) => HTMLElement | null;
|
|
32
|
+
getFirstEnabledInputEl: (ctx: Ctx) => HTMLInputElement | null | undefined;
|
|
33
|
+
getFirstEnabledAndCheckedInputEl: (ctx: Ctx) => HTMLInputElement | null | undefined;
|
|
34
|
+
getInputEls: (ctx: Ctx) => HTMLInputElement[];
|
|
35
|
+
getActiveRadioEl: (ctx: Ctx) => HTMLElement | null | undefined;
|
|
39
36
|
getOffsetRect: (el: HTMLElement | undefined) => {
|
|
40
37
|
left: number;
|
|
41
38
|
top: number;
|
|
42
39
|
width: number;
|
|
43
40
|
height: number;
|
|
44
41
|
};
|
|
45
|
-
getRectById: (ctx:
|
|
42
|
+
getRectById: (ctx: Ctx, id: string) => {
|
|
46
43
|
width: string;
|
|
47
44
|
height: string;
|
|
48
45
|
left: string;
|
|
@@ -55,5 +52,3 @@ declare const dom: {
|
|
|
55
52
|
top: string;
|
|
56
53
|
};
|
|
57
54
|
};
|
|
58
|
-
|
|
59
|
-
export { dom };
|
package/dist/radio-group.dom.js
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
module.exports = __toCommonJS(radio_group_dom_exports);
|
|
26
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
27
|
-
var dom = (0, import_dom_query.createScope)({
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const domQuery = require('@zag-js/dom-query');
|
|
6
|
+
|
|
7
|
+
const dom = domQuery.createScope({
|
|
28
8
|
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
29
9
|
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
30
10
|
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
@@ -40,7 +20,7 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
40
20
|
getInputEls: (ctx) => {
|
|
41
21
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
42
22
|
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
43
|
-
return
|
|
23
|
+
return domQuery.queryAll(dom.getRootEl(ctx), selector);
|
|
44
24
|
},
|
|
45
25
|
getActiveRadioEl: (ctx) => {
|
|
46
26
|
if (!ctx.value)
|
|
@@ -68,7 +48,5 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
68
48
|
};
|
|
69
49
|
}
|
|
70
50
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
dom
|
|
74
|
-
});
|
|
51
|
+
|
|
52
|
+
exports.dom = dom;
|
package/dist/radio-group.dom.mjs
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { createScope, queryAll } from '@zag-js/dom-query';
|
|
2
|
+
|
|
3
|
+
const 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 { dom };
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import type { Machine, StateMachine } from '@zag-js/core';
|
|
2
|
+
import type { MachineContext, MachineState, UserDefinedContext } from "./radio-group.types";
|
|
3
|
+
export declare function machine(userContext: UserDefinedContext): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|