@tamagui/switch 2.7.7 → 3.0.0-beta.1091.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 (97) hide show
  1. package/dist/cjs/StyledContext.cjs +18 -23
  2. package/dist/cjs/StyledContext.native.cjs +32 -0
  3. package/dist/cjs/StyledContext.native.js +18 -22
  4. package/dist/cjs/StyledContext.native.js.map +1 -1
  5. package/dist/cjs/Switch.cjs +139 -86
  6. package/dist/cjs/Switch.native.cjs +162 -0
  7. package/dist/cjs/Switch.native.js +146 -90
  8. package/dist/cjs/Switch.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +13 -25
  10. package/dist/cjs/index.native.cjs +30 -0
  11. package/dist/cjs/index.native.js +14 -25
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/types.cjs +9 -11
  14. package/dist/cjs/types.native.cjs +18 -0
  15. package/dist/cjs/types.native.js +9 -10
  16. package/dist/cjs/types.native.js.map +1 -1
  17. package/dist/cjs/useSwitchNative.cjs +15 -19
  18. package/dist/cjs/useSwitchNative.native.cjs +64 -0
  19. package/dist/cjs/useSwitchNative.native.js +43 -54
  20. package/dist/cjs/useSwitchNative.native.js.map +1 -1
  21. package/dist/esm/StyledContext.mjs +6 -5
  22. package/dist/esm/StyledContext.mjs.map +1 -1
  23. package/dist/esm/StyledContext.native.js +6 -5
  24. package/dist/esm/StyledContext.native.js.map +1 -1
  25. package/dist/esm/Switch.mjs +119 -71
  26. package/dist/esm/Switch.mjs.map +1 -1
  27. package/dist/esm/Switch.native.js +126 -76
  28. package/dist/esm/Switch.native.js.map +1 -1
  29. package/dist/esm/index.js +8 -12
  30. package/dist/esm/index.mjs +8 -12
  31. package/dist/esm/index.native.js +8 -12
  32. package/dist/esm/types.mjs +0 -2
  33. package/dist/esm/types.native.js +0 -2
  34. package/dist/esm/useSwitchNative.mjs +2 -1
  35. package/dist/esm/useSwitchNative.mjs.map +1 -1
  36. package/dist/esm/useSwitchNative.native.js +30 -31
  37. package/dist/esm/useSwitchNative.native.js.map +1 -1
  38. package/dist/jsx/StyledContext.mjs +6 -5
  39. package/dist/jsx/StyledContext.mjs.map +1 -1
  40. package/dist/jsx/StyledContext.native.cjs +32 -0
  41. package/dist/jsx/StyledContext.native.js +18 -22
  42. package/dist/jsx/StyledContext.native.js.map +1 -1
  43. package/dist/jsx/Switch.mjs +119 -71
  44. package/dist/jsx/Switch.mjs.map +1 -1
  45. package/dist/jsx/Switch.native.cjs +162 -0
  46. package/dist/jsx/Switch.native.js +146 -90
  47. package/dist/jsx/Switch.native.js.map +1 -1
  48. package/dist/jsx/index.js +8 -12
  49. package/dist/jsx/index.mjs +8 -12
  50. package/dist/jsx/index.native.cjs +30 -0
  51. package/dist/jsx/index.native.js +14 -25
  52. package/dist/jsx/index.native.js.map +1 -1
  53. package/dist/jsx/types.mjs +0 -2
  54. package/dist/jsx/types.native.cjs +18 -0
  55. package/dist/jsx/types.native.js +9 -10
  56. package/dist/jsx/types.native.js.map +1 -1
  57. package/dist/jsx/useSwitchNative.mjs +2 -1
  58. package/dist/jsx/useSwitchNative.mjs.map +1 -1
  59. package/dist/jsx/useSwitchNative.native.cjs +64 -0
  60. package/dist/jsx/useSwitchNative.native.js +43 -54
  61. package/dist/jsx/useSwitchNative.native.js.map +1 -1
  62. package/package.json +10 -15
  63. package/src/StyledContext.tsx +1 -3
  64. package/src/Switch.tsx +190 -89
  65. package/src/index.ts +0 -20
  66. package/src/types.ts +7 -6
  67. package/types/StyledContext.d.ts +2 -3
  68. package/types/StyledContext.d.ts.map +1 -1
  69. package/types/Switch.d.ts +209 -37
  70. package/types/Switch.d.ts.map +1 -1
  71. package/types/index.d.ts +0 -146
  72. package/types/index.d.ts.map +1 -1
  73. package/types/types.d.ts +4 -5
  74. package/types/types.d.ts.map +1 -1
  75. package/dist/cjs/createSwitch.cjs +0 -186
  76. package/dist/cjs/createSwitch.native.js +0 -194
  77. package/dist/cjs/createSwitch.native.js.map +0 -1
  78. package/dist/esm/createSwitch.mjs +0 -150
  79. package/dist/esm/createSwitch.mjs.map +0 -1
  80. package/dist/esm/createSwitch.native.js +0 -155
  81. package/dist/esm/createSwitch.native.js.map +0 -1
  82. package/dist/esm/index.js.map +0 -1
  83. package/dist/esm/index.mjs.map +0 -1
  84. package/dist/esm/index.native.js.map +0 -1
  85. package/dist/esm/types.mjs.map +0 -1
  86. package/dist/esm/types.native.js.map +0 -1
  87. package/dist/jsx/createSwitch.mjs +0 -150
  88. package/dist/jsx/createSwitch.mjs.map +0 -1
  89. package/dist/jsx/createSwitch.native.js +0 -194
  90. package/dist/jsx/createSwitch.native.js.map +0 -1
  91. package/dist/jsx/index.js.map +0 -1
  92. package/dist/jsx/index.mjs.map +0 -1
  93. package/dist/jsx/types.mjs.map +0 -1
  94. package/src/Switch.draggable-tmp +0 -340
  95. package/src/createSwitch.tsx +0 -201
  96. package/types/createSwitch.d.ts +0 -141
  97. package/types/createSwitch.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"types.native.js","names":[],"sources":["jsx/types.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar types_exports = {};\nmodule.exports = __toCommonJS(types_exports);\n//# sourceMappingURL=types.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,gBAAgB,CAAC;AACrB,OAAO,UAAU,aAAa,aAAa"}
