@tamagui/radio-headless 2.7.7 → 3.0.0-beta.643.1
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/cjs/BubbleInput.cjs +57 -71
- package/dist/cjs/BubbleInput.native.cjs +75 -0
- package/dist/cjs/BubbleInput.native.js +57 -70
- package/dist/cjs/BubbleInput.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +22 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useRadioGroup.cjs +143 -176
- package/dist/cjs/useRadioGroup.native.cjs +190 -0
- package/dist/cjs/useRadioGroup.native.js +162 -190
- package/dist/cjs/useRadioGroup.native.js.map +1 -1
- package/dist/cjs/utils.cjs +16 -19
- package/dist/cjs/utils.native.cjs +29 -0
- package/dist/cjs/utils.native.js +16 -18
- package/dist/cjs/utils.native.js.map +1 -1
- package/dist/esm/BubbleInput.mjs +41 -45
- package/dist/esm/BubbleInput.mjs.map +1 -1
- package/dist/esm/BubbleInput.native.js +42 -46
- package/dist/esm/BubbleInput.native.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.native.js +3 -3
- package/dist/esm/useRadioGroup.mjs +128 -158
- package/dist/esm/useRadioGroup.mjs.map +1 -1
- package/dist/esm/useRadioGroup.native.js +147 -173
- package/dist/esm/useRadioGroup.native.js.map +1 -1
- package/dist/esm/utils.mjs +2 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/utils.native.js +2 -1
- package/dist/esm/utils.native.js.map +1 -1
- package/dist/jsx/BubbleInput.mjs +41 -45
- package/dist/jsx/BubbleInput.mjs.map +1 -1
- package/dist/jsx/BubbleInput.native.cjs +75 -0
- package/dist/jsx/BubbleInput.native.js +57 -70
- package/dist/jsx/BubbleInput.native.js.map +1 -1
- package/dist/jsx/index.js +3 -3
- package/dist/jsx/index.mjs +3 -3
- package/dist/jsx/index.native.cjs +22 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/useRadioGroup.mjs +128 -158
- package/dist/jsx/useRadioGroup.mjs.map +1 -1
- package/dist/jsx/useRadioGroup.native.cjs +190 -0
- package/dist/jsx/useRadioGroup.native.js +162 -190
- package/dist/jsx/useRadioGroup.native.js.map +1 -1
- package/dist/jsx/utils.mjs +2 -1
- package/dist/jsx/utils.mjs.map +1 -1
- package/dist/jsx/utils.native.cjs +29 -0
- package/dist/jsx/utils.native.js +16 -18
- package/dist/jsx/utils.native.js.map +1 -1
- package/package.json +12 -12
- package/src/useRadioGroup.tsx +1 -1
- package/types/BubbleInput.d.ts +1 -1
- package/types/BubbleInput.d.ts.map +1 -1
- package/types/useRadioGroup.d.ts +10 -10
- package/types/useRadioGroup.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
|
@@ -1,30 +1,29 @@
|
|
|
1
|
+
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
6
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
10
11
|
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
19
20
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
22
|
var useRadioGroup_exports = {};
|
|
24
23
|
__export(useRadioGroup_exports, {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
useRadioGroup: () => useRadioGroup,
|
|
25
|
+
useRadioGroupItem: () => useRadioGroupItem,
|
|
26
|
+
useRadioGroupItemIndicator: () => useRadioGroupItemIndicator
|
|
28
27
|
});
|
|
29
28
|
module.exports = __toCommonJS(useRadioGroup_exports);
|
|
30
29
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
@@ -38,165 +37,133 @@ var import_BubbleInput = require("./BubbleInput.cjs");
|
|
|
38
37
|
var import_utils = require("./utils.cjs");
|
|
39
38
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
39
|
function useRadioGroup(params) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
frameAttrs: {
|
|
69
|
-
role: "radiogroup",
|
|
70
|
-
"aria-orientation": orientation,
|
|
71
|
-
"data-disabled": disabled ? "" : void 0
|
|
72
|
-
},
|
|
73
|
-
rovingFocusGroupAttrs: {
|
|
74
|
-
orientation,
|
|
75
|
-
loop: true
|
|
76
|
-
}
|
|
77
|
-
};
|
|
40
|
+
const { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;
|
|
41
|
+
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
42
|
+
prop: valueProp,
|
|
43
|
+
defaultProp: defaultValue,
|
|
44
|
+
onChange: onValueChange
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
providerValue: {
|
|
48
|
+
value,
|
|
49
|
+
onChange: setValue,
|
|
50
|
+
required,
|
|
51
|
+
disabled,
|
|
52
|
+
name,
|
|
53
|
+
native,
|
|
54
|
+
accentColor
|
|
55
|
+
},
|
|
56
|
+
frameAttrs: {
|
|
57
|
+
role: "radiogroup",
|
|
58
|
+
"aria-orientation": orientation,
|
|
59
|
+
"data-disabled": disabled ? "" : void 0
|
|
60
|
+
},
|
|
61
|
+
rovingFocusGroupAttrs: {
|
|
62
|
+
orientation,
|
|
63
|
+
loop: true
|
|
64
|
+
}
|
|
65
|
+
};
|
|
78
66
|
}
|
|
79
|
-
const ARROW_KEYS = [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
172
|
-
if (!checked) onChange?.(value);
|
|
173
|
-
}
|
|
174
|
-
}),
|
|
175
|
-
onFocus: (0, import_helpers.composeEventHandlers)(onFocus, () => {
|
|
176
|
-
if (isArrowKeyPressedRef.current) ref.current?.click();
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
},
|
|
180
|
-
rovingFocusGroupAttrs: {
|
|
181
|
-
asChild: "except-style",
|
|
182
|
-
focusable: !isDisabled,
|
|
183
|
-
active: checked
|
|
184
|
-
}
|
|
185
|
-
};
|
|
67
|
+
const ARROW_KEYS = [
|
|
68
|
+
"ArrowUp",
|
|
69
|
+
"ArrowDown",
|
|
70
|
+
"ArrowLeft",
|
|
71
|
+
"ArrowRight"
|
|
72
|
+
];
|
|
73
|
+
const useRadioGroupItem = (params) => {
|
|
74
|
+
const { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;
|
|
75
|
+
const { value: groupValue, disabled, required, onChange, name, native, accentColor } = (0, import_react.useContext)(radioGroupContext);
|
|
76
|
+
const [button, setButton] = (0, import_react.useState)(null);
|
|
77
|
+
const hasConsumerStoppedPropagationRef = (0, import_react.useRef)(false);
|
|
78
|
+
const ref = (0, import_react.useRef)(null);
|
|
79
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(refProp, (node) => setButton(node), ref);
|
|
80
|
+
const isArrowKeyPressedRef = (0, import_react.useRef)(false);
|
|
81
|
+
const isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
82
|
+
const checked = groupValue === value;
|
|
83
|
+
const labelId = (0, import_label.useLabelContext)(button);
|
|
84
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
85
|
+
(0, import_react.useEffect)(() => {
|
|
86
|
+
if (import_constants.isWeb) {
|
|
87
|
+
const handleKeyDown = (event) => {
|
|
88
|
+
if (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;
|
|
89
|
+
};
|
|
90
|
+
const handleKeyUp = () => {
|
|
91
|
+
isArrowKeyPressedRef.current = false;
|
|
92
|
+
};
|
|
93
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
94
|
+
document.addEventListener("keyup", handleKeyUp);
|
|
95
|
+
return () => {
|
|
96
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
97
|
+
document.removeEventListener("keyup", handleKeyUp);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}, []);
|
|
101
|
+
const isDisabled = disabled || itemDisabled;
|
|
102
|
+
return {
|
|
103
|
+
providerValue: { checked },
|
|
104
|
+
checked,
|
|
105
|
+
isFormControl,
|
|
106
|
+
bubbleInput: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {
|
|
107
|
+
isHidden: !native,
|
|
108
|
+
control: button,
|
|
109
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
110
|
+
name,
|
|
111
|
+
value,
|
|
112
|
+
checked,
|
|
113
|
+
required,
|
|
114
|
+
disabled: isDisabled,
|
|
115
|
+
...import_constants.isWeb && native && {
|
|
116
|
+
accentColor,
|
|
117
|
+
id
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
native,
|
|
121
|
+
frameAttrs: {
|
|
122
|
+
"data-state": (0, import_utils.getState)(checked),
|
|
123
|
+
"data-disabled": isDisabled ? "" : void 0,
|
|
124
|
+
role: "radio",
|
|
125
|
+
"aria-labelledby": labelledBy,
|
|
126
|
+
"aria-checked": checked,
|
|
127
|
+
"aria-required": required,
|
|
128
|
+
disabled: isDisabled,
|
|
129
|
+
ref: composedRefs,
|
|
130
|
+
...import_constants.isWeb && {
|
|
131
|
+
type: "button",
|
|
132
|
+
value
|
|
133
|
+
},
|
|
134
|
+
id,
|
|
135
|
+
onPress: (0, import_helpers.composeEventHandlers)(onPress, (event) => {
|
|
136
|
+
if (!checked) onChange?.(value);
|
|
137
|
+
if (isFormControl) {
|
|
138
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
139
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
140
|
+
}
|
|
141
|
+
}),
|
|
142
|
+
...import_constants.isWeb && {
|
|
143
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(onKeyDown, (event) => {
|
|
144
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
145
|
+
if (!checked) onChange?.(value);
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
onFocus: (0, import_helpers.composeEventHandlers)(onFocus, () => {
|
|
149
|
+
if (isArrowKeyPressedRef.current) ref.current?.click();
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
rovingFocusGroupAttrs: {
|
|
154
|
+
asChild: "except-style",
|
|
155
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
156
|
+
active: checked
|
|
157
|
+
}
|
|
158
|
+
};
|
|
186
159
|
};
|
|
187
160
|
function useRadioGroupItemIndicator(params) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
checked,
|
|
198
|
-
"data-state": (0, import_utils.getState)(checked),
|
|
199
|
-
"data-disabled": disabled ? "" : void 0,
|
|
200
|
-
...rest
|
|
201
|
-
};
|
|
202
|
-
}
|
|
161
|
+
const { radioGroupItemContext, disabled, ...rest } = params;
|
|
162
|
+
const { checked } = (0, import_react.useContext)(radioGroupItemContext);
|
|
163
|
+
return {
|
|
164
|
+
checked,
|
|
165
|
+
"data-state": (0, import_utils.getState)(checked),
|
|
166
|
+
"data-disabled": disabled ? "" : void 0,
|
|
167
|
+
...rest
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var useRadioGroup_exports = {};
|
|
25
|
+
__export(useRadioGroup_exports, {
|
|
26
|
+
useRadioGroup: () => useRadioGroup,
|
|
27
|
+
useRadioGroupItem: () => useRadioGroupItem,
|
|
28
|
+
useRadioGroupItemIndicator: () => useRadioGroupItemIndicator
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(useRadioGroup_exports);
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
33
|
+
var import_constants = require("@tamagui/constants");
|
|
34
|
+
var import_focusable = require("@tamagui/focusable");
|
|
35
|
+
var import_helpers = require("@tamagui/helpers");
|
|
36
|
+
var import_label = require("@tamagui/label");
|
|
37
|
+
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_BubbleInput = require("./BubbleInput.native.js");
|
|
40
|
+
var import_utils = require("./utils.native.js");
|
|
41
|
+
function useRadioGroup(params) {
|
|
42
|
+
var { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;
|
|
43
|
+
var [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
44
|
+
prop: valueProp,
|
|
45
|
+
defaultProp: defaultValue,
|
|
46
|
+
onChange: onValueChange
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
providerValue: {
|
|
50
|
+
value,
|
|
51
|
+
onChange: setValue,
|
|
52
|
+
required,
|
|
53
|
+
disabled,
|
|
54
|
+
name,
|
|
55
|
+
native,
|
|
56
|
+
accentColor
|
|
57
|
+
},
|
|
58
|
+
frameAttrs: {
|
|
59
|
+
role: "radiogroup",
|
|
60
|
+
"aria-orientation": orientation,
|
|
61
|
+
"data-disabled": disabled ? "" : void 0
|
|
62
|
+
},
|
|
63
|
+
rovingFocusGroupAttrs: {
|
|
64
|
+
orientation,
|
|
65
|
+
loop: true
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var ARROW_KEYS = [
|
|
70
|
+
"ArrowUp",
|
|
71
|
+
"ArrowDown",
|
|
72
|
+
"ArrowLeft",
|
|
73
|
+
"ArrowRight"
|
|
74
|
+
];
|
|
75
|
+
var useRadioGroupItem = function(params) {
|
|
76
|
+
var { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;
|
|
77
|
+
var { value: groupValue, disabled, required, onChange, name, native, accentColor } = (0, import_react.useContext)(radioGroupContext);
|
|
78
|
+
var [button, setButton] = (0, import_react.useState)(null);
|
|
79
|
+
var hasConsumerStoppedPropagationRef = (0, import_react.useRef)(false);
|
|
80
|
+
var ref = (0, import_react.useRef)(null);
|
|
81
|
+
var composedRefs = (0, import_compose_refs.useComposedRefs)(refProp, function(node) {
|
|
82
|
+
return setButton(node);
|
|
83
|
+
}, ref);
|
|
84
|
+
var isArrowKeyPressedRef = (0, import_react.useRef)(false);
|
|
85
|
+
var isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
86
|
+
var checked = groupValue === value;
|
|
87
|
+
var labelId = (0, import_label.useLabelContext)(button);
|
|
88
|
+
var labelledBy = ariaLabelledby || labelId;
|
|
89
|
+
(0, import_react.useEffect)(function() {
|
|
90
|
+
if (import_constants.isWeb) {
|
|
91
|
+
var handleKeyDown = function(event) {
|
|
92
|
+
if (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;
|
|
93
|
+
};
|
|
94
|
+
var handleKeyUp = function() {
|
|
95
|
+
isArrowKeyPressedRef.current = false;
|
|
96
|
+
};
|
|
97
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
98
|
+
document.addEventListener("keyup", handleKeyUp);
|
|
99
|
+
return function() {
|
|
100
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
101
|
+
document.removeEventListener("keyup", handleKeyUp);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}, []);
|
|
105
|
+
(0, import_react.useEffect)(function() {
|
|
106
|
+
if (!id) return;
|
|
107
|
+
if (disabled) return;
|
|
108
|
+
return (0, import_focusable.registerFocusable)(id, {
|
|
109
|
+
focusAndSelect: function() {
|
|
110
|
+
onChange === null || onChange === void 0 || onChange(value);
|
|
111
|
+
},
|
|
112
|
+
focus: function() {}
|
|
113
|
+
});
|
|
114
|
+
}, [
|
|
115
|
+
id,
|
|
116
|
+
value,
|
|
117
|
+
disabled
|
|
118
|
+
]);
|
|
119
|
+
var isDisabled = disabled || itemDisabled;
|
|
120
|
+
return {
|
|
121
|
+
providerValue: { checked },
|
|
122
|
+
checked,
|
|
123
|
+
isFormControl,
|
|
124
|
+
bubbleInput: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {
|
|
125
|
+
isHidden: !native,
|
|
126
|
+
control: button,
|
|
127
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
128
|
+
name,
|
|
129
|
+
value,
|
|
130
|
+
checked,
|
|
131
|
+
required,
|
|
132
|
+
disabled: isDisabled,
|
|
133
|
+
...import_constants.isWeb && native && {
|
|
134
|
+
accentColor,
|
|
135
|
+
id
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
138
|
+
native,
|
|
139
|
+
frameAttrs: {
|
|
140
|
+
"data-state": (0, import_utils.getState)(checked),
|
|
141
|
+
"data-disabled": isDisabled ? "" : void 0,
|
|
142
|
+
role: "radio",
|
|
143
|
+
"aria-labelledby": labelledBy,
|
|
144
|
+
"aria-checked": checked,
|
|
145
|
+
"aria-required": required,
|
|
146
|
+
disabled: isDisabled,
|
|
147
|
+
ref: composedRefs,
|
|
148
|
+
...import_constants.isWeb && {
|
|
149
|
+
type: "button",
|
|
150
|
+
value
|
|
151
|
+
},
|
|
152
|
+
id,
|
|
153
|
+
onPress: (0, import_helpers.composeEventHandlers)(onPress, function(event) {
|
|
154
|
+
if (!checked) onChange === null || onChange === void 0 || onChange(value);
|
|
155
|
+
if (isFormControl) {
|
|
156
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
157
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
158
|
+
}
|
|
159
|
+
}),
|
|
160
|
+
...import_constants.isWeb && {
|
|
161
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(onKeyDown, function(event) {
|
|
162
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
163
|
+
if (!checked) onChange === null || onChange === void 0 || onChange(value);
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
onFocus: (0, import_helpers.composeEventHandlers)(onFocus, function() {
|
|
167
|
+
if (isArrowKeyPressedRef.current) {
|
|
168
|
+
var _ref_current;
|
|
169
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
rovingFocusGroupAttrs: {
|
|
175
|
+
asChild: "except-style",
|
|
176
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
177
|
+
active: checked
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
function useRadioGroupItemIndicator(params) {
|
|
182
|
+
var { radioGroupItemContext, disabled, ...rest } = params;
|
|
183
|
+
var { checked } = (0, import_react.useContext)(radioGroupItemContext);
|
|
184
|
+
return {
|
|
185
|
+
checked,
|
|
186
|
+
"data-state": (0, import_utils.getState)(checked),
|
|
187
|
+
"data-disabled": disabled ? "" : void 0,
|
|
188
|
+
...rest
|
|
189
|
+
};
|
|
190
|
+
}
|