@tamagui/radio-group 1.96.0 → 1.97.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.
Files changed (69) hide show
  1. package/dist/cjs/RadioGroup.js +23 -248
  2. package/dist/cjs/RadioGroup.js.map +1 -1
  3. package/dist/cjs/RadioGroup.native.js +25 -336
  4. package/dist/cjs/RadioGroup.native.js.map +2 -2
  5. package/dist/cjs/RadioGroupStyledContext.js +25 -0
  6. package/dist/cjs/RadioGroupStyledContext.js.map +6 -0
  7. package/dist/cjs/RadioGroupStyledContext.native.js +29 -0
  8. package/dist/cjs/RadioGroupStyledContext.native.js.map +6 -0
  9. package/dist/cjs/createRadioGroup.js +107 -0
  10. package/dist/cjs/createRadioGroup.js.map +6 -0
  11. package/dist/cjs/createRadioGroup.native.js +171 -0
  12. package/dist/cjs/createRadioGroup.native.js.map +6 -0
  13. package/dist/cjs/index.js +15 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/index.native.js +19 -2
  16. package/dist/cjs/index.native.js.map +2 -2
  17. package/dist/esm/RadioGroup.js +20 -248
  18. package/dist/esm/RadioGroup.js.map +1 -1
  19. package/dist/esm/RadioGroup.mjs +19 -240
  20. package/dist/esm/RadioGroup.native.js +20 -334
  21. package/dist/esm/RadioGroup.native.js.map +2 -2
  22. package/dist/esm/RadioGroupStyledContext.js +9 -0
  23. package/dist/esm/RadioGroupStyledContext.js.map +6 -0
  24. package/dist/esm/RadioGroupStyledContext.mjs +6 -0
  25. package/dist/esm/RadioGroupStyledContext.native.js +9 -0
  26. package/dist/esm/RadioGroupStyledContext.native.js.map +6 -0
  27. package/dist/esm/createRadioGroup.js +104 -0
  28. package/dist/esm/createRadioGroup.js.map +6 -0
  29. package/dist/esm/createRadioGroup.mjs +131 -0
  30. package/dist/esm/createRadioGroup.native.js +155 -0
  31. package/dist/esm/createRadioGroup.native.js.map +6 -0
  32. package/dist/esm/index.js +16 -0
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/index.mjs +11 -1
  35. package/dist/esm/index.native.js +12 -0
  36. package/dist/esm/index.native.js.map +2 -2
  37. package/dist/jsx/RadioGroup.js +20 -248
  38. package/dist/jsx/RadioGroup.js.map +1 -1
  39. package/dist/jsx/RadioGroup.mjs +19 -240
  40. package/dist/jsx/RadioGroup.native.js +20 -334
  41. package/dist/jsx/RadioGroup.native.js.map +2 -2
  42. package/dist/jsx/RadioGroupStyledContext.js +9 -0
  43. package/dist/jsx/RadioGroupStyledContext.js.map +6 -0
  44. package/dist/jsx/RadioGroupStyledContext.mjs +6 -0
  45. package/dist/jsx/RadioGroupStyledContext.native.js +9 -0
  46. package/dist/jsx/RadioGroupStyledContext.native.js.map +6 -0
  47. package/dist/jsx/createRadioGroup.js +104 -0
  48. package/dist/jsx/createRadioGroup.js.map +6 -0
  49. package/dist/jsx/createRadioGroup.mjs +131 -0
  50. package/dist/jsx/createRadioGroup.native.js +155 -0
  51. package/dist/jsx/createRadioGroup.native.js.map +6 -0
  52. package/dist/jsx/index.js +16 -0
  53. package/dist/jsx/index.js.map +1 -1
  54. package/dist/jsx/index.mjs +11 -1
  55. package/dist/jsx/index.native.js +12 -0
  56. package/dist/jsx/index.native.js.map +2 -2
  57. package/package.json +14 -14
  58. package/src/RadioGroup.tsx +22 -432
  59. package/src/RadioGroupStyledContext.tsx +7 -0
  60. package/src/createRadioGroup.tsx +201 -0
  61. package/src/index.ts +15 -0
  62. package/types/RadioGroup.d.ts +7 -224
  63. package/types/RadioGroup.d.ts.map +1 -1
  64. package/types/RadioGroupStyledContext.d.ts +6 -0
  65. package/types/RadioGroupStyledContext.d.ts.map +1 -0
  66. package/types/createRadioGroup.d.ts +979 -0
  67. package/types/createRadioGroup.d.ts.map +1 -0
  68. package/types/index.d.ts +949 -0
  69. package/types/index.d.ts.map +1 -1
