@tamagui/switch 2.7.7 → 3.0.0-beta.643.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/StyledContext.cjs +19 -23
- package/dist/cjs/StyledContext.native.cjs +33 -0
- package/dist/cjs/StyledContext.native.js +19 -22
- package/dist/cjs/StyledContext.native.js.map +1 -1
- package/dist/cjs/Switch.cjs +140 -86
- package/dist/cjs/Switch.native.cjs +163 -0
- package/dist/cjs/Switch.native.js +147 -90
- package/dist/cjs/Switch.native.js.map +1 -1
- package/dist/cjs/index.cjs +14 -25
- package/dist/cjs/index.native.cjs +31 -0
- package/dist/cjs/index.native.js +15 -25
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +10 -11
- package/dist/cjs/types.native.cjs +19 -0
- package/dist/cjs/types.native.js +10 -10
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useSwitchNative.cjs +16 -19
- package/dist/cjs/useSwitchNative.native.cjs +65 -0
- package/dist/cjs/useSwitchNative.native.js +44 -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 +33 -0
- package/dist/jsx/StyledContext.native.js +19 -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 +163 -0
- package/dist/jsx/Switch.native.js +147 -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 +31 -0
- package/dist/jsx/index.native.js +15 -25
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/types.mjs +0 -2
- package/dist/jsx/types.native.cjs +19 -0
- package/dist/jsx/types.native.js +10 -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 +65 -0
- package/dist/jsx/useSwitchNative.native.js +44 -54
- package/dist/jsx/useSwitchNative.native.js.map +1 -1
- package/package.json +7 -14
- package/src/StyledContext.tsx +1 -3
- package/src/Switch.tsx +190 -89
- package/src/index.ts +0 -20
- package/src/types.ts +3 -5
- 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 +3 -4
- 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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var useSwitchNative_native_exports = {};
|
|
31
|
+
__export(useSwitchNative_native_exports, { useSwitchNative: () => useSwitchNative });
|
|
32
|
+
module.exports = __toCommonJS(useSwitchNative_native_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_core = require("@tamagui/core");
|
|
35
|
+
var import_focusable = require("@tamagui/focusable");
|
|
36
|
+
var React = __toESM(require("react"), 1);
|
|
37
|
+
var import_react_native = require("react-native");
|
|
38
|
+
function useSwitchNative(props) {
|
|
39
|
+
var { id, disabled, native, nativeProps, checked, setChecked } = props;
|
|
40
|
+
React.useEffect(function() {
|
|
41
|
+
if (!id) return;
|
|
42
|
+
if (disabled) return;
|
|
43
|
+
return (0, import_focusable.registerFocusable)(id, {
|
|
44
|
+
focusAndSelect: function() {
|
|
45
|
+
setChecked(function(value) {
|
|
46
|
+
return !value;
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
focus: function() {}
|
|
50
|
+
});
|
|
51
|
+
}, [
|
|
52
|
+
id,
|
|
53
|
+
disabled,
|
|
54
|
+
setChecked
|
|
55
|
+
]);
|
|
56
|
+
var renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
57
|
+
if (renderNative === "android" || renderNative === "ios") {
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, {
|
|
59
|
+
value: checked,
|
|
60
|
+
onValueChange: setChecked,
|
|
61
|
+
...nativeProps
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,36 +8,27 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
14
15
|
};
|
|
15
16
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
23
24
|
};
|
|
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
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
32
28
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
30
|
var useSwitchNative_native_exports = {};
|
|
37
|
-
__export(useSwitchNative_native_exports, {
|
|
38
|
-
useSwitchNative: () => useSwitchNative
|
|
39
|
-
});
|
|
31
|
+
__export(useSwitchNative_native_exports, { useSwitchNative: () => useSwitchNative });
|
|
40
32
|
module.exports = __toCommonJS(useSwitchNative_native_exports);
|
|
41
33
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
34
|
var import_core = require("@tamagui/core");
|
|
@@ -44,34 +36,32 @@ var import_focusable = require("@tamagui/focusable");
|
|
|
44
36
|
var React = __toESM(require("react"), 1);
|
|
45
37
|
var import_react_native = require("react-native");
|
|
46
38
|
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;
|
|
39
|
+
var { id, disabled, native, nativeProps, checked, setChecked } = props;
|
|
40
|
+
React.useEffect(function() {
|
|
41
|
+
if (!id) return;
|
|
42
|
+
if (disabled) return;
|
|
43
|
+
return (0, import_focusable.registerFocusable)(id, {
|
|
44
|
+
focusAndSelect: function() {
|
|
45
|
+
setChecked(function(value) {
|
|
46
|
+
return !value;
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
focus: function() {}
|
|
50
|
+
});
|
|
51
|
+
}, [
|
|
52
|
+
id,
|
|
53
|
+
disabled,
|
|
54
|
+
setChecked
|
|
55
|
+
]);
|
|
56
|
+
var renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
57
|
+
if (renderNative === "android" || renderNative === "ios") {
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, {
|
|
59
|
+
value: checked,
|
|
60
|
+
onValueChange: setChecked,
|
|
61
|
+
...nativeProps
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
76
65
|
}
|
|
66
|
+
|
|
77
67
|
//# sourceMappingURL=useSwitchNative.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useSwitchNative.native.js","names":[],"sources":["cjs/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,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import { createStyledContext } from "@tamagui/core";
|
|
2
|
+
|
|
2
3
|
const SwitchStyledContext = createStyledContext({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
4
|
+
active: false,
|
|
5
|
+
disabled: false,
|
|
6
|
+
frameWidth: void 0,
|
|
7
|
+
size: void 0
|
|
8
8
|
});
|
|
9
|
+
|
|
9
10
|
export { SwitchStyledContext };
|
|
10
11
|
//# sourceMappingURL=StyledContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"StyledContext.js","names":[],"sources":["esm/StyledContext.js"],"sourcesContent":["import { createStyledContext } from \"@tamagui/core\";\nconst SwitchStyledContext = createStyledContext({\n active: false,\n disabled: false,\n frameWidth: void 0,\n size: void 0\n});\nexport {\n SwitchStyledContext\n};\n//# sourceMappingURL=StyledContext.js.map\n"],"mappings":";;;AACA,MAAM,sBAAsB,oBAAoB;CAC9C,QAAQ;CACR,UAAU;CACV,YAAY,KAAK;CACjB,MAAM,KAAK;AACb,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createStyledContext } from "@tamagui/core";
|
|
2
|
+
|
|
2
3
|
var SwitchStyledContext = createStyledContext({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
4
|
+
active: false,
|
|
5
|
+
disabled: false,
|
|
6
|
+
frameWidth: void 0,
|
|
7
|
+
size: void 0
|
|
8
8
|
});
|
|
9
|
+
|
|
9
10
|
export { SwitchStyledContext };
|
|
10
11
|
//# sourceMappingURL=StyledContext.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"StyledContext.native.js","names":[],"sources":["esm/StyledContext.native.js"],"sourcesContent":["import { createStyledContext } from \"@tamagui/core\";\nvar SwitchStyledContext = createStyledContext({\n active: false,\n disabled: false,\n frameWidth: void 0,\n size: void 0\n});\nexport {\n SwitchStyledContext\n};\n//# sourceMappingURL=StyledContext.js.map\n"],"mappings":";;;AACA,IAAI,sBAAsB,oBAAoB;CAC5C,QAAQ;CACR,UAAU;CACV,YAAY,KAAK;CACjB,MAAM,KAAK;AACb,CAAC"}
|
package/dist/esm/Switch.mjs
CHANGED
|
@@ -1,74 +1,122 @@
|
|
|
1
|
-
import { getVariableValue, styled } from "@tamagui/core";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
size: {
|
|
15
|
-
"...size": val => {
|
|
16
|
-
const size = getSwitchHeight(val);
|
|
17
|
-
return {
|
|
18
|
-
height: size,
|
|
19
|
-
width: size
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
defaultVariants: {
|
|
25
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
26
|
-
}
|
|
27
|
-
}, {
|
|
28
|
-
accept: {
|
|
29
|
-
activeStyle: "style"
|
|
30
|
-
}
|
|
1
|
+
import { Theme, View, composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, withStaticProperties } from "@tamagui/core";
|
|
2
|
+
import { useSwitch } from "@tamagui/switch-headless";
|
|
3
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { SwitchStyledContext } from "./StyledContext.mjs";
|
|
6
|
+
import { useSwitchNative } from "./useSwitchNative.mjs";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
const SwitchThumbFrame = styled(View, {
|
|
10
|
+
displayName: "SwitchThumb",
|
|
11
|
+
context: SwitchStyledContext
|
|
31
12
|
});
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
tabIndex: 0,
|
|
38
|
-
variants: {
|
|
39
|
-
unstyled: {
|
|
40
|
-
false: {
|
|
41
|
-
borderRadius: 1e3,
|
|
42
|
-
backgroundColor: "$background",
|
|
43
|
-
focusVisibleStyle: {
|
|
44
|
-
outlineColor: "$outlineColor",
|
|
45
|
-
outlineStyle: "solid",
|
|
46
|
-
outlineWidth: 2
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
size: {
|
|
51
|
-
"...size": (val, {
|
|
52
|
-
props
|
|
53
|
-
}) => {
|
|
54
|
-
if (props["unstyled"]) return;
|
|
55
|
-
const height = getSwitchHeight(val);
|
|
56
|
-
const width = getSwitchWidth(val);
|
|
57
|
-
return {
|
|
58
|
-
height,
|
|
59
|
-
minHeight: height,
|
|
60
|
-
width
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
defaultVariants: {
|
|
66
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
accept: {
|
|
70
|
-
activeStyle: "style"
|
|
71
|
-
}
|
|
13
|
+
const SwitchFrame = styled(View, {
|
|
14
|
+
displayName: "Switch",
|
|
15
|
+
context: SwitchStyledContext,
|
|
16
|
+
render: "button",
|
|
17
|
+
tabIndex: 0
|
|
72
18
|
});
|
|
73
|
-
|
|
19
|
+
function createSwitch(createProps) {
|
|
20
|
+
const Frame = createProps.Frame ?? SwitchFrame;
|
|
21
|
+
const Thumb = createProps.Thumb ?? SwitchThumbFrame;
|
|
22
|
+
Frame.staticConfig.context = SwitchStyledContext;
|
|
23
|
+
Thumb.staticConfig.context = SwitchStyledContext;
|
|
24
|
+
const SwitchThumbComponent = createStyledHOC(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
25
|
+
const { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
|
|
26
|
+
const styledContext = SwitchStyledContext.useStyledContext();
|
|
27
|
+
const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
28
|
+
const size = sizeProp ?? sizeContext ?? true;
|
|
29
|
+
const initialChecked = React.useRef(active).current;
|
|
30
|
+
const initialWidth = getVariableValue(props.width, "size");
|
|
31
|
+
const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
32
|
+
const distance = frameWidth - thumbWidth;
|
|
33
|
+
const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
34
|
+
const thumb = /* @__PURE__ */ jsx(Thumb, {
|
|
35
|
+
ref: forwardedRef,
|
|
36
|
+
size,
|
|
37
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
38
|
+
x,
|
|
39
|
+
onLayout: composeEventHandlers(props.onLayout, (event) => {
|
|
40
|
+
setThumbWidth(event.nativeEvent.layout.width);
|
|
41
|
+
}),
|
|
42
|
+
disabled,
|
|
43
|
+
...thumbProps,
|
|
44
|
+
...active && activeStyle
|
|
45
|
+
});
|
|
46
|
+
const themeName = theme ?? createProps.componentThemes?.thumb;
|
|
47
|
+
return themeName ? /* @__PURE__ */ jsx(Theme, {
|
|
48
|
+
name: themeName,
|
|
49
|
+
children: thumb
|
|
50
|
+
}) : thumb;
|
|
51
|
+
});
|
|
52
|
+
const SwitchComponent = createStyledHOC(Frame, function Switch2(_props, forwardedRef) {
|
|
53
|
+
const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
|
|
54
|
+
const [checked, setChecked] = useControllableState({
|
|
55
|
+
prop: checkedProp,
|
|
56
|
+
defaultProp: defaultChecked || false,
|
|
57
|
+
onChange: onCheckedChange,
|
|
58
|
+
transition: true
|
|
59
|
+
});
|
|
60
|
+
const styledContext = React.useContext(SwitchStyledContext.context);
|
|
61
|
+
const [frameWidth, setFrameInnerWidth] = React.useState(0);
|
|
62
|
+
const { switchProps, bubbleInput, switchRef } = useSwitch(props, [checked, setChecked], forwardedRef);
|
|
63
|
+
const nativeSwitch = useSwitchNative({
|
|
64
|
+
id: props.id,
|
|
65
|
+
disabled: props.disabled,
|
|
66
|
+
native,
|
|
67
|
+
nativeProps,
|
|
68
|
+
checked,
|
|
69
|
+
setChecked
|
|
70
|
+
});
|
|
71
|
+
if (nativeSwitch) {
|
|
72
|
+
return nativeSwitch;
|
|
73
|
+
}
|
|
74
|
+
const disabled = props.disabled;
|
|
75
|
+
const size = styledContext.size ?? props.size ?? true;
|
|
76
|
+
const handleLayout = (event) => {
|
|
77
|
+
const next = event.nativeEvent.layout.width;
|
|
78
|
+
if (next !== frameWidth) {
|
|
79
|
+
setFrameInnerWidth(next);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const frame = /* @__PURE__ */ jsx(Frame, {
|
|
83
|
+
ref: switchRef,
|
|
84
|
+
render: "button",
|
|
85
|
+
...isWeb && { type: "button" },
|
|
86
|
+
size,
|
|
87
|
+
...props,
|
|
88
|
+
...switchProps,
|
|
89
|
+
disabled,
|
|
90
|
+
...checked && activeStyle,
|
|
91
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
92
|
+
alignSelf: "stretch",
|
|
93
|
+
flex: 1,
|
|
94
|
+
onLayout: handleLayout,
|
|
95
|
+
children: props.children
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
const frameTheme = (checked ? activeTheme : void 0) ?? theme ?? createProps.componentThemes?.frame;
|
|
99
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SwitchStyledContext.Provider, {
|
|
100
|
+
size,
|
|
101
|
+
active: checked,
|
|
102
|
+
disabled,
|
|
103
|
+
frameWidth,
|
|
104
|
+
children: frameTheme ? /* @__PURE__ */ jsx(Theme, {
|
|
105
|
+
name: frameTheme,
|
|
106
|
+
children: frame
|
|
107
|
+
}) : frame
|
|
108
|
+
}), bubbleInput] });
|
|
109
|
+
}, { disableTheme: true });
|
|
110
|
+
return withStaticProperties(SwitchComponent, {
|
|
111
|
+
Frame,
|
|
112
|
+
Thumb: SwitchThumbComponent
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const Switch = createSwitch({
|
|
116
|
+
Frame: SwitchFrame,
|
|
117
|
+
Thumb: SwitchThumbFrame
|
|
118
|
+
});
|
|
119
|
+
const SwitchThumb = Switch.Thumb;
|
|
120
|
+
|
|
121
|
+
export { Switch, SwitchFrame, SwitchThumb, SwitchThumbFrame, createSwitch };
|
|
74
122
|
//# sourceMappingURL=Switch.mjs.map
|
package/dist/esm/Switch.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Switch.js","names":[],"sources":["esm/Switch.js"],"sourcesContent":["import {\n composeEventHandlers,\n createStyledHOC,\n getVariableValue,\n isWeb,\n styled,\n Theme,\n View,\n withStaticProperties\n} from \"@tamagui/core\";\nimport { useSwitch } from \"@tamagui/switch-headless\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport * as React from \"react\";\nimport { SwitchStyledContext } from \"./StyledContext\";\nimport { useSwitchNative } from \"./useSwitchNative\";\nimport { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nconst SwitchThumbFrame = styled(View, {\n displayName: \"SwitchThumb\",\n context: SwitchStyledContext\n});\nconst SwitchFrame = styled(View, {\n displayName: \"Switch\",\n context: SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n const Frame = createProps.Frame ?? SwitchFrame;\n const Thumb = createProps.Thumb ?? SwitchThumbFrame;\n Frame.staticConfig.context = SwitchStyledContext;\n Thumb.staticConfig.context = SwitchStyledContext;\n const SwitchThumbComponent = createStyledHOC(\n Thumb,\n function SwitchThumb2(props, forwardedRef) {\n const { size: sizeProp, activeStyle, theme, ...thumbProps } = props;\n const styledContext = SwitchStyledContext.useStyledContext();\n const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n const size = sizeProp ?? sizeContext ?? true;\n const initialChecked = React.useRef(active).current;\n const initialWidth = getVariableValue(props.width, \"size\");\n const [thumbWidth, setThumbWidth] = React.useState(\n typeof initialWidth === \"number\" ? initialWidth : 0\n );\n const distance = frameWidth - thumbWidth;\n const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n const thumb = /* @__PURE__ */ jsx(\n Thumb,\n {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: composeEventHandlers(props.onLayout, (event) => {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n }\n );\n const themeName = theme ?? createProps.componentThemes?.thumb;\n return themeName ? /* @__PURE__ */ jsx(Theme, { name: themeName, children: thumb }) : thumb;\n }\n );\n const SwitchComponent = createStyledHOC(\n Frame,\n function Switch2(_props, forwardedRef) {\n const {\n native,\n nativeProps,\n checked: checkedProp,\n defaultChecked,\n onCheckedChange,\n activeStyle,\n activeTheme,\n theme,\n ...props\n } = _props;\n const [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n const styledContext = React.useContext(SwitchStyledContext.context);\n const [frameWidth, setFrameInnerWidth] = React.useState(0);\n const { switchProps, bubbleInput, switchRef } = useSwitch(\n props,\n [checked, setChecked],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n const nativeSwitch = useSwitchNative({\n id: props.id,\n disabled: props.disabled,\n native,\n nativeProps,\n checked,\n setChecked\n });\n if (nativeSwitch) {\n return nativeSwitch;\n }\n const disabled = props.disabled;\n const size = styledContext.size ?? props.size ?? true;\n const handleLayout = (event) => {\n const next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n const frame = /* @__PURE__ */ jsx(\n Frame,\n {\n ref: switchRef,\n render: \"button\",\n ...isWeb && { type: \"button\" },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ jsx(View, { alignSelf: \"stretch\", flex: 1, onLayout: handleLayout, children: props.children })\n }\n );\n const frameTheme = (checked ? activeTheme : void 0) ?? theme ?? createProps.componentThemes?.frame;\n return /* @__PURE__ */ jsxs(Fragment, { children: [\n /* @__PURE__ */ jsx(\n SwitchStyledContext.Provider,\n {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: frameTheme ? /* @__PURE__ */ jsx(Theme, { name: frameTheme, children: frame }) : frame\n }\n ),\n bubbleInput\n ] });\n },\n {\n disableTheme: true\n }\n );\n return withStaticProperties(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nconst Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nconst SwitchThumb = Switch.Thumb;\nexport {\n Switch,\n SwitchFrame,\n SwitchThumb,\n SwitchThumbFrame,\n createSwitch\n};\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;;;;;;;AAgBA,MAAM,mBAAmB,OAAO,MAAM;CACpC,aAAa;CACb,SAAS;AACX,CAAC;AACD,MAAM,cAAc,OAAO,MAAM;CAC/B,aAAa;CACb,SAAS;CACT,QAAQ;CACR,UAAU;AACZ,CAAC;AACD,SAAS,aAAa,aAAa;CACjC,MAAM,QAAQ,YAAY,SAAS;CACnC,MAAM,QAAQ,YAAY,SAAS;CACnC,MAAM,aAAa,UAAU;CAC7B,MAAM,aAAa,UAAU;CAC7B,MAAM,uBAAuB,gBAC3B,OACA,SAAS,aAAa,OAAO,cAAc;EACzC,MAAM,EAAE,MAAM,UAAU,aAAa,OAAO,GAAG,eAAe;EAC9D,MAAM,gBAAgB,oBAAoB,iBAAiB;EAC3D,MAAM,EAAE,MAAM,aAAa,QAAQ,UAAU,aAAa,MAAM;EAChE,MAAM,OAAO,YAAY,eAAe;EACxC,MAAM,iBA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