@tamagui/radio-headless 1.0.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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/BubbleInput.cjs +82 -0
  3. package/dist/cjs/BubbleInput.js +65 -0
  4. package/dist/cjs/BubbleInput.js.map +6 -0
  5. package/dist/cjs/BubbleInput.native.js +86 -0
  6. package/dist/cjs/BubbleInput.native.js.map +1 -0
  7. package/dist/cjs/index.cjs +19 -0
  8. package/dist/cjs/index.js +16 -0
  9. package/dist/cjs/index.js.map +6 -0
  10. package/dist/cjs/index.native.js +22 -0
  11. package/dist/cjs/index.native.js.map +1 -0
  12. package/dist/cjs/useRadioGroup.cjs +191 -0
  13. package/dist/cjs/useRadioGroup.js +160 -0
  14. package/dist/cjs/useRadioGroup.js.map +6 -0
  15. package/dist/cjs/useRadioGroup.native.js +206 -0
  16. package/dist/cjs/useRadioGroup.native.js.map +1 -0
  17. package/dist/cjs/utils.cjs +28 -0
  18. package/dist/cjs/utils.js +23 -0
  19. package/dist/cjs/utils.js.map +6 -0
  20. package/dist/cjs/utils.native.js +31 -0
  21. package/dist/cjs/utils.native.js.map +1 -0
  22. package/dist/esm/BubbleInput.js +43 -0
  23. package/dist/esm/BubbleInput.js.map +6 -0
  24. package/dist/esm/BubbleInput.mjs +48 -0
  25. package/dist/esm/BubbleInput.mjs.map +1 -0
  26. package/dist/esm/BubbleInput.native.js +49 -0
  27. package/dist/esm/BubbleInput.native.js.map +1 -0
  28. package/dist/esm/index.js +3 -0
  29. package/dist/esm/index.js.map +6 -0
  30. package/dist/esm/index.mjs +3 -0
  31. package/dist/esm/index.mjs.map +1 -0
  32. package/dist/esm/index.native.js +3 -0
  33. package/dist/esm/index.native.js.map +1 -0
  34. package/dist/esm/useRadioGroup.js +153 -0
  35. package/dist/esm/useRadioGroup.js.map +6 -0
  36. package/dist/esm/useRadioGroup.mjs +165 -0
  37. package/dist/esm/useRadioGroup.mjs.map +1 -0
  38. package/dist/esm/useRadioGroup.native.js +178 -0
  39. package/dist/esm/useRadioGroup.native.js.map +1 -0
  40. package/dist/esm/utils.js +7 -0
  41. package/dist/esm/utils.js.map +6 -0
  42. package/dist/esm/utils.mjs +5 -0
  43. package/dist/esm/utils.mjs.map +1 -0
  44. package/dist/esm/utils.native.js +5 -0
  45. package/dist/esm/utils.native.js.map +1 -0
  46. package/dist/jsx/BubbleInput.js +43 -0
  47. package/dist/jsx/BubbleInput.js.map +6 -0
  48. package/dist/jsx/BubbleInput.mjs +48 -0
  49. package/dist/jsx/BubbleInput.mjs.map +1 -0
  50. package/dist/jsx/BubbleInput.native.js +86 -0
  51. package/dist/jsx/BubbleInput.native.js.map +1 -0
  52. package/dist/jsx/index.js +3 -0
  53. package/dist/jsx/index.js.map +6 -0
  54. package/dist/jsx/index.mjs +3 -0
  55. package/dist/jsx/index.mjs.map +1 -0
  56. package/dist/jsx/index.native.js +22 -0
  57. package/dist/jsx/index.native.js.map +1 -0
  58. package/dist/jsx/useRadioGroup.js +153 -0
  59. package/dist/jsx/useRadioGroup.js.map +6 -0
  60. package/dist/jsx/useRadioGroup.mjs +165 -0
  61. package/dist/jsx/useRadioGroup.mjs.map +1 -0
  62. package/dist/jsx/useRadioGroup.native.js +206 -0
  63. package/dist/jsx/useRadioGroup.native.js.map +1 -0
  64. package/dist/jsx/utils.js +7 -0
  65. package/dist/jsx/utils.js.map +6 -0
  66. package/dist/jsx/utils.mjs +5 -0
  67. package/dist/jsx/utils.mjs.map +1 -0
  68. package/dist/jsx/utils.native.js +31 -0
  69. package/dist/jsx/utils.native.js.map +1 -0
  70. package/package.json +61 -0
  71. package/src/BubbleInput.tsx +59 -0
  72. package/src/index.ts +2 -0
  73. package/src/useRadioGroup.tsx +260 -0
  74. package/src/utils.tsx +3 -0
  75. package/types/BubbleInput.d.ts +11 -0
  76. package/types/BubbleInput.d.ts.map +1 -0
  77. package/types/index.d.ts +3 -0
  78. package/types/index.d.ts.map +1 -0
  79. package/types/useRadioGroup.d.ts +100 -0
  80. package/types/useRadioGroup.d.ts.map +1 -0
  81. package/types/utils.d.ts +2 -0
  82. package/types/utils.d.ts.map +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Radix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,82 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var BubbleInput_exports = {};
