@zag-js/radio-group 0.53.0 → 0.55.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 CHANGED
@@ -122,21 +122,21 @@ interface MachineApi<T extends PropTypes = PropTypes> {
122
122
  * Returns the state details of a radio input
123
123
  */
124
124
  getItemState(props: ItemProps): ItemState;
125
- rootProps: T["element"];
126
- labelProps: T["element"];
125
+ getRootProps(): T["element"];
126
+ getLabelProps(): T["element"];
127
127
  getItemProps(props: ItemProps): T["label"];
128
128
  getItemTextProps(props: ItemProps): T["element"];
129
129
  getItemControlProps(props: ItemProps): T["element"];
130
130
  getItemHiddenInputProps(props: ItemProps): T["input"];
131
- indicatorProps: T["element"];
131
+ getIndicatorProps(): T["element"];
132
132
  }
133
133
 
134
134
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
135
135
 
136
136
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
137
137
 
138
- declare const props: ("value" | "dir" | "id" | "getRootNode" | "form" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange")[];
139
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "dir" | "id" | "getRootNode" | "form" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange">];
138
+ declare const props: ("form" | "value" | "dir" | "id" | "getRootNode" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange")[];
139
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "form" | "value" | "dir" | "id" | "getRootNode" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange">];
140
140
  declare const itemProps: (keyof ItemProps)[];
141
141
  declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
142
142
 
package/dist/index.d.ts CHANGED
@@ -122,21 +122,21 @@ interface MachineApi<T extends PropTypes = PropTypes> {
122
122
  * Returns the state details of a radio input
123
123
  */
124
124
  getItemState(props: ItemProps): ItemState;
125
- rootProps: T["element"];
126
- labelProps: T["element"];
125
+ getRootProps(): T["element"];
126
+ getLabelProps(): T["element"];
127
127
  getItemProps(props: ItemProps): T["label"];
128
128
  getItemTextProps(props: ItemProps): T["element"];
129
129
  getItemControlProps(props: ItemProps): T["element"];
130
130
  getItemHiddenInputProps(props: ItemProps): T["input"];
131
- indicatorProps: T["element"];
131
+ getIndicatorProps(): T["element"];
132
132
  }
133
133
 
134
134
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
135
135
 
136
136
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
137
137
 
138
- declare const props: ("value" | "dir" | "id" | "getRootNode" | "form" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange")[];
139
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "dir" | "id" | "getRootNode" | "form" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange">];
138
+ declare const props: ("form" | "value" | "dir" | "id" | "getRootNode" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange")[];
139
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "form" | "value" | "dir" | "id" | "getRootNode" | "name" | "disabled" | "orientation" | "ids" | "readOnly" | "onValueChange">];
140
140
  declare const itemProps: (keyof ItemProps)[];
141
141
  declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
142
142
 
package/dist/index.js CHANGED
@@ -1,2 +1,465 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{anatomy:()=>anatomy,connect:()=>connect,itemProps:()=>itemProps,machine:()=>machine,props:()=>props,splitItemProps:()=>splitItemProps,splitProps:()=>splitProps});module.exports=__toCommonJS(src_exports);var import_anatomy=require("@zag-js/anatomy");var anatomy=(0,import_anatomy.createAnatomy)("radio-group").parts("root","label","item","itemText","itemControl","indicator");var parts=anatomy.build();var import_dom_query2=require("@zag-js/dom-query");var import_dom_query=require("@zag-js/dom-query");var dom=(0,import_dom_query.createScope)({getRootId:ctx=>ctx.ids?.root??`radio-group:${ctx.id}`,getLabelId:ctx=>ctx.ids?.label??`radio-group:${ctx.id}:label`,getItemId:(ctx,value)=>ctx.ids?.item?.(value)??`radio-group:${ctx.id}:radio:${value}`,getItemHiddenInputId:(ctx,value)=>ctx.ids?.itemHiddenInput?.(value)??`radio-group:${ctx.id}:radio:input:${value}`,getItemControlId:(ctx,value)=>ctx.ids?.itemControl?.(value)??`radio-group:${ctx.id}:radio:control:${value}`,getItemLabelId:(ctx,value)=>ctx.ids?.itemLabel?.(value)??`radio-group:${ctx.id}:radio:label:${value}`,getIndicatorId:ctx=>ctx.ids?.indicator??`radio-group:${ctx.id}:indicator`,getRootEl:ctx=>dom.getById(ctx,dom.getRootId(ctx)),getItemHiddenInputEl:(ctx,value)=>dom.getById(ctx,dom.getItemHiddenInputId(ctx,value)),getIndicatorEl:ctx=>dom.getById(ctx,dom.getIndicatorId(ctx)),getFirstEnabledInputEl:ctx=>dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),getFirstEnabledAndCheckedInputEl:ctx=>dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),getInputEls:ctx=>{const ownerId=CSS.escape(dom.getRootId(ctx));const selector=`input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;return(0,import_dom_query.queryAll)(dom.getRootEl(ctx),selector)},getActiveRadioEl:ctx=>{if(!ctx.value)return;return dom.getById(ctx,dom.getItemId(ctx,ctx.value))},getOffsetRect:el=>({left:el?.offsetLeft??0,top:el?.offsetTop??0,width:el?.offsetWidth??0,height:el?.offsetHeight??0}),getRectById:(ctx,id)=>{const radioEl=dom.getById(ctx,dom.getItemId(ctx,id));if(!radioEl)return;return dom.resolveRect(dom.getOffsetRect(radioEl))},resolveRect:rect=>({width:`${rect.width}px`,height:`${rect.height}px`,left:`${rect.left}px`,top:`${rect.top}px`})});function connect(state,send,normalize){const groupDisabled=state.context.isDisabled;const readOnly=state.context.readOnly;function getItemState(props2){return{invalid:!!props2.invalid,disabled:!!props2.disabled||groupDisabled,checked:state.context.value===props2.value,focused:state.context.focusedValue===props2.value,hovered:state.context.hoveredValue===props2.value,active:state.context.activeValue===props2.value}}function getItemDataAttrs(props2){const radioState=getItemState(props2);return{"data-focus":(0,import_dom_query2.dataAttr)(radioState.focused),"data-disabled":(0,import_dom_query2.dataAttr)(radioState.disabled),"dats-readonly":(0,import_dom_query2.dataAttr)(readOnly),"data-state":radioState.checked?"checked":"unchecked","data-hover":(0,import_dom_query2.dataAttr)(radioState.hovered),"data-invalid":(0,import_dom_query2.dataAttr)(radioState.invalid),"data-orientation":state.context.orientation}}const focus=()=>{const firstEnabledAndCheckedInput=dom.getFirstEnabledAndCheckedInputEl(state.context);if(firstEnabledAndCheckedInput){firstEnabledAndCheckedInput.focus();return}const firstEnabledInput=dom.getFirstEnabledInputEl(state.context);firstEnabledInput?.focus()};return{focus,value:state.context.value,setValue(value){send({type:"SET_VALUE",value,isTrusted:false})},clearValue(){send({type:"SET_VALUE",value:null,isTrusted:false})},getItemState,rootProps:normalize.element({...parts.root.attrs,role:"radiogroup",id:dom.getRootId(state.context),"aria-labelledby":dom.getLabelId(state.context),"data-orientation":state.context.orientation,"data-disabled":(0,import_dom_query2.dataAttr)(groupDisabled),"aria-orientation":state.context.orientation,dir:state.context.dir,style:{position:"relative"}}),labelProps:normalize.element({...parts.label.attrs,dir:state.context.dir,"data-orientation":state.context.orientation,"data-disabled":(0,import_dom_query2.dataAttr)(groupDisabled),id:dom.getLabelId(state.context),onClick:focus}),getItemProps(props2){const itemState=getItemState(props2);return normalize.label({...parts.item.attrs,dir:state.context.dir,id:dom.getItemId(state.context,props2.value),htmlFor:dom.getItemHiddenInputId(state.context,props2.value),...getItemDataAttrs(props2),onPointerMove(){if(itemState.disabled)return;if(itemState.hovered)return;send({type:"SET_HOVERED",value:props2.value,hovered:true})},onPointerLeave(){if(itemState.disabled)return;send({type:"SET_HOVERED",value:null})},onPointerDown(event){if(itemState.disabled)return;if(itemState.focused&&event.pointerType==="mouse"){event.preventDefault()}send({type:"SET_ACTIVE",value:props2.value,active:true})},onPointerUp(){if(itemState.disabled)return;send({type:"SET_ACTIVE",value:null})}})},getItemTextProps(props2){return normalize.element({...parts.itemText.attrs,dir:state.context.dir,id:dom.getItemLabelId(state.context,props2.value),...getItemDataAttrs(props2)})},getItemControlProps(props2){const controlState=getItemState(props2);return normalize.element({...parts.itemControl.attrs,dir:state.context.dir,id:dom.getItemControlId(state.context,props2.value),"data-active":(0,import_dom_query2.dataAttr)(controlState.active),"aria-hidden":true,...getItemDataAttrs(props2)})},getItemHiddenInputProps(props2){const inputState=getItemState(props2);return normalize.input({"data-ownedby":dom.getRootId(state.context),id:dom.getItemHiddenInputId(state.context,props2.value),type:"radio",name:state.context.name||state.context.id,form:state.context.form,value:props2.value,onChange(event){if(readOnly){event.preventDefault();return}if(event.target.checked){send({type:"SET_VALUE",value:props2.value,isTrusted:true})}},onBlur(){send({type:"SET_FOCUSED",value:null})},onFocus(){send({type:"SET_FOCUSED",value:props2.value,focused:true})},onKeyDown(event){if(event.defaultPrevented)return;if(event.key===" "){send({type:"SET_ACTIVE",value:props2.value,active:true})}},onKeyUp(event){if(event.defaultPrevented)return;if(event.key===" "){send({type:"SET_ACTIVE",value:null})}},disabled:inputState.disabled,defaultChecked:inputState.checked,style:import_dom_query2.visuallyHiddenStyle})},indicatorProps:normalize.element({id:dom.getIndicatorId(state.context),...parts.indicator.attrs,dir:state.context.dir,hidden:state.context.value==null,"data-disabled":(0,import_dom_query2.dataAttr)(groupDisabled),"data-orientation":state.context.orientation,style:{"--transition-property":"left, top, width, height","--left":state.context.indicatorRect?.left,"--top":state.context.indicatorRect?.top,"--width":state.context.indicatorRect?.width,"--height":state.context.indicatorRect?.height,position:"absolute",willChange:"var(--transition-property)",transitionProperty:"var(--transition-property)",transitionDuration:state.context.canIndicatorTransition?"var(--transition-duration, 150ms)":"0ms",transitionTimingFunction:"var(--transition-timing-function)",[state.context.orientation==="horizontal"?"left":"top"]:state.context.orientation==="horizontal"?"var(--left)":"var(--top)"}})}}var import_core=require("@zag-js/core");var import_dom_query3=require("@zag-js/dom-query");var import_element_rect=require("@zag-js/element-rect");var import_form_utils=require("@zag-js/form-utils");var import_utils=require("@zag-js/utils");var{not}=import_core.guards;function machine(userContext){const ctx=(0,import_utils.compact)(userContext);return(0,import_core.createMachine)({id:"radio",initial:"idle",context:{value:null,activeValue:null,focusedValue:null,hoveredValue:null,disabled:false,orientation:"vertical",...ctx,indicatorRect:{},canIndicatorTransition:false,fieldsetDisabled:false},computed:{isDisabled:ctx2=>!!ctx2.disabled||ctx2.fieldsetDisabled},entry:["syncIndicatorRect"],exit:["cleanupObserver"],activities:["trackFormControlState"],watch:{value:["setIndicatorTransition","syncIndicatorRect","syncInputElements"]},on:{SET_VALUE:[{guard:not("isTrusted"),actions:["setValue","dispatchChangeEvent"]},{actions:["setValue"]}],SET_HOVERED:{actions:"setHovered"},SET_ACTIVE:{actions:"setActive"},SET_FOCUSED:{actions:"setFocused"}},states:{idle:{}}},{guards:{isTrusted:(_ctx,evt)=>!!evt.isTrusted},activities:{trackFormControlState(ctx2,_evt,{send,initialContext}){return(0,import_form_utils.trackFormControl)(dom.getRootEl(ctx2),{onFieldsetDisabledChange(disabled){ctx2.fieldsetDisabled=disabled},onFormReset(){send({type:"SET_VALUE",value:initialContext.value})}})}},actions:{setValue(ctx2,evt){set.value(ctx2,evt.value)},setHovered(ctx2,evt){ctx2.hoveredValue=evt.value},setActive(ctx2,evt){ctx2.activeValue=evt.value},setFocused(ctx2,evt){ctx2.focusedValue=evt.value},syncInputElements(ctx2){const inputs=dom.getInputEls(ctx2);inputs.forEach(input=>{input.checked=input.value===ctx2.value})},setIndicatorTransition(ctx2){ctx2.canIndicatorTransition=(0,import_utils.isString)(ctx2.value)},cleanupObserver(ctx2){ctx2.indicatorCleanup?.()},syncIndicatorRect(ctx2){ctx2.indicatorCleanup?.();if(!dom.getIndicatorEl(ctx2))return;const value=ctx2.value;const radioEl=dom.getActiveRadioEl(ctx2);if(value==null||!radioEl){ctx2.indicatorRect={};return}ctx2.indicatorCleanup=(0,import_element_rect.trackElementRect)(radioEl,{getRect(el){return dom.getOffsetRect(el)},onChange(rect){ctx2.indicatorRect=dom.resolveRect(rect);(0,import_dom_query3.nextTick)(()=>{ctx2.canIndicatorTransition=false})}})},dispatchChangeEvent(ctx2){const inputEls=dom.getInputEls(ctx2);inputEls.forEach(inputEl=>{const checked=inputEl.value===ctx2.value;if(checked===inputEl.checked)return;(0,import_form_utils.dispatchInputCheckedEvent)(inputEl,{checked})})}}})}var invoke={change:ctx=>{if(ctx.value==null)return;ctx.onValueChange?.({value:ctx.value})}};var set={value:(ctx,value)=>{if((0,import_utils.isEqual)(ctx.value,value))return;ctx.value=value;invoke.change(ctx)}};var import_types=require("@zag-js/types");var import_utils2=require("@zag-js/utils");var props=(0,import_types.createProps)()(["dir","disabled","form","getRootNode","id","ids","name","onValueChange","orientation","readOnly","value"]);var splitProps=(0,import_utils2.createSplitProps)(props);var itemProps=(0,import_types.createProps)()(["value","disabled","invalid"]);var splitItemProps=(0,import_utils2.createSplitProps)(itemProps);0&&(module.exports={anatomy,connect,itemProps,machine,props,splitItemProps,splitProps});
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/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ anatomy: () => anatomy,
24
+ connect: () => connect,
25
+ itemProps: () => itemProps,
26
+ machine: () => machine,
27
+ props: () => props,
28
+ splitItemProps: () => splitItemProps,
29
+ splitProps: () => splitProps
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+
33
+ // src/radio-group.anatomy.ts
34
+ var import_anatomy = require("@zag-js/anatomy");
35
+ var anatomy = (0, import_anatomy.createAnatomy)("radio-group").parts(
36
+ "root",
37
+ "label",
38
+ "item",
39
+ "itemText",
40
+ "itemControl",
41
+ "indicator"
42
+ );
43
+ var parts = anatomy.build();
44
+
45
+ // src/radio-group.connect.ts
46
+ var import_dom_query2 = require("@zag-js/dom-query");
47
+
48
+ // src/radio-group.dom.ts
49
+ var import_dom_query = require("@zag-js/dom-query");
50
+ var dom = (0, import_dom_query.createScope)({
51
+ getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
52
+ getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
53
+ getItemId: (ctx, value) => ctx.ids?.item?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
54
+ getItemHiddenInputId: (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
55
+ getItemControlId: (ctx, value) => ctx.ids?.itemControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
56
+ getItemLabelId: (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
57
+ getIndicatorId: (ctx) => ctx.ids?.indicator ?? `radio-group:${ctx.id}:indicator`,
58
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
59
+ getItemHiddenInputEl: (ctx, value) => dom.getById(ctx, dom.getItemHiddenInputId(ctx, value)),
60
+ getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
61
+ getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
62
+ getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
63
+ getInputEls: (ctx) => {
64
+ const ownerId = CSS.escape(dom.getRootId(ctx));
65
+ const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
66
+ return (0, import_dom_query.queryAll)(dom.getRootEl(ctx), selector);
67
+ },
68
+ getActiveRadioEl: (ctx) => {
69
+ if (!ctx.value)
70
+ return;
71
+ return dom.getById(ctx, dom.getItemId(ctx, ctx.value));
72
+ },
73
+ getOffsetRect: (el) => ({
74
+ left: el?.offsetLeft ?? 0,
75
+ top: el?.offsetTop ?? 0,
76
+ width: el?.offsetWidth ?? 0,
77
+ height: el?.offsetHeight ?? 0
78
+ }),
79
+ getRectById: (ctx, id) => {
80
+ const radioEl = dom.getById(ctx, dom.getItemId(ctx, id));
81
+ if (!radioEl)
82
+ return;
83
+ return dom.resolveRect(dom.getOffsetRect(radioEl));
84
+ },
85
+ resolveRect: (rect) => ({
86
+ width: `${rect.width}px`,
87
+ height: `${rect.height}px`,
88
+ left: `${rect.left}px`,
89
+ top: `${rect.top}px`
90
+ })
91
+ });
92
+
93
+ // src/radio-group.connect.ts
94
+ function connect(state, send, normalize) {
95
+ const groupDisabled = state.context.isDisabled;
96
+ const readOnly = state.context.readOnly;
97
+ function getItemState(props2) {
98
+ return {
99
+ invalid: !!props2.invalid,
100
+ disabled: !!props2.disabled || groupDisabled,
101
+ checked: state.context.value === props2.value,
102
+ focused: state.context.focusedValue === props2.value,
103
+ hovered: state.context.hoveredValue === props2.value,
104
+ active: state.context.activeValue === props2.value
105
+ };
106
+ }
107
+ function getItemDataAttrs(props2) {
108
+ const radioState = getItemState(props2);
109
+ return {
110
+ "data-focus": (0, import_dom_query2.dataAttr)(radioState.focused),
111
+ "data-disabled": (0, import_dom_query2.dataAttr)(radioState.disabled),
112
+ "dats-readonly": (0, import_dom_query2.dataAttr)(readOnly),
113
+ "data-state": radioState.checked ? "checked" : "unchecked",
114
+ "data-hover": (0, import_dom_query2.dataAttr)(radioState.hovered),
115
+ "data-invalid": (0, import_dom_query2.dataAttr)(radioState.invalid),
116
+ "data-orientation": state.context.orientation
117
+ };
118
+ }
119
+ const focus = () => {
120
+ const firstEnabledAndCheckedInput = dom.getFirstEnabledAndCheckedInputEl(state.context);
121
+ if (firstEnabledAndCheckedInput) {
122
+ firstEnabledAndCheckedInput.focus();
123
+ return;
124
+ }
125
+ const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
126
+ firstEnabledInput?.focus();
127
+ };
128
+ return {
129
+ focus,
130
+ value: state.context.value,
131
+ setValue(value) {
132
+ send({ type: "SET_VALUE", value, isTrusted: false });
133
+ },
134
+ clearValue() {
135
+ send({ type: "SET_VALUE", value: null, isTrusted: false });
136
+ },
137
+ getRootProps() {
138
+ return normalize.element({
139
+ ...parts.root.attrs,
140
+ role: "radiogroup",
141
+ id: dom.getRootId(state.context),
142
+ "aria-labelledby": dom.getLabelId(state.context),
143
+ "data-orientation": state.context.orientation,
144
+ "data-disabled": (0, import_dom_query2.dataAttr)(groupDisabled),
145
+ "aria-orientation": state.context.orientation,
146
+ dir: state.context.dir,
147
+ style: {
148
+ position: "relative"
149
+ }
150
+ });
151
+ },
152
+ getLabelProps() {
153
+ return normalize.element({
154
+ ...parts.label.attrs,
155
+ dir: state.context.dir,
156
+ "data-orientation": state.context.orientation,
157
+ "data-disabled": (0, import_dom_query2.dataAttr)(groupDisabled),
158
+ id: dom.getLabelId(state.context),
159
+ onClick: focus
160
+ });
161
+ },
162
+ getItemState,
163
+ getItemProps(props2) {
164
+ const itemState = getItemState(props2);
165
+ return normalize.label({
166
+ ...parts.item.attrs,
167
+ dir: state.context.dir,
168
+ id: dom.getItemId(state.context, props2.value),
169
+ htmlFor: dom.getItemHiddenInputId(state.context, props2.value),
170
+ ...getItemDataAttrs(props2),
171
+ onPointerMove() {
172
+ if (itemState.disabled)
173
+ return;
174
+ if (itemState.hovered)
175
+ return;
176
+ send({ type: "SET_HOVERED", value: props2.value, hovered: true });
177
+ },
178
+ onPointerLeave() {
179
+ if (itemState.disabled)
180
+ return;
181
+ send({ type: "SET_HOVERED", value: null });
182
+ },
183
+ onPointerDown(event) {
184
+ if (itemState.disabled)
185
+ return;
186
+ if (itemState.focused && event.pointerType === "mouse") {
187
+ event.preventDefault();
188
+ }
189
+ send({ type: "SET_ACTIVE", value: props2.value, active: true });
190
+ },
191
+ onPointerUp() {
192
+ if (itemState.disabled)
193
+ return;
194
+ send({ type: "SET_ACTIVE", value: null });
195
+ }
196
+ });
197
+ },
198
+ getItemTextProps(props2) {
199
+ return normalize.element({
200
+ ...parts.itemText.attrs,
201
+ dir: state.context.dir,
202
+ id: dom.getItemLabelId(state.context, props2.value),
203
+ ...getItemDataAttrs(props2)
204
+ });
205
+ },
206
+ getItemControlProps(props2) {
207
+ const controlState = getItemState(props2);
208
+ return normalize.element({
209
+ ...parts.itemControl.attrs,
210
+ dir: state.context.dir,
211
+ id: dom.getItemControlId(state.context, props2.value),
212
+ "data-active": (0, import_dom_query2.dataAttr)(controlState.active),
213
+ "aria-hidden": true,
214
+ ...getItemDataAttrs(props2)
215
+ });
216
+ },
217
+ getItemHiddenInputProps(props2) {
218
+ const inputState = getItemState(props2);
219
+ return normalize.input({
220
+ "data-ownedby": dom.getRootId(state.context),
221
+ id: dom.getItemHiddenInputId(state.context, props2.value),
222
+ type: "radio",
223
+ name: state.context.name || state.context.id,
224
+ form: state.context.form,
225
+ value: props2.value,
226
+ onChange(event) {
227
+ if (readOnly) {
228
+ event.preventDefault();
229
+ return;
230
+ }
231
+ if (event.target.checked) {
232
+ send({ type: "SET_VALUE", value: props2.value, isTrusted: true });
233
+ }
234
+ },
235
+ onBlur() {
236
+ send({ type: "SET_FOCUSED", value: null });
237
+ },
238
+ onFocus() {
239
+ send({ type: "SET_FOCUSED", value: props2.value, focused: true });
240
+ },
241
+ onKeyDown(event) {
242
+ if (event.defaultPrevented)
243
+ return;
244
+ if (event.key === " ") {
245
+ send({ type: "SET_ACTIVE", value: props2.value, active: true });
246
+ }
247
+ },
248
+ onKeyUp(event) {
249
+ if (event.defaultPrevented)
250
+ return;
251
+ if (event.key === " ") {
252
+ send({ type: "SET_ACTIVE", value: null });
253
+ }
254
+ },
255
+ disabled: inputState.disabled,
256
+ defaultChecked: inputState.checked,
257
+ style: import_dom_query2.visuallyHiddenStyle
258
+ });
259
+ },
260
+ getIndicatorProps() {
261
+ return normalize.element({
262
+ id: dom.getIndicatorId(state.context),
263
+ ...parts.indicator.attrs,
264
+ dir: state.context.dir,
265
+ hidden: state.context.value == null,
266
+ "data-disabled": (0, import_dom_query2.dataAttr)(groupDisabled),
267
+ "data-orientation": state.context.orientation,
268
+ style: {
269
+ "--transition-property": "left, top, width, height",
270
+ "--left": state.context.indicatorRect?.left,
271
+ "--top": state.context.indicatorRect?.top,
272
+ "--width": state.context.indicatorRect?.width,
273
+ "--height": state.context.indicatorRect?.height,
274
+ position: "absolute",
275
+ willChange: "var(--transition-property)",
276
+ transitionProperty: "var(--transition-property)",
277
+ transitionDuration: state.context.canIndicatorTransition ? "var(--transition-duration, 150ms)" : "0ms",
278
+ transitionTimingFunction: "var(--transition-timing-function)",
279
+ [state.context.orientation === "horizontal" ? "left" : "top"]: state.context.orientation === "horizontal" ? "var(--left)" : "var(--top)"
280
+ }
281
+ });
282
+ }
283
+ };
284
+ }
285
+
286
+ // src/radio-group.machine.ts
287
+ var import_core = require("@zag-js/core");
288
+ var import_dom_query3 = require("@zag-js/dom-query");
289
+ var import_element_rect = require("@zag-js/element-rect");
290
+ var import_form_utils = require("@zag-js/form-utils");
291
+ var import_utils = require("@zag-js/utils");
292
+ var { not } = import_core.guards;
293
+ function machine(userContext) {
294
+ const ctx = (0, import_utils.compact)(userContext);
295
+ return (0, import_core.createMachine)(
296
+ {
297
+ id: "radio",
298
+ initial: "idle",
299
+ context: {
300
+ value: null,
301
+ activeValue: null,
302
+ focusedValue: null,
303
+ hoveredValue: null,
304
+ disabled: false,
305
+ orientation: "vertical",
306
+ ...ctx,
307
+ indicatorRect: {},
308
+ canIndicatorTransition: false,
309
+ fieldsetDisabled: false
310
+ },
311
+ computed: {
312
+ isDisabled: (ctx2) => !!ctx2.disabled || ctx2.fieldsetDisabled
313
+ },
314
+ entry: ["syncIndicatorRect"],
315
+ exit: ["cleanupObserver"],
316
+ activities: ["trackFormControlState"],
317
+ watch: {
318
+ value: ["setIndicatorTransition", "syncIndicatorRect", "syncInputElements"]
319
+ },
320
+ on: {
321
+ SET_VALUE: [
322
+ {
323
+ guard: not("isTrusted"),
324
+ actions: ["setValue", "dispatchChangeEvent"]
325
+ },
326
+ {
327
+ actions: ["setValue"]
328
+ }
329
+ ],
330
+ SET_HOVERED: {
331
+ actions: "setHovered"
332
+ },
333
+ SET_ACTIVE: {
334
+ actions: "setActive"
335
+ },
336
+ SET_FOCUSED: {
337
+ actions: "setFocused"
338
+ }
339
+ },
340
+ states: {
341
+ idle: {}
342
+ }
343
+ },
344
+ {
345
+ guards: {
346
+ isTrusted: (_ctx, evt) => !!evt.isTrusted
347
+ },
348
+ activities: {
349
+ trackFormControlState(ctx2, _evt, { send, initialContext }) {
350
+ return (0, import_form_utils.trackFormControl)(dom.getRootEl(ctx2), {
351
+ onFieldsetDisabledChange(disabled) {
352
+ ctx2.fieldsetDisabled = disabled;
353
+ },
354
+ onFormReset() {
355
+ send({ type: "SET_VALUE", value: initialContext.value });
356
+ }
357
+ });
358
+ }
359
+ },
360
+ actions: {
361
+ setValue(ctx2, evt) {
362
+ set.value(ctx2, evt.value);
363
+ },
364
+ setHovered(ctx2, evt) {
365
+ ctx2.hoveredValue = evt.value;
366
+ },
367
+ setActive(ctx2, evt) {
368
+ ctx2.activeValue = evt.value;
369
+ },
370
+ setFocused(ctx2, evt) {
371
+ ctx2.focusedValue = evt.value;
372
+ },
373
+ syncInputElements(ctx2) {
374
+ const inputs = dom.getInputEls(ctx2);
375
+ inputs.forEach((input) => {
376
+ input.checked = input.value === ctx2.value;
377
+ });
378
+ },
379
+ setIndicatorTransition(ctx2) {
380
+ ctx2.canIndicatorTransition = (0, import_utils.isString)(ctx2.value);
381
+ },
382
+ cleanupObserver(ctx2) {
383
+ ctx2.indicatorCleanup?.();
384
+ },
385
+ syncIndicatorRect(ctx2) {
386
+ ctx2.indicatorCleanup?.();
387
+ if (!dom.getIndicatorEl(ctx2))
388
+ return;
389
+ const value = ctx2.value;
390
+ const radioEl = dom.getActiveRadioEl(ctx2);
391
+ if (value == null || !radioEl) {
392
+ ctx2.indicatorRect = {};
393
+ return;
394
+ }
395
+ ctx2.indicatorCleanup = (0, import_element_rect.trackElementRect)(radioEl, {
396
+ getRect(el) {
397
+ return dom.getOffsetRect(el);
398
+ },
399
+ onChange(rect) {
400
+ ctx2.indicatorRect = dom.resolveRect(rect);
401
+ (0, import_dom_query3.nextTick)(() => {
402
+ ctx2.canIndicatorTransition = false;
403
+ });
404
+ }
405
+ });
406
+ },
407
+ dispatchChangeEvent(ctx2) {
408
+ const inputEls = dom.getInputEls(ctx2);
409
+ inputEls.forEach((inputEl) => {
410
+ const checked = inputEl.value === ctx2.value;
411
+ if (checked === inputEl.checked)
412
+ return;
413
+ (0, import_form_utils.dispatchInputCheckedEvent)(inputEl, { checked });
414
+ });
415
+ }
416
+ }
417
+ }
418
+ );
419
+ }
420
+ var invoke = {
421
+ change: (ctx) => {
422
+ if (ctx.value == null)
423
+ return;
424
+ ctx.onValueChange?.({ value: ctx.value });
425
+ }
426
+ };
427
+ var set = {
428
+ value: (ctx, value) => {
429
+ if ((0, import_utils.isEqual)(ctx.value, value))
430
+ return;
431
+ ctx.value = value;
432
+ invoke.change(ctx);
433
+ }
434
+ };
435
+
436
+ // src/radio-group.props.ts
437
+ var import_types = require("@zag-js/types");
438
+ var import_utils2 = require("@zag-js/utils");
439
+ var props = (0, import_types.createProps)()([
440
+ "dir",
441
+ "disabled",
442
+ "form",
443
+ "getRootNode",
444
+ "id",
445
+ "ids",
446
+ "name",
447
+ "onValueChange",
448
+ "orientation",
449
+ "readOnly",
450
+ "value"
451
+ ]);
452
+ var splitProps = (0, import_utils2.createSplitProps)(props);
453
+ var itemProps = (0, import_types.createProps)()(["value", "disabled", "invalid"]);
454
+ var splitItemProps = (0, import_utils2.createSplitProps)(itemProps);
455
+ // Annotate the CommonJS export names for ESM import in node:
456
+ 0 && (module.exports = {
457
+ anatomy,
458
+ connect,
459
+ itemProps,
460
+ machine,
461
+ props,
462
+ splitItemProps,
463
+ splitProps
464
+ });
2
465
  //# sourceMappingURL=index.js.map