@tamagui/switch 2.7.7-1788328229285 → 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 +8 -13
  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
@@ -3,33 +3,28 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
10
  };
11
11
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
19
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
21
  var StyledContext_exports = {};
24
- __export(StyledContext_exports, {
25
- SwitchStyledContext: () => SwitchStyledContext
26
- });
22
+ __export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
27
23
  module.exports = __toCommonJS(StyledContext_exports);
28
24
  var import_core = require("@tamagui/core");
29
25
  const SwitchStyledContext = (0, import_core.createStyledContext)({
30
- active: false,
31
- disabled: false,
32
- frameWidth: void 0,
33
- size: void 0,
34
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
35
- });
26
+ active: false,
27
+ disabled: false,
28
+ frameWidth: void 0,
29
+ size: void 0
30
+ });
@@ -0,0 +1,32 @@
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 __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var StyledContext_exports = {};
24
+ __export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
25
+ module.exports = __toCommonJS(StyledContext_exports);
26
+ var import_core = require("@tamagui/core");
27
+ var SwitchStyledContext = (0, import_core.createStyledContext)({
28
+ active: false,
29
+ disabled: false,
30
+ frameWidth: void 0,
31
+ size: void 0
32
+ });
@@ -5,34 +5,30 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
- value: true
24
- }), mod);
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
23
  var StyledContext_exports = {};
26
- __export(StyledContext_exports, {
27
- SwitchStyledContext: () => SwitchStyledContext
28
- });
24
+ __export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
29
25
  module.exports = __toCommonJS(StyledContext_exports);
30
26
  var import_core = require("@tamagui/core");
31
27
  var SwitchStyledContext = (0, import_core.createStyledContext)({
32
- active: false,
33
- disabled: false,
34
- frameWidth: void 0,
35
- size: void 0,
36
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
28
+ active: false,
29
+ disabled: false,
30
+ frameWidth: void 0,
31
+ size: void 0
37
32
  });
33
+
38
34
  //# sourceMappingURL=StyledContext.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","StyledContext_exports","SwitchStyledContext","module","exports","import_core","require","createStyledContext","active","disabled","frameWidth","size","unstyled","process","env","TAMAGUI_HEADLESS"],"sources":["StyledContext.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\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 __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar StyledContext_exports = {};\n__export(StyledContext_exports, {\n SwitchStyledContext: () => SwitchStyledContext\n});\nmodule.exports = __toCommonJS(StyledContext_exports);\nvar import_core = require(\"@tamagui/core\");\nvar SwitchStyledContext = (0, import_core.createStyledContext)({\n active: false,\n disabled: false,\n frameWidth: void 0,\n size: void 0,\n unstyled: process.env.TAMAGUI_HEADLESS === \"1\"\n});\n//# sourceMappingURL=StyledContext.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAAIC,QAAQ,GAAGA,CAACC,MAAM,EAAEC,GAAG,KAAK;EAC9B,KAAK,IAAIC,IAAI,IAAID,GAAG,EAClBZ,SAAS,CAACW,MAAM,EAAEE,IAAI,EAAE;IAAEC,GAAG,EAAEF,GAAG,CAACC,IAAI,CAAC;IAAEE,UAAU,EAAE;EAAK,CAAC,CAAC;AACjE,CAAC;AACD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;IAClE,KAAK,IAAIG,GAAG,IAAIhB,iBAAiB,CAACa,IAAI,CAAC,EACrC,IAAI,CAACX,YAAY,CAACe,IAAI,CAACL,EAAE,EAAEI,GAAG,CAAC,IAAIA,GAAG,KAAKF,MAAM,EAC/CnB,SAAS,CAACiB,EAAE,EAAEI,GAAG,EAAE;MAAEP,GAAG,EAAEA,CAAA,KAAMI,IAAI,CAACG,GAAG,CAAC;MAAEN,UAAU,EAAE,EAAEK,IAAI,GAAGjB,gBAAgB,CAACe,IAAI,EAAEG,GAAG,CAAC,CAAC,IAAID,IAAI,CAACL;IAAW,CAAC,CAAC;EACxH;EACA,OAAOE,EAAE;AACX,CAAC;AACD,IAAIM,YAAY,GAAIC,GAAG,IAAKR,WAAW,CAAChB,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE;EAAEyB,KAAK,EAAE;AAAK,CAAC,CAAC,EAAED,GAAG,CAAC;AAC1F,IAAIE,qBAAqB,GAAG,CAAC,CAAC;AAC9BhB,QAAQ,CAACgB,qBAAqB,EAAE;EAC9BC,mBAAmB,EAAEA,CAAA,KAAMA;AAC7B,CAAC,CAAC;AACFC,MAAM,CAACC,OAAO,GAAGN,YAAY,CAACG,qBAAqB,CAAC;AACpD,IAAII,WAAW,GAAGC,OAAO,CAAC,eAAe,CAAC;AAC1C,IAAIJ,mBAAmB,GAAG,CAAC,CAAC,EAAEG,WAAW,CAACE,mBAAmB,EAAE;EAC7DC,MAAM,EAAE,KAAK;EACbC,QAAQ,EAAE,KAAK;EACfC,UAAU,EAAE,KAAK,CAAC;EAClBC,IAAI,EAAE,KAAK,CAAC;EACZC,QAAQ,EAAEC,OAAO,CAACC,GAAG,CAACC,gBAAgB,KAAK;AAC7C,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"StyledContext.native.js","names":[],"sources":["cjs/StyledContext.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\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 __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar StyledContext_exports = {};\n__export(StyledContext_exports, {\n SwitchStyledContext: () => SwitchStyledContext\n});\nmodule.exports = __toCommonJS(StyledContext_exports);\nvar import_core = require(\"@tamagui/core\");\nvar SwitchStyledContext = (0, import_core.createStyledContext)({\n active: false,\n disabled: false,\n frameWidth: void 0,\n size: void 0\n});\n//# sourceMappingURL=StyledContext.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,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,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,wBAAwB,CAAC;AAC7B,SAAS,uBAAuB,EAC9B,2BAA2B,oBAC7B,CAAC;AACD,OAAO,UAAU,aAAa,qBAAqB;AACnD,IAAI,cAAc,QAAQ,eAAe;AACzC,IAAI,uBAAuB,GAAG,YAAY,oBAAmB,CAAE;CAC7D,QAAQ;CACR,UAAU;CACV,YAAY,KAAK;CACjB,MAAM,KAAK;AACb,CAAC"}