33
+ __export(BubbleInput_exports, {
34
+ BubbleInput: () => BubbleInput
35
+ });
36
+ module.exports = __toCommonJS(BubbleInput_exports);
37
+ var import_react = __toESM(require("react"), 1),
38
+ import_use_previous = require("@tamagui/use-previous"),
39
+ import_jsx_runtime = require("react/jsx-runtime");
40
+ const BubbleInput = props => {
41
+ const {
42
+ checked,
43
+ bubbles = !0,
44
+ control,
45
+ isHidden,
46
+ accentColor,
47
+ ...inputProps
48
+ } = props,
49
+ ref = import_react.default.useRef(null),
50
+ prevChecked = (0, import_use_previous.usePrevious)(checked);
51
+ return import_react.default.useEffect(() => {
52
+ const input = ref.current,
53
+ inputProto = window.HTMLInputElement.prototype,
54
+ setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
55
+ if (prevChecked !== checked && setChecked) {
56
+ const event = new Event("click", {
57
+ bubbles
58
+ });
59
+ setChecked.call(input, checked), input.dispatchEvent(event);
60
+ }
61
+ }, [prevChecked, checked, bubbles]), /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
62
+ type: "radio",
63
+ defaultChecked: checked,
64
+ ...inputProps,
65
+ tabIndex: -1,
66
+ ref,
67
+ "aria-hidden": isHidden,
68
+ style: {
69
+ ...(isHidden ? {
70
+ // ...controlSize,
71
+ position: "absolute",
72
+ pointerEvents: "none",
73
+ opacity: 0,
74
+ margin: 0
75
+ } : {
76
+ appearance: "auto",
77
+ accentColor
78
+ }),
79
+ ...props.style
80
+ }
81
+ });
82
+ };
@@ -0,0 +1,65 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var BubbleInput_exports = {};
24
+ __export(BubbleInput_exports, {
25
+ BubbleInput: () => BubbleInput
26
+ });
27
+ module.exports = __toCommonJS(BubbleInput_exports);
28
+ var import_react = __toESM(require("react"), 1), import_use_previous = require("@tamagui/use-previous"), import_jsx_runtime = require("react/jsx-runtime");
29
+ const BubbleInput = (props) => {
30
+ const { checked, bubbles = !0, control, isHidden, accentColor, ...inputProps } = props, ref = import_react.default.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
31
+ return import_react.default.useEffect(() => {
32
+ const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
33
+ inputProto,
34
+ "checked"
35
+ ).set;
36
+ if (prevChecked !== checked && setChecked) {
37
+ const event = new Event("click", { bubbles });
38
+ setChecked.call(input, checked), input.dispatchEvent(event);
39
+ }
40
+ }, [prevChecked, checked, bubbles]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
41
+ "input",
42
+ {
43
+ type: "radio",
44
+ defaultChecked: checked,
45
+ ...inputProps,
46
+ tabIndex: -1,
47
+ ref,
48
+ "aria-hidden": isHidden,
49
+ style: {
50
+ ...isHidden ? {
51
+ // ...controlSize,
52
+ position: "absolute",
53
+ pointerEvents: "none",
54
+ opacity: 0,
55
+ margin: 0
56
+ } : {
57
+ appearance: "auto",
58
+ accentColor
59
+ },
60
+ ...props.style
61
+ }
62
+ }
63
+ );
64
+ };
65
+ //# sourceMappingURL=BubbleInput.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/BubbleInput.tsx"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,8BAClB,sBAA4B,kCAgCxB;AAtBG,MAAM,cAAc,CAAC,UAA4B;AACtD,QAAM,EAAE,SAAS,UAAU,IAAM,SAAS,UAAU,aAAa,GAAG,WAAW,IAAI,OAC7E,MAAM,aAAAA,QAAM,OAAyB,IAAI,GACzC,kBAAc,iCAAY,OAAO;AAGvC,sBAAAA,QAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI,SACZ,aAAa,OAAO,iBAAiB,WAKrC,aAJa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF,EAC8B;AAC9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC5C,iBAAW,KAAK,OAAO,OAAO,GAC9B,MAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC,GAGhC;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,gBAAgB;AAAA,MACf,GAAG;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA,eAAa;AAAA,MACb,OAAO;AAAA,QACL,GAAI,WACA;AAAA;AAAA,UAEE,UAAU;AAAA,UACV,eAAe;AAAA,UACf,SAAS;AAAA,UACT,QAAQ;AAAA,QACV,IACA;AAAA,UACE,YAAY;AAAA,UACZ;AAAA,QACF;AAAA,QAEJ,GAAG,MAAM;AAAA,MACX;AAAA;AAAA,EACF;AAEJ;",
5
+ "names": ["React"]
6
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
33
+ }), mod);
34
+ var BubbleInput_exports = {};
35
+ __export(BubbleInput_exports, {
36
+ BubbleInput: () => BubbleInput
37
+ });
38
+ module.exports = __toCommonJS(BubbleInput_exports);
39
+ var import_jsx_runtime = require("react/jsx-runtime"),
40
+ import_react = __toESM(require("react"), 1),
41
+ import_use_previous = require("@tamagui/use-previous"),
42
+ BubbleInput = function (props) {
43
+ var {
44
+ checked,
45
+ bubbles = !0,
46
+ control,
47
+ isHidden,
48
+ accentColor,
49
+ ...inputProps
50
+ } = props,
51
+ ref = import_react.default.useRef(null),
52
+ prevChecked = (0, import_use_previous.usePrevious)(checked);
53
+ return import_react.default.useEffect(function () {
54
+ var input = ref.current,
55
+ inputProto = window.HTMLInputElement.prototype,
56
+ descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"),
57
+ setChecked = descriptor.set;
58
+ if (prevChecked !== checked && setChecked) {
59
+ var event = new Event("click", {
60
+ bubbles
61
+ });
62
+ setChecked.call(input, checked), input.dispatchEvent(event);
63
+ }
64
+ }, [prevChecked, checked, bubbles]), /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
65
+ type: "radio",
66
+ defaultChecked: checked,
67
+ ...inputProps,
68
+ tabIndex: -1,
69
+ ref,
70
+ "aria-hidden": isHidden,
71
+ style: {
72
+ ...(isHidden ? {
73
+ // ...controlSize,
74
+ position: "absolute",
75
+ pointerEvents: "none",
76
+ opacity: 0,
77
+ margin: 0
78
+ } : {
79
+ appearance: "auto",
80
+ accentColor
81
+ }),
82
+ ...props.style
83
+ }
84
+ });
85
+ };
86
+ //# sourceMappingURL=BubbleInput.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","BubbleInput_exports","__export","BubbleInput","module","exports","import_jsx_runtime","require","import_react","__toESM","import_use_previous","props","checked","bubbles","control","isHidden","accentColor","inputProps","ref","default","useRef","prevChecked","usePrevious","useEffect","input","current","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","setChecked","set","event","Event","call","dispatchEvent","jsx","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","appearance"],"sources":["../../src/BubbleInput.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAkB,CAAAK,mBAClB;AAUO,IAAAK,kBAAqB,GAAAC,OAA4B;EAAAC,YAAA,GAAAC,OAAA,CAAAF,OAAA;EAAAG,mBAAA,GAAAH,OAAA;EAAAJ,WAAA,YAAAA,CAAAQ,KAAA;IACtD;QAAMC,OAAE;QAAAC,OAAS,KAAU;QAAAC,OAAM;QAAAC,QAAS;QAAAC,WAAU;QAAA,GAAaC;MAAG,IAAWN,KAAI;MAAAO,GAC7E,GAAAV,YAAM,CAAAW,OAAA,CAAAC,MAAM,KAAyB;MAAIC,WACzC,OAAAX,mBAAc,CAAAY,WAAA,EAAAV,OAAY;IAGhC,OAAAJ,YAAA,CAAAW,OAAA,CAAMI,SAAA,CAAU,YAAM;MACpB,IAAAC,KAAM,GAAAN,GAAQ,CAAAO,OAAI;QAAAC,UACZ,GAAAC,MAAa,CAAAC,gBAAO,CAAAC,SAAiB;QAAAC,UAKrC,GAAAC,MAJa,CAAAC,wBAAO,CAAAN,UAAA;QAAAO,UAAA,GAAAH,UAAA,CAAAI,GAAA;MAAA,IACxBb,WAAA,KAAAT,OAAA,IAAAqB,UAAA;QACA,IAAAE,KAAA,OAAAC,KAAA;UAE4BvB;QAC9B,EAAI;QACFoB,UAAM,CAAAI,IAAQ,CAAAb,KAAI,EAAAZ,OAAM,GAASY,KAAE,CAAAc,aAAS,CAAAH,KAAA;MAC5C;IACyB,GAC3B,CACFd,WAAI,EAGDT,OAAA,EAAAC,OAAA,IACC,eAAK,IAAAP,kBAAA,CAAAiC,GAAA;MAAAC,IACL;MAAgBC,cACZ,EAAA7B,OAAA;MAAA,GACJK,UAAU;MAAAyB,QACV;MAAAxB,GACA;MAAa,aACN,EAAAH,QAAA;MAAA4B,KACL,EAAI;QACA,IAAA5B,QAAA;UAAA;UAEY6B,QACV,YAAe;UAAAC,aACN;UAAAC,OACT,GAAQ;UACVC,MACA;QAAA,IACE;UAAYC,UACZ;UACFhC;QAAA;QAGN,GAAAL,KAAA,CAAAgC;MAAA;IACF;EAEJ","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
+ get: () => from[key],
8
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
+ });
10
+ return to;
11
+ },
12
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
13
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
14
+ value: !0
15
+ }), mod);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./useRadioGroup.cjs"), module.exports);
19
+ __reExport(index_exports, require("./utils.cjs"), module.exports);
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function")
7
+ for (let key of __getOwnPropNames(from))
8
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
+ return to;
10
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
+ var index_exports = {};
13
+ module.exports = __toCommonJS(index_exports);
14
+ __reExport(index_exports, require("./useRadioGroup"), module.exports);
15
+ __reExport(index_exports, require("./utils"), module.exports);
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,4BAAd;AACA,0BAAc,oBADd;",
5
+ "names": []
6
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
9
+ get: () => from[key],
10
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
11
+ });
12
+ return to;
13
+ },
14
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
+ value: !0
17
+ }), mod);
18
+ var index_exports = {};
19
+ module.exports = __toCommonJS(index_exports);
20
+ __reExport(index_exports, require("./useRadioGroup.native.js"), module.exports);
21
+ __reExport(index_exports, require("./utils.native.js"), module.exports);
22
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,4BADd,GAAAH,MAAA,CAAAC,OAAA","ignoreList":[]}
@@ -0,0 +1,191 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
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, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var useRadioGroup_exports = {};
22
+ __export(useRadioGroup_exports, {
23
+ useRadioGroup: () => useRadioGroup,
24
+ useRadioGroupItem: () => useRadioGroupItem,
25
+ useRadioGroupItemIndicator: () => useRadioGroupItemIndicator
26
+ });
27
+ 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");
38
+ function useRadioGroup(params) {
39
+ 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
+ });
56
+ return {
57
+ providerValue: {
58
+ value,
59
+ onChange: setValue,
60
+ required,
61
+ disabled,
62
+ name,
63
+ native,
64
+ accentColor
65
+ },
66
+ frameAttrs: {
67
+ role: "radiogroup",
68
+ "aria-orientation": orientation,
69
+ "data-disabled": disabled ? "" : void 0
70
+ },
71
+ rovingFocusGroupAttrs: {
72
+ orientation,
73
+ loop: !0
74
+ }
75
+ };
76
+ }
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
+ },
126
+ 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
+ })
141
+ }),
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());
159
+ }),
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
+ })
167
+ })
168
+ },
169
+ rovingFocusGroupAttrs: {
170
+ asChild: "except-style",
171
+ focusable: !isDisabled,
172
+ active: checked
173
+ }
174
+ };
175
+ };
176
+ function useRadioGroupItemIndicator(params) {
177
+ const {
178
+ radioGroupItemContext,
179
+ disabled,
180
+ ...rest
181
+ } = params,
182
+ {
183
+ checked
184
+ } = (0, import_react.useContext)(radioGroupItemContext);
185
+ return {
186
+ checked,
187
+ "data-state": (0, import_utils.getState)(checked),
188
+ "data-disabled": disabled ? "" : void 0,
189
+ ...rest
190
+ };
191
+ }