@@ -1,5 +1,6 @@
1
1
  function useSwitchNative(_props) {
2
- return null;
2
+ return null;
3
3
  }
4
+
4
5
  export { useSwitchNative };
5
6
  //# sourceMappingURL=useSwitchNative.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["useSwitchNative","_props"],"sources":["../../src/useSwitchNative.tsx"],"sourcesContent":[null],"mappings":"AAKO,SAASA,gBAAgBC,MAAA,EAAsD;EACpF,OAAO;AACT","ignoreList":[]}
1
+ {"version":3,"file":"useSwitchNative.js","names":[],"sources":["jsx/useSwitchNative.js"],"sourcesContent":["function useSwitchNative(_props) {\n return null;\n}\nexport {\n useSwitchNative\n};\n//# sourceMappingURL=useSwitchNative.js.map\n"],"mappings":";AAAA,SAAS,gBAAgB,QAAQ;CAC/B,OAAO;AACT"}
@@ -0,0 +1,64 @@
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
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var useSwitchNative_native_exports = {};
30
+ __export(useSwitchNative_native_exports, { useSwitchNative: () => useSwitchNative });
31
+ module.exports = __toCommonJS(useSwitchNative_native_exports);
32
+ var import_jsx_runtime = require("react/jsx-runtime");
33
+ var import_core = require("@tamagui/core");
34
+ var import_focusable = require("@tamagui/focusable");
35
+ var React = __toESM(require("react"), 1);
36
+ var import_react_native = require("react-native");
37
+ function useSwitchNative(props) {
38
+ var { id, disabled, native, nativeProps, checked, setChecked } = props;
39
+ React.useEffect(function() {
40
+ if (!id) return;
41
+ if (disabled) return;
42
+ return (0, import_focusable.registerFocusable)(id, {
43
+ focusAndSelect: function() {
44
+ setChecked(function(value) {
45
+ return !value;
46
+ });
47
+ },
48
+ focus: function() {}
49
+ });
50
+ }, [
51
+ id,
52
+ disabled,
53
+ setChecked
54
+ ]);
55
+ var renderNative = (0, import_core.shouldRenderNativePlatform)(native);
56
+ if (renderNative === "android" || renderNative === "ios") {
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, {
58
+ value: checked,
59
+ onValueChange: setChecked,
60
+ ...nativeProps
61
+ });
62
+ }
63
+ return null;
64
+ }
@@ -7,36 +7,27 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
14
  };