@@ -1,59 +1,7 @@
1
- import { useComposedRefs } from "@tamagui/compose-refs";
2
- import { isWeb } from "@tamagui/constants";
3
1
  import { getVariableValue, styled } from "@tamagui/core";
4
- import { createContextScope } from "@tamagui/create-context";
5
2
  import { getSize } from "@tamagui/get-token";
6
- import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
7
- import { useLabelContext } from "@tamagui/label";
8
- import { RovingFocusGroup } from "@tamagui/roving-focus";
9
3
  import { ThemeableStack } from "@tamagui/stacks";
10
- import { useControllableState } from "@tamagui/use-controllable-state";
11
- import { usePrevious } from "@tamagui/use-previous";
12
- import * as React from "react";
13
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
- const RADIO_GROUP_NAME = "RadioGroup",
15
- ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"],
16
- [createRadioGroupContext, createRadioGroupScope] = createContextScope(RADIO_GROUP_NAME),
17
- [RadioGroupProvider, useRadioGroupContext] = createRadioGroupContext(RADIO_GROUP_NAME),
18
- getState = checked => checked ? "checked" : "unchecked",
19
- RADIO_GROUP_INDICATOR_NAME = "RadioGroupIndicator",
20
- RadioIndicatorFrame = styled(ThemeableStack, {
21
- name: RADIO_GROUP_INDICATOR_NAME,
22
- variants: {
23
- unstyled: {
24
- false: {
25
- width: "33%",
26
- height: "33%",
27
- borderRadius: 1e3,
28
- backgroundColor: "$color",
29
- pressTheme: !0
30
- }
31
- }
32
- },
33
- defaultVariants: {
34
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
35
- }
36
- }),
37
- RadioIndicator = RadioIndicatorFrame.extractable(React.forwardRef((props, forwardedRef) => {
38
- const {
39
- __scopeRadioGroupItem,
40
- forceMount,
41
- disabled,
42
- ...indicatorProps
43
- } = props,
44
- {
45
- checked
46
- } = useRadioGroupItemContext(RADIO_GROUP_INDICATOR_NAME, __scopeRadioGroupItem);
47
- return forceMount || checked ? /* @__PURE__ */jsx(RadioIndicatorFrame, {
48
- "data-state": getState(checked),
49
- "data-disabled": disabled ? "" : void 0,
50
- ...indicatorProps,
51
- ref: forwardedRef
52
- }) : null;
53
- }));
54
- RadioIndicator.displayName = RADIO_GROUP_INDICATOR_NAME;
55
4
  const RADIO_GROUP_ITEM_NAME = "RadioGroupItem",
56
- [RadioGroupItemProvider, useRadioGroupItemContext] = createRadioGroupContext(RADIO_GROUP_NAME),
57
5
  RadioGroupItemFrame = styled(ThemeableStack, {
58
6
  name: RADIO_GROUP_ITEM_NAME,
59
7
  tag: "button",
@@ -121,147 +69,25 @@ const RADIO_GROUP_ITEM_NAME = "RadioGroupItem",
121
69
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
122
70
  }
123
71
  }),
