@tamagui/switch 2.7.7 → 3.0.0-beta.637.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
|
@@ -1,35 +1,31 @@
|
|
|
1
|
+
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
6
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
10
11
|
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
19
20
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
22
|
var StyledContext_exports = {};
|
|
24
|
-
__export(StyledContext_exports, {
|
|
25
|
-
SwitchStyledContext: () => SwitchStyledContext
|
|
26
|
-
});
|
|
23
|
+
__export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
|
|
27
24
|
module.exports = __toCommonJS(StyledContext_exports);
|
|
28
25
|
var import_core = require("@tamagui/core");
|
|
29
26
|
const SwitchStyledContext = (0, import_core.createStyledContext)({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
27
|
+
active: false,
|
|
28
|
+
disabled: false,
|
|
29
|
+
frameWidth: void 0,
|
|
30
|
+
size: void 0
|
|
31
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var StyledContext_exports = {};
|
|
25
|
+
__export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
|
|
26
|
+
module.exports = __toCommonJS(StyledContext_exports);
|
|
27
|
+
var import_core = require("@tamagui/core");
|
|
28
|
+
var SwitchStyledContext = (0, import_core.createStyledContext)({
|
|
29
|
+
active: false,
|
|
30
|
+
disabled: false,
|
|
31
|
+
frameWidth: void 0,
|
|
32
|
+
size: void 0
|
|
33
|
+
});
|
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
24
|
var StyledContext_exports = {};
|
|
26
|
-
__export(StyledContext_exports, {
|
|
27
|
-
SwitchStyledContext: () => SwitchStyledContext
|
|
28
|
-
});
|
|
25
|
+
__export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
|
|
29
26
|
module.exports = __toCommonJS(StyledContext_exports);
|
|
30
27
|
var import_core = require("@tamagui/core");
|
|
31
28
|
var SwitchStyledContext = (0, import_core.createStyledContext)({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
29
|
+
active: false,
|
|
30
|
+
disabled: false,
|
|
31
|
+
frameWidth: void 0,
|
|
32
|
+
size: void 0
|
|
37
33
|
});
|
|
34
|
+
|
|
38
35
|
//# sourceMappingURL=StyledContext.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,qBAAqB;CAC7D,QAAQ;CACR,UAAU;CACV,YAAY,KAAK;CACjB,MAAM,KAAK;AACb,CAAC"}
|
package/dist/cjs/Switch.cjs
CHANGED
|
@@ -1,100 +1,154 @@
|
|
|
1
|
+
|
|
2
|
+
var __create = Object.create;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
2
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
8
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
10
13
|
};
|
|
11
14
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
28
|
var Switch_exports = {};
|
|
24
29
|
__export(Switch_exports, {
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
Switch: () => Switch,
|
|
31
|
+
SwitchFrame: () => SwitchFrame,
|
|
32
|
+
SwitchThumb: () => SwitchThumb,
|
|
33
|
+
SwitchThumbFrame: () => SwitchThumbFrame,
|
|
34
|
+
createSwitch: () => createSwitch
|
|
27
35
|
});
|
|
28
36
|
module.exports = __toCommonJS(Switch_exports);
|
|
29
37
|
var import_core = require("@tamagui/core");
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
}
|
|
38
|
+
var import_switch_headless = require("@tamagui/switch-headless");
|
|
39
|
+
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
40
|
+
var React = __toESM(require("react"), 1);
|
|
41
|
+
var import_StyledContext = require("./StyledContext.cjs");
|
|
42
|
+
var import_useSwitchNative = require("./useSwitchNative.cjs");
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
const SwitchThumbFrame = (0, import_core.styled)(import_core.View, {
|
|
45
|
+
displayName: "SwitchThumb",
|
|
46
|
+
context: import_StyledContext.SwitchStyledContext
|
|
59
47
|
});
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
48
|
+
const SwitchFrame = (0, import_core.styled)(import_core.View, {
|
|
49
|
+
displayName: "Switch",
|
|
50
|
+
context: import_StyledContext.SwitchStyledContext,
|
|
51
|
+
render: "button",
|
|
52
|
+
tabIndex: 0
|
|
53
|
+
});
|
|
54
|
+
function createSwitch(createProps) {
|
|
55
|
+
const Frame = createProps.Frame ?? SwitchFrame;
|
|
56
|
+
const Thumb = createProps.Thumb ?? SwitchThumbFrame;
|
|
57
|
+
Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
58
|
+
Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
59
|
+
const SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
60
|
+
const { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
|
|
61
|
+
const styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
|
|
62
|
+
const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
63
|
+
const size = sizeProp ?? sizeContext ?? true;
|
|
64
|
+
const initialChecked = React.useRef(active).current;
|
|
65
|
+
const initialWidth = (0, import_core.getVariableValue)(props.width, "size");
|
|
66
|
+
const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
67
|
+
const distance = frameWidth - thumbWidth;
|
|
68
|
+
const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
69
|
+
const thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
|
|
70
|
+
ref: forwardedRef,
|
|
71
|
+
size,
|
|
72
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
73
|
+
x,
|
|
74
|
+
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, (event) => {
|
|
75
|
+
setThumbWidth(event.nativeEvent.layout.width);
|
|
76
|
+
}),
|
|
77
|
+
disabled,
|
|
78
|
+
...thumbProps,
|
|
79
|
+
...active && activeStyle
|
|
80
|
+
});
|
|
81
|
+
const themeName = theme ?? createProps.componentThemes?.thumb;
|
|
82
|
+
return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
83
|
+
name: themeName,
|
|
84
|
+
children: thumb
|
|
85
|
+
}) : thumb;
|
|
86
|
+
});
|
|
87
|
+
const SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
|
|
88
|
+
const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
|
|
89
|
+
const [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
90
|
+
prop: checkedProp,
|
|
91
|
+
defaultProp: defaultChecked || false,
|
|
92
|
+
onChange: onCheckedChange,
|
|
93
|
+
transition: true
|
|
94
|
+
});
|
|
95
|
+
const styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
|
|
96
|
+
const [frameWidth, setFrameInnerWidth] = React.useState(0);
|
|
97
|
+
const { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked], forwardedRef);
|
|
98
|
+
const nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
|
|
99
|
+
id: props.id,
|
|
100
|
+
disabled: props.disabled,
|
|
101
|
+
native,
|
|
102
|
+
nativeProps,
|
|
103
|
+
checked,
|
|
104
|
+
setChecked
|
|
105
|
+
});
|
|
106
|
+
if (nativeSwitch) {
|
|
107
|
+
return nativeSwitch;
|
|
108
|
+
}
|
|
109
|
+
const disabled = props.disabled;
|
|
110
|
+
const size = styledContext.size ?? props.size ?? true;
|
|
111
|
+
const handleLayout = (event) => {
|
|
112
|
+
const next = event.nativeEvent.layout.width;
|
|
113
|
+
if (next !== frameWidth) {
|
|
114
|
+
setFrameInnerWidth(next);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
|
|
118
|
+
ref: switchRef,
|
|
119
|
+
render: "button",
|
|
120
|
+
...import_core.isWeb && { type: "button" },
|
|
121
|
+
size,
|
|
122
|
+
...props,
|
|
123
|
+
...switchProps,
|
|
124
|
+
disabled,
|
|
125
|
+
...checked && activeStyle,
|
|
126
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
127
|
+
alignSelf: "stretch",
|
|
128
|
+
flex: 1,
|
|
129
|
+
onLayout: handleLayout,
|
|
130
|
+
children: props.children
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
const frameTheme = (checked ? activeTheme : void 0) ?? theme ?? createProps.componentThemes?.frame;
|
|
134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
135
|
+
size,
|
|
136
|
+
active: checked,
|
|
137
|
+
disabled,
|
|
138
|
+
frameWidth,
|
|
139
|
+
children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
140
|
+
name: frameTheme,
|
|
141
|
+
children: frame
|
|
142
|
+
}) : frame
|
|
143
|
+
}), bubbleInput] });
|
|
144
|
+
}, { disableTheme: true });
|
|
145
|
+
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
146
|
+
Frame,
|
|
147
|
+
Thumb: SwitchThumbComponent
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const Switch = createSwitch({
|
|
151
|
+
Frame: SwitchFrame,
|
|
152
|
+
Thumb: SwitchThumbFrame
|
|
153
|
+
});
|
|
154
|
+
const SwitchThumb = Switch.Thumb;
|
|
@@ -0,0 +1,163 @@
|
|
|
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 Switch_exports = {};
|
|
31
|
+
__export(Switch_exports, {
|
|
32
|
+
Switch: () => Switch,
|
|
33
|
+
SwitchFrame: () => SwitchFrame,
|
|
34
|
+
SwitchThumb: () => SwitchThumb,
|
|
35
|
+
SwitchThumbFrame: () => SwitchThumbFrame,
|
|
36
|
+
createSwitch: () => createSwitch
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(Switch_exports);
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
var import_core = require("@tamagui/core");
|
|
41
|
+
var import_switch_headless = require("@tamagui/switch-headless");
|
|
42
|
+
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
43
|
+
var React = __toESM(require("react"), 1);
|
|
44
|
+
var import_StyledContext = require("./StyledContext.native.js");
|
|
45
|
+
var import_useSwitchNative = require("./useSwitchNative.native.js");
|
|
46
|
+
var SwitchThumbFrame = (0, import_core.styled)(import_core.View, {
|
|
47
|
+
displayName: "SwitchThumb",
|
|
48
|
+
context: import_StyledContext.SwitchStyledContext
|
|
49
|
+
});
|
|
50
|
+
var SwitchFrame = (0, import_core.styled)(import_core.View, {
|
|
51
|
+
displayName: "Switch",
|
|
52
|
+
context: import_StyledContext.SwitchStyledContext,
|
|
53
|
+
render: "button",
|
|
54
|
+
tabIndex: 0
|
|
55
|
+
});
|
|
56
|
+
function createSwitch(createProps) {
|
|
57
|
+
var _createProps_Frame;
|
|
58
|
+
var Frame = (_createProps_Frame = createProps.Frame) !== null && _createProps_Frame !== void 0 ? _createProps_Frame : SwitchFrame;
|
|
59
|
+
var _createProps_Thumb;
|
|
60
|
+
var Thumb = (_createProps_Thumb = createProps.Thumb) !== null && _createProps_Thumb !== void 0 ? _createProps_Thumb : SwitchThumbFrame;
|
|
61
|
+
Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
62
|
+
Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
63
|
+
var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
64
|
+
var _createProps_componentThemes;
|
|
65
|
+
var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
|
|
66
|
+
var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
|
|
67
|
+
var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
68
|
+
var _ref;
|
|
69
|
+
var size = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref !== void 0 ? _ref : true;
|
|
70
|
+
var initialChecked = React.useRef(active).current;
|
|
71
|
+
var initialWidth = (0, import_core.getVariableValue)(props.width, "size");
|
|
72
|
+
var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
73
|
+
var distance = frameWidth - thumbWidth;
|
|
74
|
+
var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
75
|
+
var thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
|
|
76
|
+
ref: forwardedRef,
|
|
77
|
+
size,
|
|
78
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
79
|
+
x,
|
|
80
|
+
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(event) {
|
|
81
|
+
setThumbWidth(event.nativeEvent.layout.width);
|
|
82
|
+
}),
|
|
83
|
+
disabled,
|
|
84
|
+
...thumbProps,
|
|
85
|
+
...active && activeStyle
|
|
86
|
+
});
|
|
87
|
+
var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;
|
|
88
|
+
return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
89
|
+
name: themeName,
|
|
90
|
+
children: thumb
|
|
91
|
+
}) : thumb;
|
|
92
|
+
});
|
|
93
|
+
var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
|
|
94
|
+
var _createProps_componentThemes;
|
|
95
|
+
var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
|
|
96
|
+
var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
97
|
+
prop: checkedProp,
|
|
98
|
+
defaultProp: defaultChecked || false,
|
|
99
|
+
onChange: onCheckedChange,
|
|
100
|
+
transition: true
|
|
101
|
+
});
|
|
102
|
+
var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
|
|
103
|
+
var [frameWidth, setFrameInnerWidth] = React.useState(0);
|
|
104
|
+
var { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked], forwardedRef);
|
|
105
|
+
var nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
|
|
106
|
+
id: props.id,
|
|
107
|
+
disabled: props.disabled,
|
|
108
|
+
native,
|
|
109
|
+
nativeProps,
|
|
110
|
+
checked,
|
|
111
|
+
setChecked
|
|
112
|
+
});
|
|
113
|
+
if (nativeSwitch) {
|
|
114
|
+
return nativeSwitch;
|
|
115
|
+
}
|
|
116
|
+
var disabled = props.disabled;
|
|
117
|
+
var _styledContext_size, _ref;
|
|
118
|
+
var size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : true;
|
|
119
|
+
var handleLayout = function(event) {
|
|
120
|
+
var next = event.nativeEvent.layout.width;
|
|
121
|
+
if (next !== frameWidth) {
|
|
122
|
+
setFrameInnerWidth(next);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
|
|
126
|
+
ref: switchRef,
|
|
127
|
+
render: "button",
|
|
128
|
+
...import_core.isWeb && { type: "button" },
|
|
129
|
+
size,
|
|
130
|
+
...props,
|
|
131
|
+
...switchProps,
|
|
132
|
+
disabled,
|
|
133
|
+
...checked && activeStyle,
|
|
134
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
135
|
+
alignSelf: "stretch",
|
|
136
|
+
flex: 1,
|
|
137
|
+
onLayout: handleLayout,
|
|
138
|
+
children: props.children
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
var _ref1, _ref2;
|
|
142
|
+
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;
|
|
143
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
144
|
+
size,
|
|
145
|
+
active: checked,
|
|
146
|
+
disabled,
|
|
147
|
+
frameWidth,
|
|
148
|
+
children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
149
|
+
name: frameTheme,
|
|
150
|
+
children: frame
|
|
151
|
+
}) : frame
|
|
152
|
+
}), bubbleInput] });
|
|
153
|
+
}, { disableTheme: true });
|
|
154
|
+
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
155
|
+
Frame,
|
|
156
|
+
Thumb: SwitchThumbComponent
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
var Switch = createSwitch({
|
|
160
|
+
Frame: SwitchFrame,
|
|
161
|
+
Thumb: SwitchThumbFrame
|
|
162
|
+
});
|
|
163
|
+
var SwitchThumb = Switch.Thumb;
|