@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
package/dist/esm/BubbleInput.mjs
CHANGED
|
@@ -1,51 +1,47 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { usePrevious } from "@tamagui/use-previous";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
accentColor
|
|
45
|
-
}),
|
|
46
|
-
...props.style
|
|
47
|
-
}
|
|
48
|
-
});
|
|
4
|
+
|
|
5
|
+
const BubbleInput = (props) => {
|
|
6
|
+
const { checked, bubbles = true, control, isHidden, accentColor, ...inputProps } = props;
|
|
7
|
+
const ref = React.useRef(null);
|
|
8
|
+
const prevChecked = usePrevious(checked);
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
const input = ref.current;
|
|
11
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
12
|
+
const descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked");
|
|
13
|
+
const setChecked = descriptor.set;
|
|
14
|
+
if (prevChecked !== checked && setChecked) {
|
|
15
|
+
const event = new Event("click", { bubbles });
|
|
16
|
+
setChecked.call(input, checked);
|
|
17
|
+
input.dispatchEvent(event);
|
|
18
|
+
}
|
|
19
|
+
}, [
|
|
20
|
+
prevChecked,
|
|
21
|
+
checked,
|
|
22
|
+
bubbles
|
|
23
|
+
]);
|
|
24
|
+
return /* @__PURE__ */ jsx("input", {
|
|
25
|
+
type: "radio",
|
|
26
|
+
defaultChecked: checked,
|
|
27
|
+
...inputProps,
|
|
28
|
+
tabIndex: -1,
|
|
29
|
+
ref,
|
|
30
|
+
"aria-hidden": isHidden,
|
|
31
|
+
style: {
|
|
32
|
+
...isHidden ? {
|
|
33
|
+
position: "absolute",
|
|
34
|
+
pointerEvents: "none",
|
|
35
|
+
opacity: 0,
|
|
36
|
+
margin: 0
|
|
37
|
+
} : {
|
|
38
|
+
appearance: "auto",
|
|
39
|
+
accentColor
|
|
40
|
+
},
|
|
41
|
+
...props.style
|
|
42
|
+
}
|
|
43
|
+
});
|
|
49
44
|
};
|
|
45
|
+
|
|
50
46
|
export { BubbleInput };
|
|
51
47
|
//# sourceMappingURL=BubbleInput.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"BubbleInput.js","names":[],"sources":["esm/BubbleInput.js"],"sourcesContent":["import React from \"react\";\nimport { usePrevious } from \"@tamagui/use-previous\";\nimport { jsx } from \"react/jsx-runtime\";\nconst BubbleInput = (props) => {\n const { checked, bubbles = true, control, isHidden, accentColor, ...inputProps } = props;\n const ref = React.useRef(null);\n const prevChecked = usePrevious(checked);\n React.useEffect(() => {\n const input = ref.current;\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(\n inputProto,\n \"checked\"\n );\n const setChecked = descriptor.set;\n if (prevChecked !== checked && setChecked) {\n const event = new Event(\"click\", { bubbles });\n setChecked.call(input, checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n return /* @__PURE__ */ jsx(\n \"input\",\n {\n type: \"radio\",\n defaultChecked: checked,\n ...inputProps,\n tabIndex: -1,\n ref,\n \"aria-hidden\": isHidden,\n style: {\n ...isHidden ? {\n // ...controlSize,\n position: \"absolute\",\n pointerEvents: \"none\",\n opacity: 0,\n margin: 0\n } : {\n appearance: \"auto\",\n accentColor\n },\n ...props.style\n }\n }\n );\n};\nexport {\n BubbleInput\n};\n//# sourceMappingURL=BubbleInput.js.map\n"],"mappings":";;;;;AAGA,MAAM,eAAe,UAAU;CAC7B,MAAM,EAAE,SAAS,UAAU,MAAM,SAAS,UAAU,aAAa,GAAG,eAAe;CACnF,MAAM,MAAM,MAAM,OAAO,IAAI;CAC7B,MAAM,cAAc,YAAY,OAAO;CACvC,MAAM,gBAAgB;EACpB,MAAM,QAAQ,IAAI;EAClB,MAAM,aAAa,OAAO,iBAAiB;EAC3C,MAAM,aAAa,OAAO,yBACxB,YACA,SACF;EACA,MAAM,aAAa,WAAW;EAC9B,IAAI,gBAAgB,WAAW,YAAY;GACzC,MAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;GAC5C,WAAW,KAAK,OAAO,OAAO;GAC9B,MAAM,cAAc,KAAK;EAC3B;CACF,GAAG;EAAC;EAAa;EAAS;CAAO,CAAC;CAClC,OAAuB,oBACrB,SACA;EACE,MAAM;EACN,gBAAgB;EAChB,GAAG;EACH,UAAU,CAAC;EACX;EACA,eAAe;EACf,OAAO;GACL,GAAG,WAAW;IAEZ,UAAU;IACV,eAAe;IACf,SAAS;IACT,QAAQ;GACV,IAAI;IACF,YAAY;IACZ;GACF;GACA,GAAG,MAAM;EACX;CACF,CACF;AACF"}
|
|
@@ -1,51 +1,47 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { usePrevious } from "@tamagui/use-previous";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
accentColor
|
|
45
|
-
}),
|
|
46
|
-
...props.style
|
|
47
|
-
}
|
|
48
|
-
});
|
|
4
|
+
|
|
5
|
+
var BubbleInput = function(props) {
|
|
6
|
+
var { checked, bubbles = true, control, isHidden, accentColor, ...inputProps } = props;
|
|
7
|
+
var ref = React.useRef(null);
|
|
8
|
+
var prevChecked = usePrevious(checked);
|
|
9
|
+
React.useEffect(function() {
|
|
10
|
+
var input = ref.current;
|
|
11
|
+
var inputProto = window.HTMLInputElement.prototype;
|
|
12
|
+
var descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked");
|
|
13
|
+
var setChecked = descriptor.set;
|
|
14
|
+
if (prevChecked !== checked && setChecked) {
|
|
15
|
+
var event = new Event("click", { bubbles });
|
|
16
|
+
setChecked.call(input, checked);
|
|
17
|
+
input.dispatchEvent(event);
|
|
18
|
+
}
|
|
19
|
+
}, [
|
|
20
|
+
prevChecked,
|
|
21
|
+
checked,
|
|
22
|
+
bubbles
|
|
23
|
+
]);
|
|
24
|
+
return /* @__PURE__ */ jsx("input", {
|
|
25
|
+
type: "radio",
|
|
26
|
+
defaultChecked: checked,
|
|
27
|
+
...inputProps,
|
|
28
|
+
tabIndex: -1,
|
|
29
|
+
ref,
|
|
30
|
+
"aria-hidden": isHidden,
|
|
31
|
+
style: {
|
|
32
|
+
...isHidden ? {
|
|
33
|
+
position: "absolute",
|
|
34
|
+
pointerEvents: "none",
|
|
35
|
+
opacity: 0,
|
|
36
|
+
margin: 0
|
|
37
|
+
} : {
|
|
38
|
+
appearance: "auto",
|
|
39
|
+
accentColor
|
|
40
|
+
},
|
|
41
|
+
...props.style
|
|
42
|
+
}
|
|
43
|
+
});
|
|
49
44
|
};
|
|
45
|
+
|
|
50
46
|
export { BubbleInput };
|
|
51
47
|
//# sourceMappingURL=BubbleInput.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"BubbleInput.native.js","names":[],"sources":["esm/BubbleInput.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport React from \"react\";\nimport { usePrevious } from \"@tamagui/use-previous\";\nvar BubbleInput = function(props) {\n var { checked, bubbles = true, control, isHidden, accentColor, ...inputProps } = props;\n var ref = React.useRef(null);\n var prevChecked = usePrevious(checked);\n React.useEffect(function() {\n var input = ref.current;\n var inputProto = window.HTMLInputElement.prototype;\n var descriptor = Object.getOwnPropertyDescriptor(inputProto, \"checked\");\n var setChecked = descriptor.set;\n if (prevChecked !== checked && setChecked) {\n var event = new Event(\"click\", {\n bubbles\n });\n setChecked.call(input, checked);\n input.dispatchEvent(event);\n }\n }, [\n prevChecked,\n checked,\n bubbles\n ]);\n return /* @__PURE__ */ _jsx(\"input\", {\n type: \"radio\",\n defaultChecked: checked,\n ...inputProps,\n tabIndex: -1,\n ref,\n \"aria-hidden\": isHidden,\n style: {\n ...isHidden ? {\n // ...controlSize,\n position: \"absolute\",\n pointerEvents: \"none\",\n opacity: 0,\n margin: 0\n } : {\n appearance: \"auto\",\n accentColor\n },\n ...props.style\n }\n });\n};\nexport {\n BubbleInput\n};\n//# sourceMappingURL=BubbleInput.js.map\n"],"mappings":";;;;;AAGA,IAAI,cAAc,SAAS,OAAO;CAChC,IAAI,EAAE,SAAS,UAAU,MAAM,SAAS,UAAU,aAAa,GAAG,eAAe;CACjF,IAAI,MAAM,MAAM,OAAO,IAAI;CAC3B,IAAI,cAAc,YAAY,OAAO;CACrC,MAAM,UAAU,WAAW;EACzB,IAAI,QAAQ,IAAI;EAChB,IAAI,aAAa,OAAO,iBAAiB;EACzC,IAAI,aAAa,OAAO,yBAAyB,YAAY,SAAS;EACtE,IAAI,aAAa,WAAW;EAC5B,IAAI,gBAAgB,WAAW,YAAY;GACzC,IAAI,QAAQ,IAAI,MAAM,SAAS,EAC7B,QACF,CAAC;GACD,WAAW,KAAK,OAAO,OAAO;GAC9B,MAAM,cAAc,KAAK;EAC3B;CACF,GAAG;EACD;EACA;EACA;CACF,CAAC;CACD,OAAuB,oBAAK,SAAS;EACnC,MAAM;EACN,gBAAgB;EAChB,GAAG;EACH,UAAU,CAAC;EACX;EACA,eAAe;EACf,OAAO;GACL,GAAG,WAAW;IAEZ,UAAU;IACV,eAAe;IACf,SAAS;IACT,QAAQ;GACV,IAAI;IACF,YAAY;IACZ;GACF;GACA,GAAG,MAAM;EACX;CACF,CAAC;AACH"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./useRadioGroup.mjs"
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from "./useRadioGroup.mjs"
|
|
2
|
+
|
|
3
|
+
export * from "./utils.mjs"
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./useRadioGroup.mjs"
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from "./useRadioGroup.mjs"
|
|
2
|
+
|
|
3
|
+
export * from "./utils.mjs"
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./useRadioGroup.native.js"
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from "./useRadioGroup.native.js"
|
|
2
|
+
|
|
3
|
+
export * from "./utils.native.js"
|
|
@@ -7,168 +7,138 @@ import { useContext, useEffect, useRef, useState } from "react";
|
|
|
7
7
|
import { BubbleInput } from "./BubbleInput.mjs";
|
|
8
8
|
import { getState } from "./utils.mjs";
|
|
9
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
|
|
10
11
|
function useRadioGroup(params) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
frameAttrs: {
|
|
39
|
-
role: "radiogroup",
|
|
40
|
-
"aria-orientation": orientation,
|
|
41
|
-
"data-disabled": disabled ? "" : void 0
|
|
42
|
-
},
|
|
43
|
-
rovingFocusGroupAttrs: {
|
|
44
|
-
orientation,
|
|
45
|
-
loop: true
|
|
46
|
-
}
|
|
47
|
-
};
|
|
12
|
+
const { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;
|
|
13
|
+
const [value, setValue] = useControllableState({
|
|
14
|
+
prop: valueProp,
|
|
15
|
+
defaultProp: defaultValue,
|
|
16
|
+
onChange: onValueChange
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
providerValue: {
|
|
20
|
+
value,
|
|
21
|
+
onChange: setValue,
|
|
22
|
+
required,
|
|
23
|
+
disabled,
|
|
24
|
+
name,
|
|
25
|
+
native,
|
|
26
|
+
accentColor
|
|
27
|
+
},
|
|
28
|
+
frameAttrs: {
|
|
29
|
+
role: "radiogroup",
|
|
30
|
+
"aria-orientation": orientation,
|
|
31
|
+
"data-disabled": disabled ? "" : void 0
|
|
32
|
+
},
|
|
33
|
+
rovingFocusGroupAttrs: {
|
|
34
|
+
orientation,
|
|
35
|
+
loop: true
|
|
36
|
+
}
|
|
37
|
+
};
|
|
48
38
|
}
|
|
49
|
-
const ARROW_KEYS = [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
142
|
-
if (!checked) onChange?.(value);
|
|
143
|
-
}
|
|
144
|
-
}),
|
|
145
|
-
onFocus: composeEventHandlers(onFocus, () => {
|
|
146
|
-
if (isArrowKeyPressedRef.current) ref.current?.click();
|
|
147
|
-
})
|
|
148
|
-
})
|
|
149
|
-
},
|
|
150
|
-
rovingFocusGroupAttrs: {
|
|
151
|
-
asChild: "except-style",
|
|
152
|
-
focusable: !isDisabled,
|
|
153
|
-
active: checked
|
|
154
|
-
}
|
|
155
|
-
};
|
|
39
|
+
const ARROW_KEYS = [
|
|
40
|
+
"ArrowUp",
|
|
41
|
+
"ArrowDown",
|
|
42
|
+
"ArrowLeft",
|
|
43
|
+
"ArrowRight"
|
|
44
|
+
];
|
|
45
|
+
const useRadioGroupItem = (params) => {
|
|
46
|
+
const { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;
|
|
47
|
+
const { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);
|
|
48
|
+
const [button, setButton] = useState(null);
|
|
49
|
+
const hasConsumerStoppedPropagationRef = useRef(false);
|
|
50
|
+
const ref = useRef(null);
|
|
51
|
+
const composedRefs = useComposedRefs(refProp, (node) => setButton(node), ref);
|
|
52
|
+
const isArrowKeyPressedRef = useRef(false);
|
|
53
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
54
|
+
const checked = groupValue === value;
|
|
55
|
+
const labelId = useLabelContext(button);
|
|
56
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (isWeb) {
|
|
59
|
+
const handleKeyDown = (event) => {
|
|
60
|
+
if (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;
|
|
61
|
+
};
|
|
62
|
+
const handleKeyUp = () => {
|
|
63
|
+
isArrowKeyPressedRef.current = false;
|
|
64
|
+
};
|
|
65
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
66
|
+
document.addEventListener("keyup", handleKeyUp);
|
|
67
|
+
return () => {
|
|
68
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
69
|
+
document.removeEventListener("keyup", handleKeyUp);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}, []);
|
|
73
|
+
const isDisabled = disabled || itemDisabled;
|
|
74
|
+
return {
|
|
75
|
+
providerValue: { checked },
|
|
76
|
+
checked,
|
|
77
|
+
isFormControl,
|
|
78
|
+
bubbleInput: /* @__PURE__ */ jsx(BubbleInput, {
|
|
79
|
+
isHidden: !native,
|
|
80
|
+
control: button,
|
|
81
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
82
|
+
name,
|
|
83
|
+
value,
|
|
84
|
+
checked,
|
|
85
|
+
required,
|
|
86
|
+
disabled: isDisabled,
|
|
87
|
+
...isWeb && native && {
|
|
88
|
+
accentColor,
|
|
89
|
+
id
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
native,
|
|
93
|
+
frameAttrs: {
|
|
94
|
+
"data-state": getState(checked),
|
|
95
|
+
"data-disabled": isDisabled ? "" : void 0,
|
|
96
|
+
role: "radio",
|
|
97
|
+
"aria-labelledby": labelledBy,
|
|
98
|
+
"aria-checked": checked,
|
|
99
|
+
"aria-required": required,
|
|
100
|
+
disabled: isDisabled,
|
|
101
|
+
ref: composedRefs,
|
|
102
|
+
...isWeb && {
|
|
103
|
+
type: "button",
|
|
104
|
+
value
|
|
105
|
+
},
|
|
106
|
+
id,
|
|
107
|
+
onPress: composeEventHandlers(onPress, (event) => {
|
|
108
|
+
if (!checked) onChange?.(value);
|
|
109
|
+
if (isFormControl) {
|
|
110
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
111
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
...isWeb && {
|
|
115
|
+
onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
116
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
117
|
+
if (!checked) onChange?.(value);
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
onFocus: composeEventHandlers(onFocus, () => {
|
|
121
|
+
if (isArrowKeyPressedRef.current) ref.current?.click();
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
rovingFocusGroupAttrs: {
|
|
126
|
+
asChild: "except-style",
|
|
127
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
128
|
+
active: checked
|
|
129
|
+
}
|
|
130
|
+
};
|
|
156
131
|
};
|
|
157
132
|
function useRadioGroupItemIndicator(params) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
checked,
|
|
168
|
-
"data-state": getState(checked),
|
|
169
|
-
"data-disabled": disabled ? "" : void 0,
|
|
170
|
-
...rest
|
|
171
|
-
};
|
|
133
|
+
const { radioGroupItemContext, disabled, ...rest } = params;
|
|
134
|
+
const { checked } = useContext(radioGroupItemContext);
|
|
135
|
+
return {
|
|
136
|
+
checked,
|
|
137
|
+
"data-state": getState(checked),
|
|
138
|
+
"data-disabled": disabled ? "" : void 0,
|
|
139
|
+
...rest
|
|
140
|
+
};
|
|
172
141
|
}
|
|
142
|
+
|
|
173
143
|
export { useRadioGroup, useRadioGroupItem, useRadioGroupItemIndicator };
|
|
174
144
|
//# sourceMappingURL=useRadioGroup.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useComposedRefs","isWeb","composeEventHandlers","useLabelContext","useControllableState","useContext","useEffect","useRef","useState","BubbleInput","getState","jsx","useRadioGroup","params","value","valueProp","onValueChange","defaultValue","required","disabled","name","native","accentColor","orientation","ref","setValue","prop","defaultProp","onChange","providerValue","frameAttrs","role","rovingFocusGroupAttrs","loop","ARROW_KEYS","useRadioGroupItem","radioGroupContext","labelledBy","ariaLabelledby","itemDisabled","refProp","id","onPress","onKeyDown","onFocus","groupValue","button","setButton","hasConsumerStoppedPropagationRef","composedRefs","node","isArrowKeyPressedRef","isFormControl","Boolean","closest","checked","labelId","handleKeyDown","event","includes","key","current","handleKeyUp","document","addEventListener","removeEventListener","isDisabled","bubbleInput","isHidden","control","bubbles","type","isPropagationStopped","stopPropagation","click","asChild","focusable","active","useRadioGroupItemIndicator","radioGroupItemContext","rest"],"sources":["useRadioGroup.mjs"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\nimport { jsx } from \"react/jsx-runtime\";\n\nfunction useRadioGroup(params) {\n\tconst { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tconst [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nconst ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nconst useRadioGroupItem = (params) => {\n\tconst { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tconst { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tconst [button, setButton] = useState(null);\n\tconst hasConsumerStoppedPropagationRef = useRef(false);\n\tconst ref = useRef(null);\n\tconst composedRefs = useComposedRefs(refProp, (node) => setButton(node), ref);\n\tconst isArrowKeyPressedRef = useRef(false);\n\tconst isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tconst checked = groupValue === value;\n\tconst labelId = useLabelContext(button);\n\tconst labelledBy = ariaLabelledby || labelId;\n\tuseEffect(() => {\n\t\tif (isWeb) {\n\t\t\tconst handleKeyDown = (event) => {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tconst handleKeyUp = () => {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tconst isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, (event) => {\n\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers(onKeyDown, (event) => {\n\t\t\t\t\tif (event.key === \"Enter\" || event.key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: composeEventHandlers(onFocus, () => {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) ref.current?.click();\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\tfocusable: !isDisabled,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tconst { radioGroupItemContext, disabled, ...rest } = params;\n\tconst { checked } = useContext(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": getState(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n\nexport { useRadioGroup, useRadioGroupItem, useRadioGroupItemIndicator };"],"mappings":"AAAA,SAASA,eAAe,QAAQ,uBAAuB;AACvD,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,SAASC,eAAe,QAAQ,gBAAgB;AAChD,SAASC,oBAAoB,QAAQ,iCAAiC;AACtE,SAASC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC/D,SAASC,WAAW,QAAQ,mBAAe;AAC3C,SAASC,QAAQ,QAAQ,aAAS;AAClC,SAASC,GAAG,QAAQ,mBAAmB;AAEvC,SAASC,aAAaA,CAACC,MAAM,EAAE;EAC9B,MAAM;IAAEC,KAAK,EAAEC,SAAS;IAAEC,aAAa;IAAEC,YAAY;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC,IAAI;IAAEC,MAAM;IAAEC,WAAW;IAAEC,WAAW;IAAEC;EAAI,CAAC,GAAGX,MAAM;EACjI,MAAM,CAACC,KAAK,EAAEW,QAAQ,CAAC,GAAGrB,oBAAoB,CAAC;IAC9CsB,IAAI,EAAEX,SAAS;IACfY,WAAW,EAAEV,YAAY;IACzBW,QAAQ,EAAEZ;EACX,CAAC,CAAC;EACF,OAAO;IACNa,aAAa,EAAE;MACdf,KAAK;MACLc,QAAQ,EAAEH,QAAQ;MAClBP,QAAQ;MACRC,QAAQ;MACRC,IAAI;MACJC,MAAM;MACNC;I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AM,EAAE;EAC3C,MAAM;IAAEkE,qBAAqB;IAAE5D,QAAQ;IAAE,GAAG6D;EAAK,CAAC,GAAGnE,MAAM;EAC3D,MAAM;IAAE0C;EAAQ,CAAC,GAAGlD,UAAU,CAAC0E,qBAAqB,CAAC;EACrD,OAAO;IACNxB,OAAO;IACP,YAAY,EAAE7C,QAAQ,CAAC6C,OAAO,CAAC;IAC/B,eAAe,EAAEpC,QAAQ,GAAG,EAAE,GAAG,KAAK,CAAC;IACvC,GAAG6D;EACJ,CAAC;AACF;AAEA,SAASpE,aAAa,EAAEuB,iBAAiB,EAAE2C,0BAA0B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useRadioGroup.js","names":[],"sources":["esm/useRadioGroup.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\nimport { jsx } from \"react/jsx-runtime\";\n\nfunction useRadioGroup(params) {\n\tconst { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tconst [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nconst ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nconst useRadioGroupItem = (params) => {\n\tconst { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tconst { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tconst [button, setButton] = useState(null);\n\tconst hasConsumerStoppedPropagationRef = useRef(false);\n\tconst ref = useRef(null);\n\tconst composedRefs = useComposedRefs(refProp, (node) => setButton(node), ref);\n\tconst isArrowKeyPressedRef = useRef(false);\n\tconst isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tconst checked = groupValue === value;\n\tconst labelId = useLabelContext(button);\n\tconst labelledBy = ariaLabelledby || labelId;\n\tuseEffect(() => {\n\t\tif (isWeb) {\n\t\t\tconst handleKeyDown = (event) => {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tconst handleKeyUp = () => {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tconst isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, (event) => {\n\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers(onKeyDown, (event) => {\n\t\t\t\t\tif (event.key === \"Enter\" || event.key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: composeEventHandlers(onFocus, () => {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) ref.current?.click();\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tconst { radioGroupItemContext, disabled, ...rest } = params;\n\tconst { checked } = useContext(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": getState(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n\nexport { useRadioGroup, useRadioGroupItem, useRadioGroupItemIndicator };"],"mappings":";;;;;;;;;;;AAUA,SAA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