15
15
  var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
- get: () => from[key],
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- return to;
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
23
  };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
- value: mod,
31
- enumerable: true
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
32
27
  }) : target, mod));
33
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
- value: true
35
- }), mod);
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
29
  var useSwitchNative_native_exports = {};
37
- __export(useSwitchNative_native_exports, {
38
- useSwitchNative: () => useSwitchNative
39
- });
30
+ __export(useSwitchNative_native_exports, { useSwitchNative: () => useSwitchNative });
40
31
  module.exports = __toCommonJS(useSwitchNative_native_exports);
41
32
  var import_jsx_runtime = require("react/jsx-runtime");
42
33
  var import_core = require("@tamagui/core");
@@ -44,34 +35,32 @@ var import_focusable = require("@tamagui/focusable");
44
35
  var React = __toESM(require("react"), 1);
45
36
  var import_react_native = require("react-native");
46
37
  function useSwitchNative(props) {
47
- var {
48
- id,
49
- disabled,
50
- native,
51
- nativeProps,
52
- checked,
53
- setChecked
54
- } = props;
55
- React.useEffect(function () {
56
- if (!id) return;
57
- if (disabled) return;
58
- return (0, import_focusable.registerFocusable)(id, {
59
- focusAndSelect: function () {
60
- setChecked(function (value) {
61
- return !value;
62
- });
63
- },
64
- focus: function () {}
65
- });
66
- }, [id, disabled, setChecked]);
67
- var renderNative = (0, import_core.shouldRenderNativePlatform)(native);
68
- if (renderNative === "android" || renderNative === "ios") {
69
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native.Switch, {
70
- value: checked,
71
- onValueChange: setChecked,
72
- ...nativeProps
73
- });
74
- }
75
- return null;
38
+ var { id, disabled, native, nativeProps, checked, setChecked } = props;
39
+ React.useEffect(function() {
40
+ if (!id) return;
41
+ if (disabled) return;
42
+ return (0, import_focusable.registerFocusable)(id, {
43
+ focusAndSelect: function() {
44
+ setChecked(function(value) {
45
+ return !value;
46
+ });
47
+ },
48
+ focus: function() {}
49
+ });
50
+ }, [
51
+ id,
52
+ disabled,
53
+ setChecked
54
+ ]);
55
+ var renderNative = (0, import_core.shouldRenderNativePlatform)(native);
56
+ if (renderNative === "android" || renderNative === "ios") {
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, {
58
+ value: checked,
59
+ onValueChange: setChecked,
60
+ ...nativeProps
61
+ });
62
+ }
63
+ return null;
76
64
  }