124
- RadioGroupItem = RadioGroupItemFrame.extractable(React.forwardRef((props, forwardedRef) => {
125
- const {
126
- __scopeRadioGroup,
127
- value,
128
- labelledBy: ariaLabelledby,
129
- disabled: itemDisabled,
130
- ...itemProps
131
- } = props,
132
- {
133
- value: groupValue,
134
- disabled,
135
- required,
136
- onChange,
137
- name,
138
- native,
139
- accentColor
140
- } = useRadioGroupContext(RADIO_GROUP_ITEM_NAME, __scopeRadioGroup),
141
- [button, setButton] = React.useState(null),
142
- hasConsumerStoppedPropagationRef = React.useRef(!1),
143
- ref = React.useRef(null),
144
- composedRefs = useComposedRefs(forwardedRef, node => setButton(node), ref),
145
- isArrowKeyPressedRef = React.useRef(!1),
146
- isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
147
- checked = groupValue === value,
148
- labelId = useLabelContext(button),
149
- labelledBy = ariaLabelledby || labelId;
150
- React.useEffect(() => {
151
- if (isWeb) {
152
- const handleKeyDown = event => {
153
- ARROW_KEYS.includes(event.key) && (isArrowKeyPressedRef.current = !0);
154
- },
155
- handleKeyUp = () => {
156
- isArrowKeyPressedRef.current = !1;
157
- };
158
- return document.addEventListener("keydown", handleKeyDown), document.addEventListener("keyup", handleKeyUp), () => {
159
- document.removeEventListener("keydown", handleKeyDown), document.removeEventListener("keyup", handleKeyUp);
160
- };
161
- }
162
- }, []);
163
- const isDisabled = disabled || itemDisabled;
164
- return /* @__PURE__ */jsx(RadioGroupItemProvider, {
165
- checked,
166
- scope: __scopeRadioGroup,
167
- children: isWeb && native ? /* @__PURE__ */jsx(BubbleInput, {
168
- control: button,
169
- bubbles: !hasConsumerStoppedPropagationRef.current,
170
- name,
171
- value,
172
- checked,
173
- required,
174
- disabled: isDisabled,
175
- id: props.id,
176
- accentColor
177
- }) : /* @__PURE__ */jsxs(Fragment, {
178
- children: [/* @__PURE__ */jsx(RovingFocusGroup.Item, {
179
- __scopeRovingFocusGroup: RADIO_GROUP_NAME,
180
- asChild: "except-style",
181
- focusable: !isDisabled,
182
- active: checked,
183
- children: /* @__PURE__ */jsx(RadioGroupItemFrame, {
184
- "data-state": getState(checked),
185
- "data-disabled": isDisabled ? "" : void 0,
186
- role: "radio",
187
- "aria-labelledby": labelledBy,
188
- "aria-checked": checked,
189
- "aria-required": required,
190
- disabled: isDisabled,
191
- ref: composedRefs,
192
- ...(isWeb && {
193
- type: "button",
194
- value
195
- }),
196
- ...itemProps,
197
- onPress: composeEventHandlers(props.onPress, event => {
198
- checked || onChange?.(value), isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
199
- }),
200
- ...(isWeb && {
201
- onKeyDown: composeEventHandlers(props.onKeyDown, event => {
202
- event.key === "Enter" && event.preventDefault();
203
- }),
204
- onFocus: composeEventHandlers(itemProps.onFocus, () => {
205
- isArrowKeyPressedRef.current && ref.current?.click();
206
- })
207
- })
208
- })
209
- }), isFormControl && /* @__PURE__ */jsx(BubbleInput, {
210
- isHidden: !0,
211
- control: button,
212
- bubbles: !hasConsumerStoppedPropagationRef.current,
213
- name,
214
- value,
215
- checked,
216
- required,
217
- disabled: isDisabled
218
- })]
219
- })
220
- });
221
- })),
222
- BubbleInput = props => {
223
- const {
224
- checked,
225
- bubbles = !0,
226
- control,
227
- isHidden,
228
- accentColor,
229
- ...inputProps
230
- } = props,
231
- ref = React.useRef(null),
232
- prevChecked = usePrevious(checked);
233
- return React.useEffect(() => {
234
- const input = ref.current,
235
- inputProto = window.HTMLInputElement.prototype,
236
- setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
237
- if (prevChecked !== checked && setChecked) {
238
- const event = new Event("click", {
239
- bubbles
240
- });
241
- setChecked.call(input, checked), input.dispatchEvent(event);
242
- }
243
- }, [prevChecked, checked, bubbles]), /* @__PURE__ */jsx("input", {
244
- type: "radio",
245
- defaultChecked: checked,
246
- ...inputProps,
247
- tabIndex: -1,
248
- ref,
249
- "aria-hidden": isHidden,
250
- style: {
251
- ...(isHidden ? {
252
- // ...controlSize,
253
- position: "absolute",
254
- pointerEvents: "none",
255
- opacity: 0,
256
- margin: 0
257
- } : {
258
- appearance: "auto",
259
- accentColor
260
- }),
261
- ...props.style
72
+ RADIO_GROUP_INDICATOR_NAME = "RadioGroupIndicator",
73
+ RadioGroupIndicatorFrame = styled(ThemeableStack, {
74
+ name: RADIO_GROUP_INDICATOR_NAME,
75
+ variants: {
76
+ unstyled: {
77
+ false: {
78
+ width: "33%",
79
+ height: "33%",
80
+ borderRadius: 1e3,
81
+ backgroundColor: "$color",
82
+ pressTheme: !0
83
+ }
262
84
  }
263
- });
264
- },
85
+ },
86
+ defaultVariants: {
87
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
88
+ }
89
+ }),
90
+ RADIO_GROUP_NAME = "RadioGroup",
265
91
  RadioGroupFrame = styled(ThemeableStack, {
266
92
  name: RADIO_GROUP_NAME,
267
93
  variants: {
@@ -276,52 +102,5 @@ const RADIO_GROUP_ITEM_NAME = "RadioGroupItem",
276
102
  }
277
103
  }
278
104
  }
279
- }),
280
- RadioGroup = withStaticProperties(RadioGroupFrame.extractable(React.forwardRef((props, forwardedRef) => {
281
- const {
282
- __scopeRadioGroup,
283
- value: valueProp,
284
- defaultValue,
285
- onValueChange,
286
- disabled = !1,
287
- required = !1,
288
- name,
289
- orientation,
290
- native,
291
- accentColor,
292
- ...radioGroupProps
293
- } = props,
294
- [value, setValue] = useControllableState({
295
- prop: valueProp,
296
- defaultProp: defaultValue,
297
- onChange: onValueChange
298
- });
299
- return /* @__PURE__ */jsx(RadioGroupProvider, {
300
- scope: __scopeRadioGroup,
301
- value,
302
- required,
303
- onChange: setValue,
304
- disabled,
305
- name,
306
- native,
307
- accentColor,
308
- children: /* @__PURE__ */jsx(RovingFocusGroup, {
309
- __scopeRovingFocusGroup: RADIO_GROUP_NAME,
310
- orientation,
311
- loop: !0,
312
- children: /* @__PURE__ */jsx(RadioGroupFrame, {
313
- role: "radiogroup",
314
- "aria-orientation": orientation,
315
- ref: forwardedRef,
316
- orientation,
317
- "data-disabled": disabled ? "" : void 0,
318
- ...radioGroupProps
319
- })
320
- })
321
- });
322
- })), {
323
- Indicator: RadioIndicator,
324
- Item: RadioGroupItem
325
105
  });
