@zag-js/radio-group 1.46.0 → 1.48.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.
@@ -1,253 +1,250 @@
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
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
34
4
  });
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.js");
40
- var dom = __toESM(require("./radio-group.dom.js"));
5
+ const require_radio_group_anatomy = require("./radio-group.anatomy.js");
6
+ const require_radio_group_dom = require("./radio-group.dom.js");
7
+ let _zag_js_dom_query = require("@zag-js/dom-query");
8
+ let _zag_js_focus_visible = require("@zag-js/focus-visible");
9
+ let _zag_js_utils = require("@zag-js/utils");
10
+ // src/radio-group.connect.ts
41
11
  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-labelledby": dom.getItemLabelId(scope, props.value),
184
- "aria-invalid": itemState.invalid || void 0,
185
- onClick(event) {
186
- if (readOnly) {
187
- event.preventDefault();
188
- return;
189
- }
190
- if (event.currentTarget.checked) {
191
- send({ type: "SET_VALUE", value: props.value, isTrusted: true });
192
- }
193
- },
194
- onBlur() {
195
- send({ type: "SET_FOCUSED", value: null, focused: false, focusVisible: false });
196
- },
197
- onFocus() {
198
- const focusVisible = (0, import_focus_visible.isFocusVisible)();
199
- send({ type: "SET_FOCUSED", value: props.value, focused: true, focusVisible });
200
- },
201
- onKeyDown(event) {
202
- if (event.defaultPrevented) return;
203
- if (event.key === " ") {
204
- send({ type: "SET_ACTIVE", value: props.value, active: true });
205
- }
206
- },
207
- onKeyUp(event) {
208
- if (event.defaultPrevented) return;
209
- if (event.key === " ") {
210
- send({ type: "SET_ACTIVE", value: null });
211
- }
212
- },
213
- disabled: itemState.disabled || readOnly,
214
- defaultChecked: itemState.checked,
215
- style: import_dom_query.visuallyHiddenStyle
216
- });
217
- },
218
- getIndicatorProps() {
219
- const rect = context.get("indicatorRect");
220
- const animateIndicator = context.get("animateIndicator");
221
- return normalize.element({
222
- id: dom.getIndicatorId(scope),
223
- ...import_radio_group.parts.indicator.attrs,
224
- dir: prop("dir"),
225
- hidden: context.get("value") == null || isRectEmpty(rect),
226
- "data-disabled": (0, import_dom_query.dataAttr)(groupDisabled),
227
- "data-orientation": prop("orientation"),
228
- onTransitionEnd(event) {
229
- if ((0, import_dom_query.getEventTarget)(event) !== event.currentTarget) return;
230
- send({ type: "INDICATOR_TRANSITION_END" });
231
- },
232
- style: {
233
- "--transition-property": "left, top, width, height",
234
- "--left": (0, import_utils.toPx)(rect?.x),
235
- "--top": (0, import_utils.toPx)(rect?.y),
236
- "--width": (0, import_utils.toPx)(rect?.width),
237
- "--height": (0, import_utils.toPx)(rect?.height),
238
- position: "absolute",
239
- willChange: animateIndicator ? "var(--transition-property)" : "auto",
240
- transitionProperty: animateIndicator ? "var(--transition-property)" : "none",
241
- transitionDuration: animateIndicator ? "var(--transition-duration, 150ms)" : "0ms",
242
- transitionTimingFunction: "var(--transition-timing-function)",
243
- [prop("orientation") === "horizontal" ? "left" : "top"]: prop("orientation") === "horizontal" ? "var(--left)" : "var(--top)"
244
- }
245
- });
246
- }
247
- };
12
+ const { context, send, computed, prop, scope } = service;
13
+ const groupDisabled = computed("isDisabled");
14
+ const groupInvalid = prop("invalid");
15
+ const readOnly = prop("readOnly");
16
+ function getItemState(props) {
17
+ return {
18
+ value: props.value,
19
+ invalid: !!props.invalid || !!groupInvalid,
20
+ disabled: !!props.disabled || groupDisabled,
21
+ checked: context.get("value") === props.value,
22
+ focused: context.get("focusedValue") === props.value,
23
+ focusVisible: context.get("focusVisibleValue") === props.value,
24
+ hovered: context.get("hoveredValue") === props.value,
25
+ active: context.get("activeValue") === props.value
26
+ };
27
+ }
28
+ function getItemDataAttrs(props) {
29
+ const itemState = getItemState(props);
30
+ return {
31
+ "data-focus": (0, _zag_js_dom_query.dataAttr)(itemState.focused),
32
+ "data-focus-visible": (0, _zag_js_dom_query.dataAttr)(itemState.focusVisible),
33
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(itemState.disabled),
34
+ "data-readonly": (0, _zag_js_dom_query.dataAttr)(readOnly),
35
+ "data-state": itemState.checked ? "checked" : "unchecked",
36
+ "data-hover": (0, _zag_js_dom_query.dataAttr)(itemState.hovered),
37
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(itemState.invalid),
38
+ "data-orientation": prop("orientation"),
39
+ "data-ssr": (0, _zag_js_dom_query.dataAttr)(context.get("ssr"))
40
+ };
41
+ }
42
+ const focus = () => {
43
+ (require_radio_group_dom.getFirstEnabledAndCheckedInputEl(scope) ?? require_radio_group_dom.getFirstEnabledInputEl(scope))?.focus();
44
+ };
45
+ return {
46
+ focus,
47
+ value: context.get("value"),
48
+ setValue(value) {
49
+ send({
50
+ type: "SET_VALUE",
51
+ value,
52
+ isTrusted: false
53
+ });
54
+ },
55
+ clearValue() {
56
+ send({
57
+ type: "SET_VALUE",
58
+ value: null,
59
+ isTrusted: false
60
+ });
61
+ },
62
+ getRootProps() {
63
+ return normalize.element({
64
+ ...require_radio_group_anatomy.parts.root.attrs,
65
+ role: "radiogroup",
66
+ id: require_radio_group_dom.getRootId(scope),
67
+ "aria-labelledby": require_radio_group_dom.getLabelId(scope),
68
+ "aria-required": prop("required") || void 0,
69
+ "aria-disabled": groupDisabled || void 0,
70
+ "aria-readonly": readOnly || void 0,
71
+ "data-orientation": prop("orientation"),
72
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(groupDisabled),
73
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(groupInvalid),
74
+ "data-required": (0, _zag_js_dom_query.dataAttr)(prop("required")),
75
+ "aria-orientation": prop("orientation"),
76
+ dir: prop("dir"),
77
+ style: { position: "relative" }
78
+ });
79
+ },
80
+ getLabelProps() {
81
+ return normalize.element({
82
+ ...require_radio_group_anatomy.parts.label.attrs,
83
+ dir: prop("dir"),
84
+ "data-orientation": prop("orientation"),
85
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(groupDisabled),
86
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(groupInvalid),
87
+ "data-required": (0, _zag_js_dom_query.dataAttr)(prop("required")),
88
+ id: require_radio_group_dom.getLabelId(scope),
89
+ onClick: focus
90
+ });
91
+ },
92
+ getItemState,
93
+ getItemProps(props) {
94
+ const itemState = getItemState(props);
95
+ return normalize.label({
96
+ ...require_radio_group_anatomy.parts.item.attrs,
97
+ dir: prop("dir"),
98
+ id: require_radio_group_dom.getItemId(scope, props.value),
99
+ htmlFor: require_radio_group_dom.getItemHiddenInputId(scope, props.value),
100
+ ...getItemDataAttrs(props),
101
+ onPointerMove() {
102
+ if (itemState.disabled) return;
103
+ if (itemState.hovered) return;
104
+ send({
105
+ type: "SET_HOVERED",
106
+ value: props.value,
107
+ hovered: true
108
+ });
109
+ },
110
+ onPointerLeave() {
111
+ if (itemState.disabled) return;
112
+ send({
113
+ type: "SET_HOVERED",
114
+ value: null
115
+ });
116
+ },
117
+ onPointerDown(event) {
118
+ if (itemState.disabled) return;
119
+ if (!(0, _zag_js_dom_query.isLeftClick)(event)) return;
120
+ if (itemState.focused && event.pointerType === "mouse") event.preventDefault();
121
+ send({
122
+ type: "SET_ACTIVE",
123
+ value: props.value,
124
+ active: true
125
+ });
126
+ },
127
+ onPointerUp() {
128
+ if (itemState.disabled) return;
129
+ send({
130
+ type: "SET_ACTIVE",
131
+ value: null
132
+ });
133
+ },
134
+ onClick() {
135
+ if (!itemState.disabled && (0, _zag_js_dom_query.isSafari)()) require_radio_group_dom.getItemHiddenInputEl(scope, props.value)?.focus();
136
+ }
137
+ });
138
+ },
139
+ getItemTextProps(props) {
140
+ return normalize.element({
141
+ ...require_radio_group_anatomy.parts.itemText.attrs,
142
+ dir: prop("dir"),
143
+ id: require_radio_group_dom.getItemLabelId(scope, props.value),
144
+ ...getItemDataAttrs(props)
145
+ });
146
+ },
147
+ getItemControlProps(props) {
148
+ const itemState = getItemState(props);
149
+ return normalize.element({
150
+ ...require_radio_group_anatomy.parts.itemControl.attrs,
151
+ dir: prop("dir"),
152
+ id: require_radio_group_dom.getItemControlId(scope, props.value),
153
+ "data-active": (0, _zag_js_dom_query.dataAttr)(itemState.active),
154
+ "aria-hidden": true,
155
+ ...getItemDataAttrs(props)
156
+ });
157
+ },
158
+ getItemHiddenInputProps(props) {
159
+ const itemState = getItemState(props);
160
+ return normalize.input({
161
+ "data-ownedby": require_radio_group_dom.getRootId(scope),
162
+ id: require_radio_group_dom.getItemHiddenInputId(scope, props.value),
163
+ type: "radio",
164
+ name: prop("name") || prop("id"),
165
+ form: prop("form"),
166
+ value: props.value,
167
+ required: prop("required"),
168
+ "aria-labelledby": require_radio_group_dom.getItemLabelId(scope, props.value),
169
+ "aria-invalid": itemState.invalid || void 0,
170
+ onClick(event) {
171
+ if (readOnly) {
172
+ event.preventDefault();
173
+ return;
174
+ }
175
+ if (event.currentTarget.checked) send({
176
+ type: "SET_VALUE",
177
+ value: props.value,
178
+ isTrusted: true
179
+ });
180
+ },
181
+ onBlur() {
182
+ send({
183
+ type: "SET_FOCUSED",
184
+ value: null,
185
+ focused: false,
186
+ focusVisible: false
187
+ });
188
+ },
189
+ onFocus() {
190
+ const focusVisible = (0, _zag_js_focus_visible.isFocusVisible)();
191
+ send({
192
+ type: "SET_FOCUSED",
193
+ value: props.value,
194
+ focused: true,
195
+ focusVisible
196
+ });
197
+ },
198
+ onKeyDown(event) {
199
+ if (event.defaultPrevented) return;
200
+ if (event.key === " ") send({
201
+ type: "SET_ACTIVE",
202
+ value: props.value,
203
+ active: true
204
+ });
205
+ },
206
+ onKeyUp(event) {
207
+ if (event.defaultPrevented) return;
208
+ if (event.key === " ") send({
209
+ type: "SET_ACTIVE",
210
+ value: null
211
+ });
212
+ },
213
+ disabled: itemState.disabled || readOnly,
214
+ defaultChecked: itemState.checked,
215
+ style: _zag_js_dom_query.visuallyHiddenStyle
216
+ });
217
+ },
218
+ getIndicatorProps() {
219
+ const rect = context.get("indicatorRect");
220
+ const animateIndicator = context.get("animateIndicator");
221
+ return normalize.element({
222
+ id: require_radio_group_dom.getIndicatorId(scope),
223
+ ...require_radio_group_anatomy.parts.indicator.attrs,
224
+ dir: prop("dir"),
225
+ hidden: context.get("value") == null || isRectEmpty(rect),
226
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(groupDisabled),
227
+ "data-orientation": prop("orientation"),
228
+ onTransitionEnd(event) {
229
+ if ((0, _zag_js_dom_query.getEventTarget)(event) !== event.currentTarget) return;
230
+ send({ type: "INDICATOR_TRANSITION_END" });
231
+ },
232
+ style: {
233
+ "--transition-property": "left, top, width, height",
234
+ "--left": (0, _zag_js_utils.toPx)(rect?.x),
235
+ "--top": (0, _zag_js_utils.toPx)(rect?.y),
236
+ "--width": (0, _zag_js_utils.toPx)(rect?.width),
237
+ "--height": (0, _zag_js_utils.toPx)(rect?.height),
238
+ position: "absolute",
239
+ willChange: animateIndicator ? "var(--transition-property)" : "auto",
240
+ transitionProperty: animateIndicator ? "var(--transition-property)" : "none",
241
+ transitionDuration: animateIndicator ? "var(--transition-duration, 150ms)" : "0ms",
242
+ transitionTimingFunction: "var(--transition-timing-function)",
243
+ [prop("orientation") === "horizontal" ? "left" : "top"]: prop("orientation") === "horizontal" ? "var(--left)" : "var(--top)"
244
+ }
245
+ });
246
+ }
247
+ };
248
248
  }
249
- var isRectEmpty = (rect) => rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
250
- // Annotate the CommonJS export names for ESM import in node:
251
- 0 && (module.exports = {
252
- connect
253
- });
249
+ const isRectEmpty = (rect) => rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
250
+ exports.connect = connect;