@tamagui/switch 2.7.7 → 3.0.0-beta.1093.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/StyledContext.cjs +18 -23
- package/dist/cjs/StyledContext.native.cjs +32 -0
- package/dist/cjs/StyledContext.native.js +18 -22
- package/dist/cjs/StyledContext.native.js.map +1 -1
- package/dist/cjs/Switch.cjs +139 -86
- package/dist/cjs/Switch.native.cjs +162 -0
- package/dist/cjs/Switch.native.js +146 -90
- package/dist/cjs/Switch.native.js.map +1 -1
- package/dist/cjs/index.cjs +13 -25
- package/dist/cjs/index.native.cjs +30 -0
- package/dist/cjs/index.native.js +14 -25
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +9 -11
- package/dist/cjs/types.native.cjs +18 -0
- package/dist/cjs/types.native.js +9 -10
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useSwitchNative.cjs +15 -19
- package/dist/cjs/useSwitchNative.native.cjs +64 -0
- package/dist/cjs/useSwitchNative.native.js +43 -54
- package/dist/cjs/useSwitchNative.native.js.map +1 -1
- package/dist/esm/StyledContext.mjs +6 -5
- package/dist/esm/StyledContext.mjs.map +1 -1
- package/dist/esm/StyledContext.native.js +6 -5
- package/dist/esm/StyledContext.native.js.map +1 -1
- package/dist/esm/Switch.mjs +119 -71
- package/dist/esm/Switch.mjs.map +1 -1
- package/dist/esm/Switch.native.js +126 -76
- package/dist/esm/Switch.native.js.map +1 -1
- package/dist/esm/index.js +8 -12
- package/dist/esm/index.mjs +8 -12
- package/dist/esm/index.native.js +8 -12
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.native.js +0 -2
- package/dist/esm/useSwitchNative.mjs +2 -1
- package/dist/esm/useSwitchNative.mjs.map +1 -1
- package/dist/esm/useSwitchNative.native.js +30 -31
- package/dist/esm/useSwitchNative.native.js.map +1 -1
- package/dist/jsx/StyledContext.mjs +6 -5
- package/dist/jsx/StyledContext.mjs.map +1 -1
- package/dist/jsx/StyledContext.native.cjs +32 -0
- package/dist/jsx/StyledContext.native.js +18 -22
- package/dist/jsx/StyledContext.native.js.map +1 -1
- package/dist/jsx/Switch.mjs +119 -71
- package/dist/jsx/Switch.mjs.map +1 -1
- package/dist/jsx/Switch.native.cjs +162 -0
- package/dist/jsx/Switch.native.js +146 -90
- package/dist/jsx/Switch.native.js.map +1 -1
- package/dist/jsx/index.js +8 -12
- package/dist/jsx/index.mjs +8 -12
- package/dist/jsx/index.native.cjs +30 -0
- package/dist/jsx/index.native.js +14 -25
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/types.mjs +0 -2
- package/dist/jsx/types.native.cjs +18 -0
- package/dist/jsx/types.native.js +9 -10
- package/dist/jsx/types.native.js.map +1 -1
- package/dist/jsx/useSwitchNative.mjs +2 -1
- package/dist/jsx/useSwitchNative.mjs.map +1 -1
- package/dist/jsx/useSwitchNative.native.cjs +64 -0
- package/dist/jsx/useSwitchNative.native.js +43 -54
- package/dist/jsx/useSwitchNative.native.js.map +1 -1
- package/package.json +10 -15
- package/src/StyledContext.tsx +1 -3
- package/src/Switch.tsx +190 -89
- package/src/index.ts +0 -20
- package/src/types.ts +7 -6
- package/types/StyledContext.d.ts +2 -3
- package/types/StyledContext.d.ts.map +1 -1
- package/types/Switch.d.ts +209 -37
- package/types/Switch.d.ts.map +1 -1
- package/types/index.d.ts +0 -146
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +4 -5
- package/types/types.d.ts.map +1 -1
- package/dist/cjs/createSwitch.cjs +0 -186
- package/dist/cjs/createSwitch.native.js +0 -194
- package/dist/cjs/createSwitch.native.js.map +0 -1
- package/dist/esm/createSwitch.mjs +0 -150
- package/dist/esm/createSwitch.mjs.map +0 -1
- package/dist/esm/createSwitch.native.js +0 -155
- package/dist/esm/createSwitch.native.js.map +0 -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/esm/types.mjs.map +0 -1
- package/dist/esm/types.native.js.map +0 -1
- package/dist/jsx/createSwitch.mjs +0 -150
- package/dist/jsx/createSwitch.mjs.map +0 -1
- package/dist/jsx/createSwitch.native.js +0 -194
- package/dist/jsx/createSwitch.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
- package/dist/jsx/types.mjs.map +0 -1
- package/src/Switch.draggable-tmp +0 -340
- package/src/createSwitch.tsx +0 -201
- package/types/createSwitch.d.ts +0 -141
- package/types/createSwitch.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":[],"sourcesContent":[
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
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,"
|
|
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": "
|
|
3
|
+
"version": "3.0.0-beta.1093.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/
|
|
38
|
-
"@tamagui/
|
|
39
|
-
"@tamagui/
|
|
40
|
-
"@tamagui/
|
|
41
|
-
"@tamagui/
|
|
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.1093.1",
|
|
39
|
+
"@tamagui/focusable": "3.0.0-beta.1093.1",
|
|
40
|
+
"@tamagui/react-native-types": "3.0.0-beta.1093.1",
|
|
41
|
+
"@tamagui/switch-headless": "3.0.0-beta.1093.1",
|
|
42
|
+
"@tamagui/use-controllable-state": "3.0.0-beta.1093.1"
|
|
48
43
|
},
|
|
49
44
|
"devDependencies": {
|
|
50
|
-
"@tamagui/build": "
|
|
51
|
-
"react": "
|
|
52
|
-
"react-native": "0.
|
|
45
|
+
"@tamagui/build": "3.0.0-beta.1093.1",
|
|
46
|
+
"react": "19.2.3",
|
|
47
|
+
"react-native": "0.86.2"
|
|
53
48
|
},
|
|
54
49
|
"peerDependencies": {
|
|
55
50
|
"react": ">=19"
|
package/src/StyledContext.tsx
CHANGED
|
@@ -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 {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
-
|
|
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
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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 {
|
|
4
|
-
|
|
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
|
|
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
|
|
package/types/StyledContext.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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"}
|