326
- RadioGroup.displayName = RADIO_GROUP_NAME;
327
- export { RadioGroup, createRadioGroupScope };
106
+ export { RadioGroupFrame, RadioGroupIndicatorFrame, RadioGroupItemFrame };
@@ -1,155 +1,7 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useComposedRefs } from "@tamagui/compose-refs";
3
- import { isWeb } from "@tamagui/constants";
4
1
  import { getVariableValue, styled } from "@tamagui/core";
5
- import { createContextScope } from "@tamagui/create-context";
6
- import { registerFocusable } from "@tamagui/focusable";
7
2
  import { getSize } from "@tamagui/get-token";
8
- import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
9
- import { useLabelContext } from "@tamagui/label";
10
- import { RovingFocusGroup } from "@tamagui/roving-focus";
11
3
  import { ThemeableStack } from "@tamagui/stacks";
12
- import { useControllableState } from "@tamagui/use-controllable-state";
13
- import { usePrevious } from "@tamagui/use-previous";
14
- import * as React from "react";
15
- function _array_like_to_array(arr, len) {
16
- (len == null || len > arr.length) && (len = arr.length);
17
- for (var i = 0, arr2 = new Array(len); i < len; i++)
18
- arr2[i] = arr[i];
19
- return arr2;
20
- }
21
- function _array_with_holes(arr) {
22
- if (Array.isArray(arr))
23
- return arr;
24
- }
25
- function _define_property(obj, key, value) {
26
- return key in obj ? Object.defineProperty(obj, key, {
27
- value,
28
- enumerable: !0,
29
- configurable: !0,
30
- writable: !0
31
- }) : obj[key] = value, obj;
32
- }
33
- function _iterable_to_array_limit(arr, i) {
34
- var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
35
- if (_i != null) {
36
- var _arr = [], _n = !0, _d = !1, _s, _e;
37
- try {
38
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
39
- ;
40
- } catch (err) {
41
- _d = !0, _e = err;
42
- } finally {
43
- try {
44
- !_n && _i.return != null && _i.return();
45
- } finally {
46
- if (_d)
47
- throw _e;
48
- }
49
- }
50
- return _arr;
51
- }
52
- }
53
- function _non_iterable_rest() {
54
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
55
- }
56
- function _object_spread(target) {
57
- for (var i = 1; i < arguments.length; i++) {
58
- var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
59
- typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
60
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
61
- }))), ownKeys2.forEach(function(key) {
62
- _define_property(target, key, source[key]);
63
- });
64
- }
65
- return target;
66
- }
67
- function ownKeys(object, enumerableOnly) {
68
- var keys = Object.keys(object);
69
- if (Object.getOwnPropertySymbols) {
70
- var symbols = Object.getOwnPropertySymbols(object);
71
- enumerableOnly && (symbols = symbols.filter(function(sym) {
72
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
73
- })), keys.push.apply(keys, symbols);
74
- }
75
- return keys;
76
- }
77
- function _object_spread_props(target, source) {
78
- return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
79
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
80
- }), target;
81
- }
82
- function _object_without_properties(source, excluded) {
83
- if (source == null)
84
- return {};
85
- var target = _object_without_properties_loose(source, excluded), key, i;
86
- if (Object.getOwnPropertySymbols) {
87
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
88
- for (i = 0; i < sourceSymbolKeys.length; i++)
89
- key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
90
- }
91
- return target;
92
- }
93
- function _object_without_properties_loose(source, excluded) {
94
- if (source == null)
95
- return {};
96
- var target = {}, sourceKeys = Object.keys(source), key, i;
97
- for (i = 0; i < sourceKeys.length; i++)
98
- key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
99
- return target;
100
- }
101
- function _sliced_to_array(arr, i) {
102
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
103
- }
104
- function _unsupported_iterable_to_array(o, minLen) {
105
- if (o) {
106
- if (typeof o == "string")
107
- return _array_like_to_array(o, minLen);
108
- var n = Object.prototype.toString.call(o).slice(8, -1);
109
- if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
110
- return Array.from(n);
111
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
112
- return _array_like_to_array(o, minLen);
113
- }
114
- }
115
- var RADIO_GROUP_NAME = "RadioGroup", ARROW_KEYS = [
116
- "ArrowUp",
117
- "ArrowDown",
118
- "ArrowLeft",
119
- "ArrowRight"
120
- ], _createContextScope = _sliced_to_array(createContextScope(RADIO_GROUP_NAME), 2), createRadioGroupContext = _createContextScope[0], createRadioGroupScope = _createContextScope[1], _createRadioGroupContext = _sliced_to_array(createRadioGroupContext(RADIO_GROUP_NAME), 2), RadioGroupProvider = _createRadioGroupContext[0], useRadioGroupContext = _createRadioGroupContext[1], getState = function(checked) {
121
- return checked ? "checked" : "unchecked";
122
- }, RADIO_GROUP_INDICATOR_NAME = "RadioGroupIndicator", RadioIndicatorFrame = styled(ThemeableStack, {
123
- name: RADIO_GROUP_INDICATOR_NAME,
124
- variants: {
125
- unstyled: {
126
- false: {
127
- width: "33%",
128
- height: "33%",
129
- borderRadius: 1e3,
130
- backgroundColor: "$color",
131
- pressTheme: !0
132
- }
133
- }
134
- },
135
- defaultVariants: {
136
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
137
- }
138
- }), RadioIndicator = RadioIndicatorFrame.extractable(/* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
139
- var __scopeRadioGroupItem = props.__scopeRadioGroupItem, forceMount = props.forceMount, disabled = props.disabled, indicatorProps = _object_without_properties(props, [
140
- "__scopeRadioGroupItem",
141
- "forceMount",
142
- "disabled"
143
- ]), checked = useRadioGroupItemContext(RADIO_GROUP_INDICATOR_NAME, __scopeRadioGroupItem).checked;
144
- return forceMount || checked ? /* @__PURE__ */ _jsx(RadioIndicatorFrame, _object_spread_props(_object_spread({
145
- "data-state": getState(checked),
146
- "data-disabled": disabled ? "" : void 0
147
- }, indicatorProps), {
148
- ref: forwardedRef
149
- })) : null;
150
- }));
151
- RadioIndicator.displayName = RADIO_GROUP_INDICATOR_NAME;
152
- var RADIO_GROUP_ITEM_NAME = "RadioGroupItem", _createRadioGroupContext1 = _sliced_to_array(createRadioGroupContext(RADIO_GROUP_NAME), 2), RadioGroupItemProvider = _createRadioGroupContext1[0], useRadioGroupItemContext = _createRadioGroupContext1[1], RadioGroupItemFrame = styled(ThemeableStack, {
4
+ var RADIO_GROUP_ITEM_NAME = "RadioGroupItem", RadioGroupItemFrame = styled(ThemeableStack, {
153
5
  name: RADIO_GROUP_ITEM_NAME,
154
6
  tag: "button",
155
7
  variants: {
@@ -213,147 +65,23 @@ var RADIO_GROUP_ITEM_NAME = "RadioGroupItem", _createRadioGroupContext1 = _slice
213
65
  defaultVariants: {
214
66
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
215
67
  }
216
- }), RadioGroupItem = RadioGroupItemFrame.extractable(/* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
217
- var __scopeRadioGroup = props.__scopeRadioGroup, value = props.value, ariaLabelledby = props.labelledBy, itemDisabled = props.disabled, itemProps = _object_without_properties(props, [
218
- "__scopeRadioGroup",
219
- "value",
220
- "labelledBy",
221
- "disabled"
222
- ]), _useRadioGroupContext = useRadioGroupContext(RADIO_GROUP_ITEM_NAME, __scopeRadioGroup), groupValue = _useRadioGroupContext.value, disabled = _useRadioGroupContext.disabled, required = _useRadioGroupContext.required, onChange = _useRadioGroupContext.onChange, name = _useRadioGroupContext.name, native = _useRadioGroupContext.native, accentColor = _useRadioGroupContext.accentColor, _React_useState = _sliced_to_array(React.useState(null), 2), button = _React_useState[0], setButton = _React_useState[1], hasConsumerStoppedPropagationRef = React.useRef(!1), ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, function(node) {
223
- return setButton(node);
224
- }, ref), isArrowKeyPressedRef = React.useRef(!1), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, checked = groupValue === value, labelId = useLabelContext(button), labelledBy = ariaLabelledby || labelId;
225
- React.useEffect(function() {
226
- if (isWeb) {
227
- var handleKeyDown = function(event) {
228
- ARROW_KEYS.includes(event.key) && (isArrowKeyPressedRef.current = !0);
229
- }, handleKeyUp = function() {
230
- isArrowKeyPressedRef.current = !1;
231
- };
232
- return document.addEventListener("keydown", handleKeyDown), document.addEventListener("keyup", handleKeyUp), function() {
233
- document.removeEventListener("keydown", handleKeyDown), document.removeEventListener("keyup", handleKeyUp);
234
- };
235
- }
236
- }, []), React.useEffect(function() {
237
- if (props.id && !disabled)
238
- return registerFocusable(props.id, {
239
- focusAndSelect: function() {
240
- onChange == null || onChange(value);
241
- },
242
- focus: function() {
243
- }
244
- });
245
- }, [
246
- props.id,
247
- value,
248
- disabled
249
- ]);
250
- var isDisabled = disabled || itemDisabled;
251
- return /* @__PURE__ */ _jsx(RadioGroupItemProvider, {
252
- checked,
253
- scope: __scopeRadioGroup,
254
- children: isWeb && native ? /* @__PURE__ */ _jsx(BubbleInput, {
255
- control: button,
256
- bubbles: !hasConsumerStoppedPropagationRef.current,
257
- name,
258
- value,
259
- checked,
260
- required,
261
- disabled: isDisabled,
262
- id: props.id,
263
- accentColor
264
- }) : /* @__PURE__ */ _jsxs(_Fragment, {
265
- children: [
266
- /* @__PURE__ */ _jsx(RovingFocusGroup.Item, {
267
- __scopeRovingFocusGroup: RADIO_GROUP_NAME,
268
- asChild: "except-style",
269
- focusable: !isDisabled,
270
- active: checked,
271
- children: /* @__PURE__ */ _jsx(RadioGroupItemFrame, _object_spread(_object_spread_props(_object_spread(
272
- {
273
- // theme={checked ? 'active' : undefined}
274
- "data-state": getState(checked),
275
- "data-disabled": isDisabled ? "" : void 0,
276
- role: "radio",
277
- "aria-labelledby": labelledBy,
278
- "aria-checked": checked,
279
- "aria-required": required,
280
- disabled: isDisabled,
281
- ref: composedRefs
282
- },
283
- isWeb && {
284
- type: "button",
285
- value
286
- },
287
- // allow them to override all but the handlers that already compose:
288
- itemProps
289
- ), {
290
- onPress: composeEventHandlers(props.onPress, function(event) {
291
- checked || onChange == null || onChange(value), isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
292
- })
293
- }), isWeb && {
294
- onKeyDown: composeEventHandlers(props.onKeyDown, function(event) {
295
- event.key === "Enter" && event.preventDefault();
296
- }),
297
- onFocus: composeEventHandlers(itemProps.onFocus, function() {
298
- if (isArrowKeyPressedRef.current) {
299
- var _ref_current;
300
- (_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();
301
- }
302
- })
303
- }))
304
- }),
305
- isFormControl && /* @__PURE__ */ _jsx(BubbleInput, {
306
- isHidden: !0,
307
- control: button,
308
- bubbles: !hasConsumerStoppedPropagationRef.current,
309
- name,
310
- value,
311
- checked,
312
- required,
313
- disabled: isDisabled
314
- })
315
- ]
316
- })
317
- });
318
- })), BubbleInput = function(props) {
319
- var checked = props.checked, _props_bubbles = props.bubbles, bubbles = _props_bubbles === void 0 ? !0 : _props_bubbles, control = props.control, isHidden = props.isHidden, accentColor = props.accentColor, inputProps = _object_without_properties(props, [
320
- "checked",
321
- "bubbles",
322
- "control",
323
- "isHidden",
324
- "accentColor"
325
- ]), ref = React.useRef(null), prevChecked = usePrevious(checked);
326
- return React.useEffect(function() {
327
- var input = ref.current, inputProto = window.HTMLInputElement.prototype, descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"), setChecked = descriptor.set;
328
- if (prevChecked !== checked && setChecked) {
329
- var event = new Event("click", {
330
- bubbles
331
- });
332
- setChecked.call(input, checked), input.dispatchEvent(event);
68
+ }), RADIO_GROUP_INDICATOR_NAME = "RadioGroupIndicator", RadioGroupIndicatorFrame = styled(ThemeableStack, {
69
+ name: RADIO_GROUP_INDICATOR_NAME,
70
+ variants: {
71
+ unstyled: {
72
+ false: {
73
+ width: "33%",
74
+ height: "33%",
75
+ borderRadius: 1e3,
76
+ backgroundColor: "$color",
77
+ pressTheme: !0
78
+ }
333
79
  }
334
- }, [
335
- prevChecked,
336
- checked,
337
- bubbles
338
- ]), /* @__PURE__ */ _jsx("input", _object_spread_props(_object_spread({
339
- type: "radio",
340
- defaultChecked: checked
341
- }, inputProps), {
342
- tabIndex: -1,
343
- ref,
344
- "aria-hidden": isHidden,
345
- style: _object_spread({}, isHidden ? {
346
- // ...controlSize,
347
- position: "absolute",
348
- pointerEvents: "none",
349
- opacity: 0,
350
- margin: 0
351
- } : {
352
- appearance: "auto",
353
- accentColor
354
- }, props.style)
355
- }));
356
- }, RadioGroupFrame = styled(ThemeableStack, {
80
+ },
81
+ defaultVariants: {
82
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
83
+ }
84
+ }), RADIO_GROUP_NAME = "RadioGroup", RadioGroupFrame = styled(ThemeableStack, {
357
85
  name: RADIO_GROUP_NAME,
358
86
  variants: {
359
87
  orientation: {
@@ -367,52 +95,10 @@ var RADIO_GROUP_ITEM_NAME = "RadioGroupItem", _createRadioGroupContext1 = _slice
367
95
  }
368
96
  }
369
97
  }
370
- }), RadioGroup = withStaticProperties(RadioGroupFrame.extractable(/* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
371
- var __scopeRadioGroup = props.__scopeRadioGroup, valueProp = props.value, defaultValue = props.defaultValue, onValueChange = props.onValueChange, _props_disabled = props.disabled, disabled = _props_disabled === void 0 ? !1 : _props_disabled, _props_required = props.required, required = _props_required === void 0 ? !1 : _props_required, name = props.name, orientation = props.orientation, native = props.native, accentColor = props.accentColor, radioGroupProps = _object_without_properties(props, [
372
- "__scopeRadioGroup",
373
- "value",
374
- "defaultValue",
375
- "onValueChange",
376
- "disabled",
377
- "required",
378
- "name",
379
- "orientation",
380
- "native",
381
- "accentColor"
382
- ]), _useControllableState = _sliced_to_array(useControllableState({
383
- prop: valueProp,
384
- defaultProp: defaultValue,
385
- onChange: onValueChange
386
- }), 2), value = _useControllableState[0], setValue = _useControllableState[1];
387
- return /* @__PURE__ */ _jsx(RadioGroupProvider, {
388
- scope: __scopeRadioGroup,
389
- value,
390
- required,
391
- onChange: setValue,
392
- disabled,
393
- name,
394
- native,
395
- accentColor,
396
- children: /* @__PURE__ */ _jsx(RovingFocusGroup, {
397
- __scopeRovingFocusGroup: RADIO_GROUP_NAME,
398
- orientation,
399
- loop: !0,
400
- children: /* @__PURE__ */ _jsx(RadioGroupFrame, _object_spread({
401
- role: "radiogroup",
402
- "aria-orientation": orientation,
403
- ref: forwardedRef,
404
- orientation,
405
- "data-disabled": disabled ? "" : void 0
406
- }, radioGroupProps))
407
- })
408
- });
409
- })), {
410
- Indicator: RadioIndicator,
411
- Item: RadioGroupItem
412
98
  });
413
- RadioGroup.displayName = RADIO_GROUP_NAME;
414
99
  export {
415
- RadioGroup,
416
- createRadioGroupScope
100
+ RadioGroupFrame,
101
+ RadioGroupIndicatorFrame,
102
+ RadioGroupItemFrame
417
103
  };
418
104
  //# sourceMappingURL=RadioGroup.js.map