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