65
+
77
66
  //# sourceMappingURL=useSwitchNative.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useSwitchNative_native_exports","__export","useSwitchNative","module","exports","__toCommonJS","import_jsx_runtime","require","import_core","import_focusable","React","__toESM","import_react_native","props","id","disabled","native","nativeProps","checked","setChecked","useEffect","registerFocusable","focusAndSelect","value","focus","renderNative","shouldRenderNativePlatform","jsx","Switch","onValueChange"],"sources":["../../src/useSwitchNative.native.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,8BAAA;AAAAC,QAAA,CAAAD,8BAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAL,8BAAA;AAAA,IAAAM,kBAAA,GAA4BC,OAAA;AAC5B,IAAAC,WAAA,GAA2CD,OAAA;AAC3C,IAAAE,gBAAA,GAAkCF,OAAA;AAClC,IAAAG,KAAA,GAAuBC,OAAA,CAAAJ,OAAA;AACvB,IAAAK,mBAAA,GAAuCL,OAAA;AAG5B,SAASL,gBAAgBW,KAAA,EAAO;EACvC,IAAI;IAAEC,EAAA;IAAIC,QAAA;IAAUC,MAAA;IAAQC,WAAA;IAAaC,OAAA;IAASC;EAAW,IAAIN,KAAA;EACjEH,KAAA,CAAMU,SAAA,CAAU,YAAW;IACvB,IAAI,CAACN,EAAA,EAAI;IACT,IAAIC,QAAA,EAAU;IACd,WAAON,gBAAA,CAAAY,iBAAA,EAAkBP,EAAA,EAAI;MACzBQ,cAAA,EAAgB,SAAAA,CAAA,EAAW;QACvBH,UAAA,CAAW,UAASI,KAAA,EAAO;UACvB,OAAO,CAACA,KAAA;QACZ,CAAC;MACL;MACAC,KAAA,EAAO,SAAAA,CAAA,EAAW,CAAC;IACvB,CAAC;EACL,GAAG,CACCV,EAAA,EACAC,QAAA,EACAI,UAAA,CACH;EACD,IAAIM,YAAA,OAAejB,WAAA,CAAAkB,0BAAA,EAA2BV,MAAM;EACpD,IAAIS,YAAA,KAAiB,aAAaA,YAAA,KAAiB,OAAO;IACtD,OAAqB,mBAAAnB,kBAAA,CAAAqB,GAAA,EAAKf,mBAAA,CAAAgB,MAAA,EAAc;MACpCL,KAAA,EAAOL,OAAA;MACPW,aAAA,EAAeV,UAAA;MACf,GAAGF;IACP,CAAC;EACL;EACA,OAAO;AACX","ignoreList":[]}
