@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.
- package/dist/cjs/RadioGroup.js +23 -248
- package/dist/cjs/RadioGroup.js.map +1 -1
- package/dist/cjs/RadioGroup.native.js +25 -336
- package/dist/cjs/RadioGroup.native.js.map +2 -2
- package/dist/cjs/RadioGroupStyledContext.js +25 -0
- package/dist/cjs/RadioGroupStyledContext.js.map +6 -0
- package/dist/cjs/RadioGroupStyledContext.native.js +29 -0
- package/dist/cjs/RadioGroupStyledContext.native.js.map +6 -0
- package/dist/cjs/createRadioGroup.js +107 -0
- package/dist/cjs/createRadioGroup.js.map +6 -0
- package/dist/cjs/createRadioGroup.native.js +171 -0
- package/dist/cjs/createRadioGroup.native.js.map +6 -0
- package/dist/cjs/index.js +15 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +19 -2
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/RadioGroup.js +20 -248
- package/dist/esm/RadioGroup.js.map +1 -1
- package/dist/esm/RadioGroup.mjs +19 -240
- package/dist/esm/RadioGroup.native.js +20 -334
- package/dist/esm/RadioGroup.native.js.map +2 -2
- package/dist/esm/RadioGroupStyledContext.js +9 -0
- package/dist/esm/RadioGroupStyledContext.js.map +6 -0
- package/dist/esm/RadioGroupStyledContext.mjs +6 -0
- package/dist/esm/RadioGroupStyledContext.native.js +9 -0
- package/dist/esm/RadioGroupStyledContext.native.js.map +6 -0
- package/dist/esm/createRadioGroup.js +104 -0
- package/dist/esm/createRadioGroup.js.map +6 -0
- package/dist/esm/createRadioGroup.mjs +131 -0
- package/dist/esm/createRadioGroup.native.js +155 -0
- package/dist/esm/createRadioGroup.native.js.map +6 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +11 -1
- package/dist/esm/index.native.js +12 -0
- package/dist/esm/index.native.js.map +2 -2
- package/dist/jsx/RadioGroup.js +20 -248
- package/dist/jsx/RadioGroup.js.map +1 -1
- package/dist/jsx/RadioGroup.mjs +19 -240
- package/dist/jsx/RadioGroup.native.js +20 -334
- package/dist/jsx/RadioGroup.native.js.map +2 -2
- package/dist/jsx/RadioGroupStyledContext.js +9 -0
- package/dist/jsx/RadioGroupStyledContext.js.map +6 -0
- package/dist/jsx/RadioGroupStyledContext.mjs +6 -0
- package/dist/jsx/RadioGroupStyledContext.native.js +9 -0
- package/dist/jsx/RadioGroupStyledContext.native.js.map +6 -0
- package/dist/jsx/createRadioGroup.js +104 -0
- package/dist/jsx/createRadioGroup.js.map +6 -0
- package/dist/jsx/createRadioGroup.mjs +131 -0
- package/dist/jsx/createRadioGroup.native.js +155 -0
- package/dist/jsx/createRadioGroup.native.js.map +6 -0
- package/dist/jsx/index.js +16 -0
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +11 -1
- package/dist/jsx/index.native.js +12 -0
- package/dist/jsx/index.native.js.map +2 -2
- package/package.json +14 -14
- package/src/RadioGroup.tsx +22 -432
- package/src/RadioGroupStyledContext.tsx +7 -0
- package/src/createRadioGroup.tsx +201 -0
- package/src/index.ts +15 -0
- package/types/RadioGroup.d.ts +7 -224
- package/types/RadioGroup.d.ts.map +1 -1
- package/types/RadioGroupStyledContext.d.ts +6 -0
- package/types/RadioGroupStyledContext.d.ts.map +1 -0
- package/types/createRadioGroup.d.ts +979 -0
- package/types/createRadioGroup.d.ts.map +1 -0
- package/types/index.d.ts +949 -0
- package/types/index.d.ts.map +1 -1
package/dist/jsx/RadioGroup.js
CHANGED
|
@@ -1,54 +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
|
-
|
|
6
2
|
import { getSize } from "@tamagui/get-token";
|
|
7
|
-
import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
|
|
8
|
-
import { useLabelContext } from "@tamagui/label";
|
|
9
|
-
import { RovingFocusGroup } from "@tamagui/roving-focus";
|
|
10
3
|
import { ThemeableStack } from "@tamagui/stacks";
|
|
11
|
-
|
|
12
|
-
import { usePrevious } from "@tamagui/use-previous";
|
|
13
|
-
import * as React from "react";
|
|
14
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
-
const RADIO_GROUP_NAME = "RadioGroup", ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], [createRadioGroupContext, createRadioGroupScope] = createContextScope(RADIO_GROUP_NAME), [RadioGroupProvider, useRadioGroupContext] = createRadioGroupContext(RADIO_GROUP_NAME), getState = (checked) => checked ? "checked" : "unchecked", RADIO_GROUP_INDICATOR_NAME = "RadioGroupIndicator", RadioIndicatorFrame = styled(ThemeableStack, {
|
|
16
|
-
name: RADIO_GROUP_INDICATOR_NAME,
|
|
17
|
-
variants: {
|
|
18
|
-
unstyled: {
|
|
19
|
-
false: {
|
|
20
|
-
width: "33%",
|
|
21
|
-
height: "33%",
|
|
22
|
-
borderRadius: 1e3,
|
|
23
|
-
backgroundColor: "$color",
|
|
24
|
-
pressTheme: !0
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
defaultVariants: {
|
|
29
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
30
|
-
}
|
|
31
|
-
}), RadioIndicator = RadioIndicatorFrame.extractable(
|
|
32
|
-
React.forwardRef(
|
|
33
|
-
(props, forwardedRef) => {
|
|
34
|
-
const { __scopeRadioGroupItem, forceMount, disabled, ...indicatorProps } = props, { checked } = useRadioGroupItemContext(
|
|
35
|
-
RADIO_GROUP_INDICATOR_NAME,
|
|
36
|
-
__scopeRadioGroupItem
|
|
37
|
-
);
|
|
38
|
-
return forceMount || checked ? /* @__PURE__ */ jsx(
|
|
39
|
-
RadioIndicatorFrame,
|
|
40
|
-
{
|
|
41
|
-
"data-state": getState(checked),
|
|
42
|
-
"data-disabled": disabled ? "" : void 0,
|
|
43
|
-
...indicatorProps,
|
|
44
|
-
ref: forwardedRef
|
|
45
|
-
}
|
|
46
|
-
) : null;
|
|
47
|
-
}
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
RadioIndicator.displayName = RADIO_GROUP_INDICATOR_NAME;
|
|
51
|
-
const RADIO_GROUP_ITEM_NAME = "RadioGroupItem", [RadioGroupItemProvider, useRadioGroupItemContext] = createRadioGroupContext(RADIO_GROUP_NAME), RadioGroupItemFrame = styled(ThemeableStack, {
|
|
4
|
+
const RADIO_GROUP_ITEM_NAME = "RadioGroupItem", RadioGroupItemFrame = styled(ThemeableStack, {
|
|
52
5
|
name: RADIO_GROUP_ITEM_NAME,
|
|
53
6
|
tag: "button",
|
|
54
7
|
variants: {
|
|
@@ -114,144 +67,23 @@ const RADIO_GROUP_ITEM_NAME = "RadioGroupItem", [RadioGroupItemProvider, useRadi
|
|
|
114
67
|
defaultVariants: {
|
|
115
68
|
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
116
69
|
}
|
|
117
|
-
}),
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
value: groupValue,
|
|
128
|
-
disabled,
|
|
129
|
-
required,
|
|
130
|
-
onChange,
|
|
131
|
-
name,
|
|
132
|
-
native,
|
|
133
|
-
accentColor
|
|
134
|
-
} = useRadioGroupContext(RADIO_GROUP_ITEM_NAME, __scopeRadioGroup), [button, setButton] = React.useState(null), hasConsumerStoppedPropagationRef = React.useRef(!1), ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node), ref), isArrowKeyPressedRef = React.useRef(!1), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, checked = groupValue === value, labelId = useLabelContext(button), labelledBy = ariaLabelledby || labelId;
|
|
135
|
-
React.useEffect(() => {
|
|
136
|
-
if (isWeb) {
|
|
137
|
-
const handleKeyDown = (event) => {
|
|
138
|
-
ARROW_KEYS.includes(event.key) && (isArrowKeyPressedRef.current = !0);
|
|
139
|
-
}, handleKeyUp = () => {
|
|
140
|
-
isArrowKeyPressedRef.current = !1;
|
|
141
|
-
};
|
|
142
|
-
return document.addEventListener("keydown", handleKeyDown), document.addEventListener("keyup", handleKeyUp), () => {
|
|
143
|
-
document.removeEventListener("keydown", handleKeyDown), document.removeEventListener("keyup", handleKeyUp);
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}, []);
|
|
147
|
-
const isDisabled = disabled || itemDisabled;
|
|
148
|
-
return /* @__PURE__ */ jsx(RadioGroupItemProvider, { checked, scope: __scopeRadioGroup, children: isWeb && native ? /* @__PURE__ */ jsx(
|
|
149
|
-
BubbleInput,
|
|
150
|
-
{
|
|
151
|
-
control: button,
|
|
152
|
-
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
153
|
-
name,
|
|
154
|
-
value,
|
|
155
|
-
checked,
|
|
156
|
-
required,
|
|
157
|
-
disabled: isDisabled,
|
|
158
|
-
id: props.id,
|
|
159
|
-
accentColor
|
|
160
|
-
}
|
|
161
|
-
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
162
|
-
/* @__PURE__ */ jsx(
|
|
163
|
-
RovingFocusGroup.Item,
|
|
164
|
-
{
|
|
165
|
-
__scopeRovingFocusGroup: RADIO_GROUP_NAME,
|
|
166
|
-
asChild: "except-style",
|
|
167
|
-
focusable: !isDisabled,
|
|
168
|
-
active: checked,
|
|
169
|
-
children: /* @__PURE__ */ jsx(
|
|
170
|
-
RadioGroupItemFrame,
|
|
171
|
-
{
|
|
172
|
-
"data-state": getState(checked),
|
|
173
|
-
"data-disabled": isDisabled ? "" : void 0,
|
|
174
|
-
role: "radio",
|
|
175
|
-
"aria-labelledby": labelledBy,
|
|
176
|
-
"aria-checked": checked,
|
|
177
|
-
"aria-required": required,
|
|
178
|
-
disabled: isDisabled,
|
|
179
|
-
ref: composedRefs,
|
|
180
|
-
...isWeb && {
|
|
181
|
-
type: "button",
|
|
182
|
-
value
|
|
183
|
-
},
|
|
184
|
-
...itemProps,
|
|
185
|
-
onPress: composeEventHandlers(props.onPress, (event) => {
|
|
186
|
-
checked || onChange?.(value), isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
187
|
-
}),
|
|
188
|
-
...isWeb && {
|
|
189
|
-
onKeyDown: composeEventHandlers(
|
|
190
|
-
props.onKeyDown,
|
|
191
|
-
(event) => {
|
|
192
|
-
event.key === "Enter" && event.preventDefault();
|
|
193
|
-
}
|
|
194
|
-
),
|
|
195
|
-
onFocus: composeEventHandlers(itemProps.onFocus, () => {
|
|
196
|
-
isArrowKeyPressedRef.current && ref.current?.click();
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
),
|
|
203
|
-
isFormControl && /* @__PURE__ */ jsx(
|
|
204
|
-
BubbleInput,
|
|
205
|
-
{
|
|
206
|
-
isHidden: !0,
|
|
207
|
-
control: button,
|
|
208
|
-
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
209
|
-
name,
|
|
210
|
-
value,
|
|
211
|
-
checked,
|
|
212
|
-
required,
|
|
213
|
-
disabled: isDisabled
|
|
214
|
-
}
|
|
215
|
-
)
|
|
216
|
-
] }) });
|
|
217
|
-
}
|
|
218
|
-
)
|
|
219
|
-
), BubbleInput = (props) => {
|
|
220
|
-
const { checked, bubbles = !0, control, isHidden, accentColor, ...inputProps } = props, ref = React.useRef(null), prevChecked = usePrevious(checked);
|
|
221
|
-
return React.useEffect(() => {
|
|
222
|
-
const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
|
|
223
|
-
inputProto,
|
|
224
|
-
"checked"
|
|
225
|
-
).set;
|
|
226
|
-
if (prevChecked !== checked && setChecked) {
|
|
227
|
-
const event = new Event("click", { bubbles });
|
|
228
|
-
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
229
|
-
}
|
|
230
|
-
}, [prevChecked, checked, bubbles]), /* @__PURE__ */ jsx(
|
|
231
|
-
"input",
|
|
232
|
-
{
|
|
233
|
-
type: "radio",
|
|
234
|
-
defaultChecked: checked,
|
|
235
|
-
...inputProps,
|
|
236
|
-
tabIndex: -1,
|
|
237
|
-
ref,
|
|
238
|
-
"aria-hidden": isHidden,
|
|
239
|
-
style: {
|
|
240
|
-
...isHidden ? {
|
|
241
|
-
// ...controlSize,
|
|
242
|
-
position: "absolute",
|
|
243
|
-
pointerEvents: "none",
|
|
244
|
-
opacity: 0,
|
|
245
|
-
margin: 0
|
|
246
|
-
} : {
|
|
247
|
-
appearance: "auto",
|
|
248
|
-
accentColor
|
|
249
|
-
},
|
|
250
|
-
...props.style
|
|
70
|
+
}), RADIO_GROUP_INDICATOR_NAME = "RadioGroupIndicator", RadioGroupIndicatorFrame = styled(ThemeableStack, {
|
|
71
|
+
name: RADIO_GROUP_INDICATOR_NAME,
|
|
72
|
+
variants: {
|
|
73
|
+
unstyled: {
|
|
74
|
+
false: {
|
|
75
|
+
width: "33%",
|
|
76
|
+
height: "33%",
|
|
77
|
+
borderRadius: 1e3,
|
|
78
|
+
backgroundColor: "$color",
|
|
79
|
+
pressTheme: !0
|
|
251
80
|
}
|
|
252
81
|
}
|
|
253
|
-
|
|
254
|
-
|
|
82
|
+
},
|
|
83
|
+
defaultVariants: {
|
|
84
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
85
|
+
}
|
|
86
|
+
}), RADIO_GROUP_NAME = "RadioGroup", RadioGroupFrame = styled(ThemeableStack, {
|
|
255
87
|
name: RADIO_GROUP_NAME,
|
|
256
88
|
variants: {
|
|
257
89
|
orientation: {
|
|
@@ -265,70 +97,10 @@ const RADIO_GROUP_ITEM_NAME = "RadioGroupItem", [RadioGroupItemProvider, useRadi
|
|
|
265
97
|
}
|
|
266
98
|
}
|
|
267
99
|
}
|
|
268
|
-
})
|
|
269
|
-
RadioGroupFrame.extractable(
|
|
270
|
-
React.forwardRef(
|
|
271
|
-
(props, forwardedRef) => {
|
|
272
|
-
const {
|
|
273
|
-
__scopeRadioGroup,
|
|
274
|
-
value: valueProp,
|
|
275
|
-
defaultValue,
|
|
276
|
-
onValueChange,
|
|
277
|
-
disabled = !1,
|
|
278
|
-
required = !1,
|
|
279
|
-
name,
|
|
280
|
-
orientation,
|
|
281
|
-
native,
|
|
282
|
-
accentColor,
|
|
283
|
-
...radioGroupProps
|
|
284
|
-
} = props, [value, setValue] = useControllableState({
|
|
285
|
-
prop: valueProp,
|
|
286
|
-
defaultProp: defaultValue,
|
|
287
|
-
onChange: onValueChange
|
|
288
|
-
});
|
|
289
|
-
return /* @__PURE__ */ jsx(
|
|
290
|
-
RadioGroupProvider,
|
|
291
|
-
{
|
|
292
|
-
scope: __scopeRadioGroup,
|
|
293
|
-
value,
|
|
294
|
-
required,
|
|
295
|
-
onChange: setValue,
|
|
296
|
-
disabled,
|
|
297
|
-
name,
|
|
298
|
-
native,
|
|
299
|
-
accentColor,
|
|
300
|
-
children: /* @__PURE__ */ jsx(
|
|
301
|
-
RovingFocusGroup,
|
|
302
|
-
{
|
|
303
|
-
__scopeRovingFocusGroup: RADIO_GROUP_NAME,
|
|
304
|
-
orientation,
|
|
305
|
-
loop: !0,
|
|
306
|
-
children: /* @__PURE__ */ jsx(
|
|
307
|
-
RadioGroupFrame,
|
|
308
|
-
{
|
|
309
|
-
role: "radiogroup",
|
|
310
|
-
"aria-orientation": orientation,
|
|
311
|
-
ref: forwardedRef,
|
|
312
|
-
orientation,
|
|
313
|
-
"data-disabled": disabled ? "" : void 0,
|
|
314
|
-
...radioGroupProps
|
|
315
|
-
}
|
|
316
|
-
)
|
|
317
|
-
}
|
|
318
|
-
)
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
)
|
|
323
|
-
),
|
|
324
|
-
{
|
|
325
|
-
Indicator: RadioIndicator,
|
|
326
|
-
Item: RadioGroupItem
|
|
327
|
-
}
|
|
328
|
-
);
|
|
329
|
-
RadioGroup.displayName = RADIO_GROUP_NAME;
|
|
100
|
+
});
|
|
330
101
|
export {
|
|
331
|
-
|
|
332
|
-
|
|
102
|
+
RadioGroupFrame,
|
|
103
|
+
RadioGroupIndicatorFrame,
|
|
104
|
+
RadioGroupItemFrame
|
|
333
105
|
};
|
|
334
106
|
//# sourceMappingURL=RadioGroup.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/RadioGroup.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AAAA,SAAS,kBAAkB,cAAc;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAE/B,MAAM,wBAAwB,kBAEjB,sBAAsB,OAAO,gBAAgB;AAAA,EACxD,MAAM;AAAA,EACN,KAAK;AAAA,EAEL,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,QACN,cAAc;AAAA,QACd,iBAAiB;AAAA,QACjB,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,aAAa;AAAA,QACb,aAAa;AAAA,QACb,SAAS;AAAA,QAET,YAAY;AAAA,UACV,aAAa;AAAA,UACb,iBAAiB;AAAA,QACnB;AAAA,QAEA,YAAY;AAAA,UACV,aAAa;AAAA,UACb,iBAAiB;AAAA,QACnB;AAAA,QAEA,mBAAmB;AAAA,UACjB,cAAc;AAAA,UACd,cAAc;AAAA,UACd,cAAc;AAAA,QAChB;AAAA,QAEA,YAAY;AAAA,UACV,aAAa;AAAA,UACb,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,QAAQ;AAAA,QAER,YAAY;AAAA,UACV,aAAa;AAAA,UACb,iBAAiB;AAAA,QACnB;AAAA,QAEA,YAAY;AAAA,UACV,aAAa;AAAA,UACb,iBAAiB;AAAA,QACnB;AAAA,QAEA,mBAAmB;AAAA,UACjB,cAAc;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM;AAAA,MACJ,WAAW,CAAC,OAAO,EAAE,MAAM,MAAM;AAC/B,cAAM,OAAO,KAAK;AAAA,UAChB,iBAAiB,QAAQ,KAAK,CAAC,KAAK,MAAM,aAAgB;AAAA,QAC5D;AACA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU,QAAQ,IAAI,qBAAqB;AAAA,EAC7C;AACF,CAAC,GAEK,6BAA6B,uBAEtB,2BAA2B,OAAO,gBAAgB;AAAA,EAC7D,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,cAAc;AAAA,QACd,iBAAiB;AAAA,QACjB,YAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU,QAAQ,IAAI,qBAAqB;AAAA,EAC7C;AACF,CAAC,GAEK,mBAAmB,cAEZ,kBAAkB,OAAO,gBAAgB;AAAA,EACpD,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,aAAa;AAAA,MACX,YAAY;AAAA,QACV,eAAe;AAAA,QACf,gBAAgB;AAAA,MAClB;AAAA,MACA,UAAU;AAAA,QACR,eAAe;AAAA,QACf,gBAAgB;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACF,CAAC;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/jsx/RadioGroup.mjs
CHANGED
|
@@ -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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
327
|
-
export { RadioGroup, createRadioGroupScope };
|
|
106
|
+
export { RadioGroupFrame, RadioGroupIndicatorFrame, RadioGroupItemFrame };
|