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