1
+ {"version":3,"file":"useSwitchNative.native.js","names":[],"sources":["jsx/useSwitchNative.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useSwitchNative_native_exports = {};\n__export(useSwitchNative_native_exports, {\n useSwitchNative: () => useSwitchNative\n});\nmodule.exports = __toCommonJS(useSwitchNative_native_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_core = require(\"@tamagui/core\");\nvar import_focusable = require(\"@tamagui/focusable\");\nvar React = __toESM(require(\"react\"), 1);\nvar import_react_native = require(\"react-native\");\nfunction useSwitchNative(props) {\n var { id, disabled, native, nativeProps, checked, setChecked } = props;\n React.useEffect(function() {\n if (!id) return;\n if (disabled) return;\n return (0, import_focusable.registerFocusable)(id, {\n focusAndSelect: function() {\n setChecked(function(value) {\n return !value;\n });\n },\n focus: function() {\n }\n });\n }, [\n id,\n disabled,\n setChecked\n ]);\n var renderNative = (0, import_core.shouldRenderNativePlatform)(native);\n if (renderNative === \"android\" || renderNative === \"ios\") {\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, {\n value: checked,\n onValueChange: setChecked,\n ...nativeProps\n });\n }\n return null;\n}\n//# sourceMappingURL=useSwitchNative.native.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,iCAAiC,CAAC;AACtC,SAAS,gCAAgC,EACvC,uBAAuB,gBACzB,CAAC;AACD,OAAO,UAAU,aAAa,8BAA8B;AAC5D,IAAI,qBAAqB,QAAQ,mBAAmB;AACpD,IAAI,cAAc,QAAQ,eAAe;AACzC,IAAI,mBAAmB,QAAQ,oBAAoB;AACnD,IAAI,QAAQ,QAAQ,QAAQ,OAAO,GAAG,CAAC;AACvC,IAAI,sBAAsB,QAAQ,cAAc;AAChD,SAAS,gBAAgB,OAAO;CAC9B,IAAI,EAAE,IAAI,UAAU,QAAQ,aAAa,SAAS,eAAe;CACjE,MAAM,UAAU,WAAW;EACzB,IAAI,CAAC,IAAI;EACT,IAAI,UAAU;EACd,QAAQ,GAAG,iBAAiB,kBAAiB,CAAE,IAAI;GACjD,gBAAgB,WAAW;IACzB,WAAW,SAAS,OAAO;KACzB,OAAO,CAAC;IACV,CAAC;GACH;GACA,OAAO,WAAW,CAClB;EACF,CAAC;CACH,GAAG;EACD;EACA;EACA;CACF,CAAC;CACD,IAAI,gBAAgB,GAAG,YAAY,2BAA0B,CAAE,MAAM;CACrE,IAAI,iBAAiB,aAAa,iBAAiB,OAAO;EACxD,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,oBAAoB,QAAQ;GAC7E,OAAO;GACP,eAAe;GACf,GAAG;EACL,CAAC;CACH;CACA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@tamagui/switch",
3
- "version": "2.7.7",
3
+ "version": "3.0.0-beta.1091.1",
4
+ "license": "MIT",
4
5
  "source": "src/index.ts",
5
6
  "files": [
6
7
  "src",
@@ -34,22 +35,16 @@
34
35
  "clean:build": "tamagui-build clean:build"
35
36
  },
36
37
  "dependencies": {
37
- "@tamagui/compose-refs": "2.7.7",
38
- "@tamagui/constants": "2.7.7",
39
- "@tamagui/core": "2.7.7",
40
- "@tamagui/focusable": "2.7.7",
41
- "@tamagui/get-token": "2.7.7",
42
- "@tamagui/helpers": "2.7.7",
43
- "@tamagui/label": "2.7.7",
44
- "@tamagui/stacks": "2.7.7",
45
- "@tamagui/switch-headless": "2.7.7",
46
- "@tamagui/use-controllable-state": "2.7.7",
47
- "@tamagui/use-previous": "2.7.7"
38
+ "@tamagui/core": "3.0.0-beta.1091.1",
39
+ "@tamagui/focusable": "3.0.0-beta.1091.1",
40
+ "@tamagui/react-native-types": "3.0.0-beta.1091.1",
41
+ "@tamagui/switch-headless": "3.0.0-beta.1091.1",
42
+ "@tamagui/use-controllable-state": "3.0.0-beta.1091.1"
48
43
  },
49
44
  "devDependencies": {
50
- "@tamagui/build": "2.7.7",
51
- "react": ">=19",
52
- "react-native": "0.83.2"
45
+ "@tamagui/build": "3.0.0-beta.1091.1",
46
+ "react": "19.2.3",
47
+ "react-native": "0.86.2"
53
48
  },
54
49
  "peerDependencies": {
55
50
  "react": ">=19"
@@ -5,12 +5,10 @@ export const SwitchStyledContext = createStyledContext<{
5
5
  active?: boolean
6
6
  disabled?: boolean
7
7
  frameWidth?: number
8
- size?: SizeTokens
9
- unstyled?: boolean
8
+ size?: SizeTokens | number | true
10
9
  }>({
11
10
  active: false,
12
11
  disabled: false,
13
12
  frameWidth: undefined,
14
13
  size: undefined,
15
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
16
14
  })
package/src/Switch.tsx CHANGED
@@ -1,91 +1,192 @@
1
- import type { SizeTokens } from '@tamagui/core'
2
- import { getVariableValue, styled } from '@tamagui/core'
3
- import { getSize } from '@tamagui/get-token'
4
- import { YStack } from '@tamagui/stacks'
5
-
6
- export const SwitchThumb = styled(
7
- YStack,
8
- {
9
- name: 'SwitchThumb',
10
-
11
- variants: {
12
- unstyled: {
13
- false: {
14
- size: '$true',
15
- backgroundColor: '$background',
16
- borderRadius: 1000,
17
- },
18
- },
19
-
20
- size: {
21
- '...size': (val) => {
22
- const size = getSwitchHeight(val)
23
- return {
24
- height: size,
25
- width: size,
26
- }
27
- },
28
- },
29
- } as const,
30
-
31
- defaultVariants: {
32
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
33
- },
34
- },
35
- {
36
- accept: {
37
- activeStyle: 'style',
38
- } as const,
1
+ import type { GetProps } from '@tamagui/core'
2
+ import {
3
+ composeEventHandlers,
4
+ createStyledHOC,
5
+ getVariableValue,
6
+ isWeb,
7
+ styled,
8
+ Theme,
9
+ type ThemeProps,
10
+ View,
11
+ withStaticProperties,
12
+ } from '@tamagui/core'
13
+ import { useSwitch } from '@tamagui/switch-headless'
14
+ import { useControllableState } from '@tamagui/use-controllable-state'
15
+ import * as React from 'react'
16
+ import type { LayoutChangeEvent } from '@tamagui/react-native-types'
17
+ import { SwitchStyledContext } from './StyledContext'
18
+ import type {
19
+ SwitchComponent as SwitchFrameComponent,
20
+ SwitchProps,
21
+ SwitchThumbComponent as SwitchThumbFrameComponent,
22
+ SwitchThumbProps,
23
+ } from './types'
24
+ import { useSwitchNative } from './useSwitchNative'
25
+
26
+ export const SwitchThumbFrame = styled(View, {
27
+ displayName: 'SwitchThumb',
28
+ context: SwitchStyledContext,
29
+ })
30
+
31
+ export const SwitchFrame = styled(View, {
32
+ displayName: 'Switch',
33
+ context: SwitchStyledContext,
34
+ render: 'button',
35
+ tabIndex: 0,
36
+ })
37
+
38
+ export function createSwitch(createProps: {
39
+ Frame?: SwitchFrameComponent
40
+ Thumb?: SwitchThumbFrameComponent
41
+ componentThemes?: {
42
+ frame?: ThemeProps['name']
43
+ thumb?: ThemeProps['name']
39
44
  }
40
- )
41
-
42
- const getSwitchHeight = (val: SizeTokens) =>
43
- Math.round(getVariableValue(getSize(val)) * 0.65)
44
-
45
- const getSwitchWidth = (val: SizeTokens) => getSwitchHeight(val) * 2
46
-
47
- export const SwitchFrame = styled(
48
- YStack,
49
- {
50
- name: 'Switch',
51
- render: 'button',
52
- tabIndex: 0,
53
-
54
- variants: {
55
- unstyled: {
56
- false: {
57
- borderRadius: 1000,
58
- backgroundColor: '$background',
59
-
60
- focusVisibleStyle: {
61
- outlineColor: '$outlineColor',
62
- outlineStyle: 'solid',
63
- outlineWidth: 2,
64
- },
65
- },
66
- },
67
-
68
- size: {
69
- '...size': (val, { props }) => {
70
- if (props['unstyled']) return
71
- const height = getSwitchHeight(val)
72
- const width = getSwitchWidth(val)
73
- return {
74
- height,
75
- minHeight: height,
76
- width,
77
- }
78
- },
79
- },
80
- } as const,
81
-
82
- defaultVariants: {
83
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
45
+ }) {
46
+ const Frame = (createProps.Frame ?? SwitchFrame) as typeof SwitchFrame
47
+ const Thumb = (createProps.Thumb ?? SwitchThumbFrame) as typeof SwitchThumbFrame
48
+
49
+ Frame.staticConfig.context = SwitchStyledContext
50
+ Thumb.staticConfig.context = SwitchStyledContext
51
+
52
+ const SwitchThumbComponent = createStyledHOC(
53
+ Thumb,
54
+ function SwitchThumb(
55
+ props: Omit<GetProps<typeof Thumb>, keyof SwitchThumbProps> & SwitchThumbProps,
56
+ forwardedRef
57
+ ) {
58
+ const { size: sizeProp, activeStyle, theme, ...thumbProps } = props
59
+ const styledContext = SwitchStyledContext.useStyledContext()
60
+ const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext
61
+ const size = sizeProp ?? sizeContext ?? true
62
+ const initialChecked = React.useRef(active).current
63
+ const initialWidth = getVariableValue(props.width, 'size')
64
+ const [thumbWidth, setThumbWidth] = React.useState(
65
+ typeof initialWidth === 'number' ? initialWidth : 0
66
+ )
67
+ const distance = frameWidth - thumbWidth
68
+ const x = initialChecked ? (active ? 0 : -distance) : active ? distance : 0
69
+
70
+ const thumb = (
71
+ <Thumb
72
+ ref={forwardedRef}
73
+ size={size}
74
+ alignSelf={initialChecked ? 'flex-end' : 'flex-start'}
75
+ x={x}
76
+ onLayout={composeEventHandlers(props.onLayout, (event) => {
77
+ setThumbWidth(event.nativeEvent.layout.width)
78
+ })}
79
+ disabled={disabled}
80
+ {...thumbProps}
81
+ {...(active && activeStyle)}
82
+ />
83
+ )
84
+
85
+ const themeName = theme ?? createProps.componentThemes?.thumb
86
+ return themeName ? <Theme name={themeName}>{thumb}</Theme> : thumb
87
+ }
88
+ )
89
+
90
+ const SwitchComponent = createStyledHOC(
91
+ Frame,
92
+ function Switch(_props: SwitchProps, forwardedRef) {
93
+ const {
94
+ native,
95
+ nativeProps,
96
+ checked: checkedProp,
97
+ defaultChecked,
98
+ onCheckedChange,
99
+ activeStyle,
100
+ activeTheme,
101
+ theme,
102
+ ...props
103
+ } = _props
104
+ const [checked, setChecked] = useControllableState({
105
+ prop: checkedProp,
106
+ defaultProp: defaultChecked || false,
107
+ onChange: onCheckedChange,
108
+ transition: true,
109
+ })
110
+ const styledContext = React.useContext(SwitchStyledContext.context)
111
+ const [frameWidth, setFrameInnerWidth] = React.useState(0)
112
+ const { switchProps, bubbleInput, switchRef } = useSwitch(
113
+ props as any,
114
+ [checked, setChecked],
115
+ // @ts-ignore TODO tamagui react 19 type error
116
+ forwardedRef
117
+ )
118
+ const nativeSwitch = useSwitchNative({
119
+ id: props.id,
120
+ disabled: props.disabled,
121
+ native,
122
+ nativeProps,
123
+ checked,
124
+ setChecked,
125
+ })
126
+
127
+ if (nativeSwitch) {
128
+ return nativeSwitch
129
+ }
130
+
131
+ const disabled = props.disabled
132
+ const size = styledContext.size ?? props.size ?? true
133
+
134
+ const handleLayout = (event: LayoutChangeEvent) => {
135
+ const next = event.nativeEvent.layout.width
136
+ if (next !== frameWidth) {
137
+ setFrameInnerWidth(next)
138
+ }
139
+ }
140
+
141
+ const frame = (
142
+ <Frame
143
+ ref={switchRef}
144
+ render="button"
145
+ {...(isWeb && { type: 'button' })}
146
+ size={size}
147
+ {...props}
148
+ {...(switchProps as any)}
149
+ disabled={disabled}
150
+ {...(checked && activeStyle)}
151
+ >
152
+ <View alignSelf="stretch" flex={1} onLayout={handleLayout}>
153
+ {props.children}
154
+ </View>
155
+ </Frame>
156
+ )
157
+
158
+ const frameTheme =
159
+ (checked ? activeTheme : undefined) ?? theme ?? createProps.componentThemes?.frame
160
+
161
+ return (
162
+ <>
163
+ <SwitchStyledContext.Provider
164
+ size={size}
165
+ active={checked}
166
+ disabled={disabled}
167
+ frameWidth={frameWidth}
168
+ >
169
+ {frameTheme ? <Theme name={frameTheme}>{frame}</Theme> : frame}
170
+ </SwitchStyledContext.Provider>
171
+
172
+ {bubbleInput}
173
+ </>
174
+ )
84
175
  },
85
- },
86
- {
87
- accept: {
88
- activeStyle: 'style',
89
- } as const,
90
- }
91
- )
176
+ {
177
+ disableTheme: true,
178
+ }
179
+ )
180
+
181
+ return withStaticProperties(SwitchComponent, {
182
+ Frame,
183
+ Thumb: SwitchThumbComponent,
184
+ })
185
+ }
186
+
187
+ export const Switch = createSwitch({
188
+ Frame: SwitchFrame,
189
+ Thumb: SwitchThumbFrame,
190
+ })
191
+
192
+ export const SwitchThumb = Switch.Thumb
package/src/index.ts CHANGED
@@ -1,24 +1,4 @@
1
- import { createSwitch } from './createSwitch'
2
- import { SwitchFrame, SwitchThumb } from './Switch'
3
-
4
- export * from './createSwitch'
5
1
  export * from './StyledContext'
6
2
  export * from './Switch'
7
3
  export * from './types'
8
4
  export { useSwitchNative } from './useSwitchNative'
9
-
10
- /**
11
- * @summary A component that displays a switch that can be used to toggle between two states.
12
- * @see — Docs https://tamagui.dev/ui/switch
13
- *
14
- * @example
15
- * ```tsx
16
- * <Switch id={id} size={props.size} defaultChecked={props.defaultChecked}>
17
- * <Switch.Thumb transition="quicker" />
18
- * </Switch>
19
- * ```
20
- */
21
- export const Switch = createSwitch({
22
- Frame: SwitchFrame,
23
- Thumb: SwitchThumb,
24
- })
package/src/types.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import type { GetProps, NativeValue, SizeTokens, ViewProps } from '@tamagui/core'
2
2
  import type { SwitchExtraProps as HeadlessSwitchExtraProps } from '@tamagui/switch-headless'
3
- import type { SwitchProps as NativeSwitchProps, ViewStyle } from 'react-native'
4
- import type { SwitchThumb } from './Switch'
3
+ import type {
4
+ SwitchProps as NativeSwitchProps,
5
+ ViewStyle,
6
+ } from '@tamagui/react-native-types'
7
+ import type { SwitchThumbFrame } from './Switch'
5
8
 
6
9
  export type SwitchSharedProps = {
7
- size?: SizeTokens | number
8
- unstyled?: boolean
10
+ size?: SizeTokens | number | true
9
11
  }
10
12
 
11
13
  export type SwitchBaseProps = ViewProps & SwitchSharedProps
@@ -16,7 +18,7 @@ export type SwitchFrameActiveStyleProps = {
16
18
  }
17
19
 
18
20
  export type SwitchThumbActiveStyleProps = {
19
- activeStyle?: GetProps<typeof SwitchThumb>
21
+ activeStyle?: GetProps<typeof SwitchThumbFrame>
20
22
  }
21
23
 
22
24
  export type SwitchExtraProps = HeadlessSwitchExtraProps & {
@@ -32,7 +34,6 @@ export type SwitchThumbProps = SwitchThumbBaseProps &
32
34
  SwitchSharedProps &
33
35
  SwitchThumbActiveStyleProps
34
36
 
35
- // loose types for createSwitch generics - actual components have stricter types
36
37
  export type SwitchComponent = (props: any) => any
37
38
  export type SwitchThumbComponent = (props: any) => any
38
39
 
@@ -3,7 +3,6 @@ export declare const SwitchStyledContext: import("@tamagui/core").StyledContext<
3
3
  active?: boolean;
4
4
  disabled?: boolean;
5
5
  frameWidth?: number;
6
- size?: SizeTokens;
7
- unstyled?: boolean;
8
- }>;
6
+ size?: SizeTokens | number | true;
7
+ }, "active" | "disabled" | "frameWidth" | "size">;
9
8
  //# sourceMappingURL=StyledContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StyledContext.d.ts","sourceRoot":"","sources":["../src/StyledContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C,eAAO,MAAM,mBAAmB;aACrB,OAAO;eACL,OAAO;iBACL,MAAM;WACZ,UAAU;eACN,OAAO;EAOlB,CAAA"}
1
+ {"version":3,"file":"StyledContext.d.ts","sourceRoot":"","sources":["../src/StyledContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C,eAAO,MAAM,mBAAmB;aACrB,OAAO;eACL,OAAO;iBACL,MAAM;WACZ,UAAU,GAAG,MAAM,GAAG,IAAI;iDAMjC,CAAA"}