@zag-js/radio-group 2.0.0-next.2 → 2.0.0-next.4

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,184 +1,157 @@
1
- // src/radio-group.machine.ts
2
- import { createGuards, createMachine } from "@zag-js/core";
3
- import { dispatchInputCheckedEvent, resizeObserverBorderBox, trackFormControl } from "@zag-js/dom-query";
1
+ import { getIndicatorEl, getInputEls, getOffsetRect, getRadioEl, getRootEl } from "./radio-group.dom.mjs";
2
+ import { AnimationFrame, dispatchInputCheckedEvent, resizeObserverBorderBox, trackFormControl } from "@zag-js/dom-query";
4
3
  import { trackFocusVisible } from "@zag-js/focus-visible";
5
- import * as dom from "./radio-group.dom.mjs";
6
- var { not } = createGuards();
7
- var machine = createMachine({
8
- props({ props }) {
9
- return {
10
- orientation: "vertical",
11
- ...props
12
- };
13
- },
14
- initialState() {
15
- return "idle";
16
- },
17
- context({ prop, bindable }) {
18
- return {
19
- value: bindable(() => ({
20
- defaultValue: prop("defaultValue"),
21
- value: prop("value"),
22
- onChange(value) {
23
- prop("onValueChange")?.({ value });
24
- }
25
- })),
26
- activeValue: bindable(() => ({
27
- defaultValue: null
28
- })),
29
- focusedValue: bindable(() => ({
30
- defaultValue: null
31
- })),
32
- focusVisibleValue: bindable(() => ({
33
- defaultValue: null
34
- })),
35
- hoveredValue: bindable(() => ({
36
- defaultValue: null
37
- })),
38
- indicatorRect: bindable(() => ({
39
- defaultValue: null
40
- })),
41
- animateIndicator: bindable(() => ({
42
- defaultValue: false
43
- })),
44
- fieldsetDisabled: bindable(() => ({
45
- defaultValue: false
46
- })),
47
- ssr: bindable(() => ({
48
- defaultValue: true
49
- }))
50
- };
51
- },
52
- refs() {
53
- return {
54
- indicatorCleanup: null,
55
- focusVisibleValue: null,
56
- prevValue: null
57
- };
58
- },
59
- computed: {
60
- isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled")
61
- },
62
- entry: ["syncPrevValue", "syncIndicatorRect", "syncSsr"],
63
- exit: ["cleanupObserver"],
64
- effects: ["trackFormControlState", "trackFocusVisible"],
65
- watch({ track, action, context }) {
66
- track([() => context.get("value")], () => {
67
- action(["syncIndicatorAnimation", "syncIndicatorRect", "syncInputElements"]);
68
- });
69
- },
70
- on: {
71
- SET_VALUE: [
72
- {
73
- guard: not("isTrusted"),
74
- actions: ["setValue", "dispatchChangeEvent"]
75
- },
76
- {
77
- actions: ["setValue"]
78
- }
79
- ],
80
- SET_HOVERED: {
81
- actions: ["setHovered"]
82
- },
83
- SET_ACTIVE: {
84
- actions: ["setActive"]
85
- },
86
- SET_FOCUSED: {
87
- actions: ["setFocused"]
88
- },
89
- INDICATOR_TRANSITION_END: {
90
- actions: ["clearIndicatorAnimation"]
91
- }
92
- },
93
- states: {
94
- idle: {}
95
- },
96
- implementations: {
97
- guards: {
98
- isTrusted: ({ event }) => !!event.isTrusted
99
- },
100
- effects: {
101
- trackFormControlState({ context, scope }) {
102
- return trackFormControl(dom.getRootEl(scope), {
103
- onFieldsetDisabledChange(disabled) {
104
- context.set("fieldsetDisabled", disabled);
105
- },
106
- onFormReset() {
107
- context.set("value", context.initial("value"));
108
- }
109
- });
110
- },
111
- trackFocusVisible({ scope }) {
112
- return trackFocusVisible({ root: scope.getRootNode?.() });
113
- }
114
- },
115
- actions: {
116
- setValue({ context, event }) {
117
- context.set("value", event.value);
118
- },
119
- setHovered({ context, event }) {
120
- context.set("hoveredValue", event.value);
121
- },
122
- setActive({ context, event }) {
123
- context.set("activeValue", event.value);
124
- },
125
- setFocused({ context, event }) {
126
- context.set("focusedValue", event.value);
127
- const focusVisibleValue = event.value != null && event.focusVisible ? event.value : null;
128
- context.set("focusVisibleValue", focusVisibleValue);
129
- },
130
- syncPrevValue({ context, refs }) {
131
- refs.set("prevValue", context.get("value"));
132
- },
133
- syncIndicatorAnimation({ context, refs }) {
134
- const prevValue = refs.get("prevValue");
135
- const nextValue = context.get("value");
136
- const animate = prevValue != null && nextValue != null && prevValue !== nextValue;
137
- context.set("animateIndicator", animate);
138
- refs.set("prevValue", nextValue);
139
- },
140
- clearIndicatorAnimation({ context }) {
141
- context.set("animateIndicator", false);
142
- },
143
- syncInputElements({ context, scope }) {
144
- const inputs = dom.getInputEls(scope);
145
- inputs.forEach((input) => {
146
- input.checked = input.value === context.get("value");
147
- });
148
- },
149
- cleanupObserver({ refs }) {
150
- refs.get("indicatorCleanup")?.();
151
- },
152
- syncSsr({ context }) {
153
- context.set("ssr", false);
154
- },
155
- syncIndicatorRect({ context, scope, refs }) {
156
- refs.get("indicatorCleanup")?.();
157
- if (!dom.getIndicatorEl(scope)) return;
158
- const value = context.get("value");
159
- const radioEl = dom.getRadioEl(scope, value);
160
- if (value == null || !radioEl) {
161
- context.set("indicatorRect", null);
162
- return;
163
- }
164
- const exec = () => {
165
- context.set("indicatorRect", dom.getOffsetRect(radioEl));
166
- };
167
- exec();
168
- const indicatorCleanup = resizeObserverBorderBox.observe(radioEl, exec);
169
- refs.set("indicatorCleanup", indicatorCleanup);
170
- },
171
- dispatchChangeEvent({ context, scope }) {
172
- const inputEls = dom.getInputEls(scope);
173
- inputEls.forEach((inputEl) => {
174
- const checked = inputEl.value === context.get("value");
175
- if (checked === inputEl.checked) return;
176
- dispatchInputCheckedEvent(inputEl, { checked });
177
- });
178
- }
179
- }
180
- }
4
+ import { isEqual } from "@zag-js/utils";
5
+ import { createGuards, createMachine } from "@zag-js/core";
6
+ // src/radio-group.machine.ts
7
+ const { not } = createGuards();
8
+ const machine = createMachine({
9
+ props({ props }) {
10
+ return {
11
+ orientation: "vertical",
12
+ ...props
13
+ };
14
+ },
15
+ initialState() {
16
+ return "idle";
17
+ },
18
+ context({ prop, bindable }) {
19
+ return {
20
+ value: bindable(() => ({
21
+ defaultValue: prop("defaultValue"),
22
+ value: prop("value"),
23
+ onChange(value) {
24
+ prop("onValueChange")?.({ value });
25
+ }
26
+ })),
27
+ activeValue: bindable(() => ({ defaultValue: null })),
28
+ focusedValue: bindable(() => ({ defaultValue: null })),
29
+ focusVisibleValue: bindable(() => ({ defaultValue: null })),
30
+ hoveredValue: bindable(() => ({ defaultValue: null })),
31
+ indicatorRect: bindable(() => ({ defaultValue: null })),
32
+ indicatorInstant: bindable(() => ({ defaultValue: false })),
33
+ fieldsetDisabled: bindable(() => ({ defaultValue: false })),
34
+ ssr: bindable(() => ({ defaultValue: true }))
35
+ };
36
+ },
37
+ refs() {
38
+ return {
39
+ indicatorCleanup: null,
40
+ indicatorFrame: AnimationFrame.create(),
41
+ focusVisibleValue: null
42
+ };
43
+ },
44
+ computed: { isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled") },
45
+ entry: ["syncIndicatorRect", "syncSsr"],
46
+ exit: ["cleanupObserver", "cancelIndicatorFrame"],
47
+ effects: ["trackFormControlState", "trackFocusVisible"],
48
+ watch({ track, action, context }) {
49
+ track([() => context.get("value")], () => {
50
+ action(["syncIndicatorRect", "syncInputElements"]);
51
+ });
52
+ },
53
+ on: {
54
+ SET_VALUE: [{
55
+ guard: not("isTrusted"),
56
+ actions: ["setValue", "dispatchChangeEvent"]
57
+ }, { actions: ["setValue"] }],
58
+ SET_HOVERED: { actions: ["setHovered"] },
59
+ SET_ACTIVE: { actions: ["setActive"] },
60
+ SET_FOCUSED: { actions: ["setFocused"] },
61
+ INDICATOR_RESIZE: [{
62
+ guard: "isIndicatorTransitioning",
63
+ actions: ["setResizedIndicatorRect"]
64
+ }, { actions: ["snapIndicator", "setResizedIndicatorRect"] }]
65
+ },
66
+ states: { idle: {} },
67
+ implementations: {
68
+ guards: {
69
+ isTrusted: ({ event }) => !!event.isTrusted,
70
+ isIndicatorTransitioning: ({ event }) => !!event.transitioning
71
+ },
72
+ effects: {
73
+ trackFormControlState({ context, scope }) {
74
+ return trackFormControl(getRootEl(scope), {
75
+ onFieldsetDisabledChange(disabled) {
76
+ context.set("fieldsetDisabled", disabled);
77
+ },
78
+ onFormReset() {
79
+ context.set("value", context.initial("value"));
80
+ }
81
+ });
82
+ },
83
+ trackFocusVisible({ scope }) {
84
+ return trackFocusVisible({ root: scope.getRootNode?.() });
85
+ }
86
+ },
87
+ actions: {
88
+ setValue({ context, event }) {
89
+ context.set("value", event.value);
90
+ },
91
+ setHovered({ context, event }) {
92
+ context.set("hoveredValue", event.value);
93
+ },
94
+ setActive({ context, event }) {
95
+ context.set("activeValue", event.value);
96
+ },
97
+ setFocused({ context, event }) {
98
+ context.set("focusedValue", event.value);
99
+ const focusVisibleValue = event.value != null && event.focusVisible ? event.value : null;
100
+ context.set("focusVisibleValue", focusVisibleValue);
101
+ },
102
+ snapIndicator({ context, refs }) {
103
+ const frame = refs.get("indicatorFrame");
104
+ context.set("indicatorInstant", true);
105
+ frame.request(() => frame.request(() => context.set("indicatorInstant", false)));
106
+ },
107
+ cancelIndicatorFrame({ refs }) {
108
+ refs.get("indicatorFrame").cancel();
109
+ },
110
+ syncInputElements({ context, scope }) {
111
+ getInputEls(scope).forEach((input) => {
112
+ input.checked = input.value === context.get("value");
113
+ });
114
+ },
115
+ cleanupObserver({ refs }) {
116
+ refs.get("indicatorCleanup")?.();
117
+ },
118
+ syncSsr({ context }) {
119
+ context.set("ssr", false);
120
+ },
121
+ setResizedIndicatorRect({ context, event }) {
122
+ context.set("indicatorRect", event.rect);
123
+ },
124
+ syncIndicatorRect({ context, scope, refs, send }) {
125
+ refs.get("indicatorCleanup")?.();
126
+ const indicatorEl = getIndicatorEl(scope);
127
+ if (!indicatorEl) return;
128
+ const value = context.get("value");
129
+ const radioEl = getRadioEl(scope, value);
130
+ if (value == null || !radioEl) {
131
+ context.set("indicatorRect", null);
132
+ return;
133
+ }
134
+ context.set("indicatorRect", getOffsetRect(radioEl));
135
+ const onResize = () => {
136
+ const rect = getOffsetRect(radioEl);
137
+ if (isEqual(context.get("indicatorRect"), rect)) return;
138
+ send({
139
+ type: "INDICATOR_RESIZE",
140
+ rect,
141
+ transitioning: indicatorEl.getAnimations?.().length > 0
142
+ });
143
+ };
144
+ const indicatorCleanup = resizeObserverBorderBox.observe(radioEl, onResize);
145
+ refs.set("indicatorCleanup", indicatorCleanup);
146
+ },
147
+ dispatchChangeEvent({ context, scope }) {
148
+ getInputEls(scope).forEach((inputEl) => {
149
+ const checked = inputEl.value === context.get("value");
150
+ if (checked === inputEl.checked) return;
151
+ dispatchInputCheckedEvent(inputEl, { checked });
152
+ });
153
+ }
154
+ }
155
+ }
181
156
  });
182
- export {
183
- machine
184
- };
157
+ export { machine };
@@ -1,10 +1,5 @@
1
- import { ItemProps, RadioGroupProps } from './radio-group.types.mjs';
2
- import '@zag-js/core';
3
- import '@zag-js/types';
4
-
5
- declare const props: (keyof RadioGroupProps)[];
6
- declare const splitProps: <Props extends Partial<RadioGroupProps>>(props: Props) => [Partial<RadioGroupProps>, Omit<Props, keyof RadioGroupProps>];
7
- declare const itemProps: (keyof ItemProps)[];
8
- declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
9
-
10
- export { itemProps, props, splitItemProps, splitProps };
1
+ import { ItemProps, RadioGroupProps } from "./radio-group.types.mjs";
2
+ export declare const props: (keyof RadioGroupProps)[];
3
+ export declare const splitProps: <Props extends Partial<RadioGroupProps>>(props: Props) => [Partial<RadioGroupProps>, Omit<Props, keyof RadioGroupProps>];
4
+ export declare const itemProps: (keyof ItemProps)[];
5
+ export declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
@@ -1,10 +1,5 @@
1
- import { ItemProps, RadioGroupProps } from './radio-group.types.js';
2
- import '@zag-js/core';
3
- import '@zag-js/types';
4
-
5
- declare const props: (keyof RadioGroupProps)[];
6
- declare const splitProps: <Props extends Partial<RadioGroupProps>>(props: Props) => [Partial<RadioGroupProps>, Omit<Props, keyof RadioGroupProps>];
7
- declare const itemProps: (keyof ItemProps)[];
8
- declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
9
-
10
- export { itemProps, props, splitItemProps, splitProps };
1
+ import { ItemProps, RadioGroupProps } from "./radio-group.types.js";
2
+ export declare const props: (keyof RadioGroupProps)[];
3
+ export declare const splitProps: <Props extends Partial<RadioGroupProps>>(props: Props) => [Partial<RadioGroupProps>, Omit<Props, keyof RadioGroupProps>];
4
+ export declare const itemProps: (keyof ItemProps)[];
5
+ export declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
@@ -1,56 +1,34 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/radio-group.props.ts
21
- var radio_group_props_exports = {};
22
- __export(radio_group_props_exports, {
23
- itemProps: () => itemProps,
24
- props: () => props,
25
- splitItemProps: () => splitItemProps,
26
- splitProps: () => splitProps
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
27
4
  });
28
- module.exports = __toCommonJS(radio_group_props_exports);
29
- var import_types = require("@zag-js/types");
30
- var import_utils = require("@zag-js/utils");
31
- var props = (0, import_types.createProps)()([
32
- "dir",
33
- "disabled",
34
- "form",
35
- "getRootNode",
36
- "id",
37
- "ids",
38
- "invalid",
39
- "name",
40
- "onValueChange",
41
- "orientation",
42
- "readOnly",
43
- "required",
44
- "value",
45
- "defaultValue"
5
+ let _zag_js_utils = require("@zag-js/utils");
6
+ let _zag_js_types = require("@zag-js/types");
7
+ // src/radio-group.props.ts
8
+ const props = (0, _zag_js_types.createProps)()([
9
+ "dir",
10
+ "disabled",
11
+ "form",
12
+ "getRootNode",
13
+ "id",
14
+ "ids",
15
+ "invalid",
16
+ "name",
17
+ "onValueChange",
18
+ "orientation",
19
+ "readOnly",
20
+ "required",
21
+ "value",
22
+ "defaultValue"
46
23
  ]);
47
- var splitProps = (0, import_utils.createSplitProps)(props);
48
- var itemProps = (0, import_types.createProps)()(["value", "disabled", "invalid"]);
49
- var splitItemProps = (0, import_utils.createSplitProps)(itemProps);
50
- // Annotate the CommonJS export names for ESM import in node:
51
- 0 && (module.exports = {
52
- itemProps,
53
- props,
54
- splitItemProps,
55
- splitProps
56
- });
24
+ const splitProps = (0, _zag_js_utils.createSplitProps)(props);
25
+ const itemProps = (0, _zag_js_types.createProps)()([
26
+ "value",
27
+ "disabled",
28
+ "invalid"
29
+ ]);
30
+ const splitItemProps = (0, _zag_js_utils.createSplitProps)(itemProps);
31
+ exports.itemProps = itemProps;
32
+ exports.props = props;
33
+ exports.splitItemProps = splitItemProps;
34
+ exports.splitProps = splitProps;
@@ -1,28 +1,27 @@
1
- // src/radio-group.props.ts
2
- import { createProps } from "@zag-js/types";
3
1
  import { createSplitProps } from "@zag-js/utils";
4
- var props = createProps()([
5
- "dir",
6
- "disabled",
7
- "form",
8
- "getRootNode",
9
- "id",
10
- "ids",
11
- "invalid",
12
- "name",
13
- "onValueChange",
14
- "orientation",
15
- "readOnly",
16
- "required",
17
- "value",
18
- "defaultValue"
2
+ import { createProps } from "@zag-js/types";
3
+ // src/radio-group.props.ts
4
+ const props = createProps()([
5
+ "dir",
6
+ "disabled",
7
+ "form",
8
+ "getRootNode",
9
+ "id",
10
+ "ids",
11
+ "invalid",
12
+ "name",
13
+ "onValueChange",
14
+ "orientation",
15
+ "readOnly",
16
+ "required",
17
+ "value",
18
+ "defaultValue"
19
+ ]);
20
+ const splitProps = createSplitProps(props);
21
+ const itemProps = createProps()([
22
+ "value",
23
+ "disabled",
24
+ "invalid"
19
25
  ]);
20
- var splitProps = createSplitProps(props);
21
- var itemProps = createProps()(["value", "disabled", "invalid"]);
22
- var splitItemProps = createSplitProps(itemProps);
23
- export {
24
- itemProps,
25
- props,
26
- splitItemProps,
27
- splitProps
28
- };
26
+ const splitItemProps = createSplitProps(itemProps);
27
+ export { itemProps, props, splitItemProps, splitProps };