@@ -1,100 +1,153 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
10
12
  };
11
13
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
19
21
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
27
  var Switch_exports = {};
24
28
  __export(Switch_exports, {
25
- SwitchFrame: () => SwitchFrame,
26
- SwitchThumb: () => SwitchThumb
29
+ Switch: () => Switch,
30
+ SwitchFrame: () => SwitchFrame,
31
+ SwitchThumb: () => SwitchThumb,
32
+ SwitchThumbFrame: () => SwitchThumbFrame,
33
+ createSwitch: () => createSwitch
27
34
  });
28
35
  module.exports = __toCommonJS(Switch_exports);
29
36
  var import_core = require("@tamagui/core");
30
- var import_get_token = require("@tamagui/get-token");
31
- var import_stacks = require("@tamagui/stacks");
32
- const SwitchThumb = (0, import_core.styled)(import_stacks.YStack, {
33
- name: "SwitchThumb",
34
- variants: {
35
- unstyled: {
36
- false: {
37
- size: "$true",
38
- backgroundColor: "$background",
39
- borderRadius: 1e3
40
- }
41
- },
42
- size: {
43
- "...size": val => {
44
- const size = getSwitchHeight(val);
45
- return {
46
- height: size,
47
- width: size
48
- };
49
- }
50
- }
51
- },
52
- defaultVariants: {
53
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
54
- }
55
- }, {
56
- accept: {
57
- activeStyle: "style"
58
- }
37
+ var import_switch_headless = require("@tamagui/switch-headless");
38
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
39
+ var React = __toESM(require("react"), 1);
40
+ var import_StyledContext = require("./StyledContext.cjs");
41
+ var import_useSwitchNative = require("./useSwitchNative.cjs");
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ const SwitchThumbFrame = (0, import_core.styled)(import_core.View, {
44
+ displayName: "SwitchThumb",
45
+ context: import_StyledContext.SwitchStyledContext
59
46
  });
60
- const getSwitchHeight = val => Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.65);
61
- const getSwitchWidth = val => getSwitchHeight(val) * 2;
62
- const SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
63
- name: "Switch",
64
- render: "button",
65
- tabIndex: 0,
66
- variants: {
67
- unstyled: {
68
- false: {
69
- borderRadius: 1e3,
70
- backgroundColor: "$background",
71
- focusVisibleStyle: {
72
- outlineColor: "$outlineColor",
73
- outlineStyle: "solid",
74
- outlineWidth: 2
75
- }
76
- }
77
- },
78
- size: {
79
- "...size": (val, {
80
- props
81
- }) => {
82
- if (props["unstyled"]) return;
83
- const height = getSwitchHeight(val);
84
- const width = getSwitchWidth(val);
85
- return {
86
- height,
87
- minHeight: height,
88
- width
89
- };
90
- }
91
- }
92
- },
93
- defaultVariants: {
94
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
95
- }
96
- }, {
97
- accept: {
98
- activeStyle: "style"
99
- }
100
- });
47
+ const SwitchFrame = (0, import_core.styled)(import_core.View, {
48
+ displayName: "Switch",
49
+ context: import_StyledContext.SwitchStyledContext,
50
+ render: "button",
51
+ tabIndex: 0
52
+ });
53
+ function createSwitch(createProps) {
54
+ const Frame = createProps.Frame ?? SwitchFrame;
55
+ const Thumb = createProps.Thumb ?? SwitchThumbFrame;
56
+ Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
57
+ Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
58
+ const SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
59
+ const { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
60
+ const styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
61
+ const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
62
+ const size = sizeProp ?? sizeContext ?? true;
63
+ const initialChecked = React.useRef(active).current;
64
+ const initialWidth = (0, import_core.getVariableValue)(props.width, "size");
65
+ const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
66
+ const distance = frameWidth - thumbWidth;
67
+ const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
68
+ const thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
69
+ ref: forwardedRef,
70
+ size,
71
+ alignSelf: initialChecked ? "flex-end" : "flex-start",
72
+ x,
73
+ onLayout: (0, import_core.composeEventHandlers)(props.onLayout, (event) => {
74
+ setThumbWidth(event.nativeEvent.layout.width);
75
+ }),
76
+ disabled,
77
+ ...thumbProps,
78
+ ...active && activeStyle
79
+ });
80
+ const themeName = theme ?? createProps.componentThemes?.thumb;
81
+ return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
82
+ name: themeName,
83
+ children: thumb
84
+ }) : thumb;
85
+ });
86
+ const SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
87
+ const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
88
+ const [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
89
+ prop: checkedProp,
90
+ defaultProp: defaultChecked || false,
91
+ onChange: onCheckedChange,
92
+ transition: true
93
+ });
94
+ const styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
95
+ const [frameWidth, setFrameInnerWidth] = React.useState(0);
96
+ const { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked], forwardedRef);
97
+ const nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
98
+ id: props.id,
99
+ disabled: props.disabled,
100
+ native,
101
+ nativeProps,
102
+ checked,
103
+ setChecked
104
+ });
105
+ if (nativeSwitch) {
106
+ return nativeSwitch;
107
+ }
108
+ const disabled = props.disabled;
109
+ const size = styledContext.size ?? props.size ?? true;
110
+ const handleLayout = (event) => {
111
+ const next = event.nativeEvent.layout.width;
112
+ if (next !== frameWidth) {
113
+ setFrameInnerWidth(next);
114
+ }
115
+ };
116
+ const frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
117
+ ref: switchRef,
118
+ render: "button",
119
+ ...import_core.isWeb && { type: "button" },
120
+ size,
121
+ ...props,
122
+ ...switchProps,
123
+ disabled,
124
+ ...checked && activeStyle,
125
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
126
+ alignSelf: "stretch",
127
+ flex: 1,
128
+ onLayout: handleLayout,
129
+ children: props.children
130
+ })
131
+ });
132
+ const frameTheme = (checked ? activeTheme : void 0) ?? theme ?? createProps.componentThemes?.frame;
133
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
134
+ size,
135
+ active: checked,
136
+ disabled,
137
+ frameWidth,
138
+ children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
139
+ name: frameTheme,
140
+ children: frame
141
+ }) : frame
142
+ }), bubbleInput] });
143
+ }, { disableTheme: true });
144
+ return (0, import_core.withStaticProperties)(SwitchComponent, {
145
+ Frame,
146
+ Thumb: SwitchThumbComponent
147
+ });
148
+ }
149
+ const Switch = createSwitch({
150
+ Frame: SwitchFrame,
151
+ Thumb: SwitchThumbFrame
152
+ });
153
+ const SwitchThumb = Switch.Thumb;
@@ -0,0 +1,162 @@
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 Switch_exports = {};
30
+ __export(Switch_exports, {
31
+ Switch: () => Switch,
32
+ SwitchFrame: () => SwitchFrame,
33
+ SwitchThumb: () => SwitchThumb,
34
+ SwitchThumbFrame: () => SwitchThumbFrame,
35
+ createSwitch: () => createSwitch
36
+ });
37
+ module.exports = __toCommonJS(Switch_exports);
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+ var import_core = require("@tamagui/core");
40
+ var import_switch_headless = require("@tamagui/switch-headless");
41
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
42
+ var React = __toESM(require("react"), 1);
43
+ var import_StyledContext = require("./StyledContext.native.js");
44
+ var import_useSwitchNative = require("./useSwitchNative.native.js");
45
+ var SwitchThumbFrame = (0, import_core.styled)(import_core.View, {
46
+ displayName: "SwitchThumb",
47
+ context: import_StyledContext.SwitchStyledContext
48
+ });
49
+ var SwitchFrame = (0, import_core.styled)(import_core.View, {
50
+ displayName: "Switch",
51
+ context: import_StyledContext.SwitchStyledContext,
52
+ render: "button",
53
+ tabIndex: 0
54
+ });
55
+ function createSwitch(createProps) {
56
+ var _createProps_Frame;
57
+ var Frame = (_createProps_Frame = createProps.Frame) !== null && _createProps_Frame !== void 0 ? _createProps_Frame : SwitchFrame;
58
+ var _createProps_Thumb;
59
+ var Thumb = (_createProps_Thumb = createProps.Thumb) !== null && _createProps_Thumb !== void 0 ? _createProps_Thumb : SwitchThumbFrame;
60
+ Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
61
+ Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
62
+ var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
63
+ var _createProps_componentThemes;
64
+ var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
65
+ var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
66
+ var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
67
+ var _ref;
68
+ var size = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref !== void 0 ? _ref : true;
69
+ var initialChecked = React.useRef(active).current;
70
+ var initialWidth = (0, import_core.getVariableValue)(props.width, "size");
71
+ var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
72
+ var distance = frameWidth - thumbWidth;
73
+ var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
74
+ var thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
75
+ ref: forwardedRef,
76
+ size,
77
+ alignSelf: initialChecked ? "flex-end" : "flex-start",
78
+ x,
79
+ onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(event) {
80
+ setThumbWidth(event.nativeEvent.layout.width);
81
+ }),
82
+ disabled,
83
+ ...thumbProps,
84
+ ...active && activeStyle
85
+ });
86
+ var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;
87
+ return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
88
+ name: themeName,
89
+ children: thumb
90
+ }) : thumb;
91
+ });
92
+ var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
93
+ var _createProps_componentThemes;
94
+ var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
95
+ var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
96
+ prop: checkedProp,
97
+ defaultProp: defaultChecked || false,
98
+ onChange: onCheckedChange,
99
+ transition: true
100
+ });
101
+ var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
102
+ var [frameWidth, setFrameInnerWidth] = React.useState(0);
103
+ var { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked], forwardedRef);
104
+ var nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
105
+ id: props.id,
106
+ disabled: props.disabled,
107
+ native,
108
+ nativeProps,
109
+ checked,
110
+ setChecked
111
+ });
112
+ if (nativeSwitch) {
113
+ return nativeSwitch;
114
+ }
115
+ var disabled = props.disabled;
116
+ var _styledContext_size, _ref;
117
+ var size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : true;
118
+ var handleLayout = function(event) {
119
+ var next = event.nativeEvent.layout.width;
120
+ if (next !== frameWidth) {
121
+ setFrameInnerWidth(next);
122
+ }
123
+ };
124
+ var frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
125
+ ref: switchRef,
126
+ render: "button",
127
+ ...import_core.isWeb && { type: "button" },
128
+ size,
129
+ ...props,
130
+ ...switchProps,
131
+ disabled,
132
+ ...checked && activeStyle,
133
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
134
+ alignSelf: "stretch",
135
+ flex: 1,
136
+ onLayout: handleLayout,
137
+ children: props.children
138
+ })
139
+ });
140
+ var _ref1, _ref2;
141
+ var frameTheme = (_ref2 = (_ref1 = checked ? activeTheme : void 0) !== null && _ref1 !== void 0 ? _ref1 : theme) !== null && _ref2 !== void 0 ? _ref2 : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.frame;
142
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
143
+ size,
144
+ active: checked,
145
+ disabled,
146
+ frameWidth,
147
+ children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
148
+ name: frameTheme,
149
+ children: frame
150
+ }) : frame
151
+ }), bubbleInput] });
152
+ }, { disableTheme: true });
153
+ return (0, import_core.withStaticProperties)(SwitchComponent, {
154
+ Frame,
155
+ Thumb: SwitchThumbComponent
156
+ });
157
+ }
158
+ var Switch = createSwitch({
159
+ Frame: SwitchFrame,
160
+ Thumb: SwitchThumbFrame
161
+ });
162
+ var SwitchThumb = Switch.Thumb;