@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.
- package/dist/cjs/BubbleInput.cjs +45 -40
- package/dist/cjs/BubbleInput.native.js +73 -69
- package/dist/cjs/BubbleInput.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useRadioGroup.cjs +149 -138
- package/dist/cjs/useRadioGroup.native.js +163 -149
- package/dist/cjs/useRadioGroup.native.js.map +1 -1
- package/dist/cjs/utils.cjs +12 -10
- package/dist/cjs/utils.native.js +12 -10
- package/dist/cjs/utils.native.js.map +1 -1
- package/dist/esm/BubbleInput.mjs +18 -15
- package/dist/esm/BubbleInput.mjs.map +1 -1
- package/dist/esm/BubbleInput.native.js +18 -16
- package/dist/esm/BubbleInput.native.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/useRadioGroup.mjs +128 -118
- package/dist/esm/useRadioGroup.mjs.map +1 -1
- package/dist/esm/useRadioGroup.native.js +141 -129
- package/dist/esm/useRadioGroup.native.js.map +1 -1
- package/dist/jsx/BubbleInput.mjs +18 -15
- package/dist/jsx/BubbleInput.mjs.map +1 -1
- package/dist/jsx/BubbleInput.native.js +73 -69
- package/dist/jsx/BubbleInput.native.js.map +1 -1
- package/dist/jsx/index.js +2 -2
- package/dist/jsx/index.js.map +1 -6
- package/dist/jsx/index.native.js +7 -5
- package/dist/jsx/useRadioGroup.mjs +128 -118
- package/dist/jsx/useRadioGroup.mjs.map +1 -1
- package/dist/jsx/useRadioGroup.native.js +163 -149
- package/dist/jsx/useRadioGroup.native.js.map +1 -1
- package/dist/jsx/utils.native.js +12 -10
- package/package.json +16 -20
- package/dist/cjs/BubbleInput.js +0 -65
- package/dist/cjs/BubbleInput.js.map +0 -6
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useRadioGroup.js +0 -160
- package/dist/cjs/useRadioGroup.js.map +0 -6
- package/dist/cjs/utils.js +0 -23
- package/dist/cjs/utils.js.map +0 -6
- package/dist/esm/BubbleInput.js +0 -43
- package/dist/esm/BubbleInput.js.map +0 -6
- package/dist/esm/useRadioGroup.js +0 -153
- package/dist/esm/useRadioGroup.js.map +0 -6
- package/dist/esm/utils.js +0 -7
- package/dist/esm/utils.js.map +0 -6
- package/dist/jsx/BubbleInput.js +0 -43
- package/dist/jsx/BubbleInput.js.map +0 -6
- package/dist/jsx/useRadioGroup.js +0 -153
- package/dist/jsx/useRadioGroup.js.map +0 -6
- package/dist/jsx/utils.js +0 -7
- 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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:
|
|
75
|
+
loop: true
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
|
-
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
161
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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),
|