@tamagui/switch 1.61.2 → 1.62.0
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/Switch.js +12 -24
- package/dist/cjs/Switch.js.map +1 -1
- package/dist/cjs/Switch.native.js +99 -0
- package/dist/cjs/Switch.native.js.map +6 -0
- package/dist/cjs/createSwitch.js +64 -129
- package/dist/cjs/createSwitch.js.map +2 -2
- package/dist/cjs/createSwitch.native.js +196 -0
- package/dist/cjs/createSwitch.native.js.map +6 -0
- package/dist/cjs/index.js +4 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +22 -0
- package/dist/cjs/index.native.js.map +6 -0
- package/dist/esm/Switch.js +6 -11
- package/dist/esm/Switch.js.map +1 -1
- package/dist/esm/createSwitch.js +57 -107
- package/dist/esm/createSwitch.js.map +2 -2
- package/dist/jsx/Switch.js +6 -11
- package/dist/jsx/Switch.js.map +1 -1
- package/dist/jsx/Switch.native.js +79 -0
- package/dist/jsx/Switch.native.js.map +6 -0
- package/dist/jsx/createSwitch.js +51 -101
- package/dist/jsx/createSwitch.js.map +2 -2
- package/dist/jsx/createSwitch.native.js +172 -0
- package/dist/jsx/createSwitch.native.js.map +6 -0
- package/dist/jsx/index.native.js +3 -0
- package/dist/jsx/index.native.js.map +6 -0
- package/package.json +11 -11
package/dist/cjs/Switch.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
12
10
|
for (let key of __getOwnPropNames(from))
|
|
13
|
-
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
12
|
return to;
|
|
17
13
|
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value:
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
19
15
|
var Switch_exports = {};
|
|
20
16
|
__export(Switch_exports, {
|
|
21
17
|
Switch: () => Switch,
|
|
@@ -23,10 +19,7 @@ __export(Switch_exports, {
|
|
|
23
19
|
SwitchThumb: () => SwitchThumb
|
|
24
20
|
});
|
|
25
21
|
module.exports = __toCommonJS(Switch_exports);
|
|
26
|
-
var import_core = require("@tamagui/core");
|
|
27
|
-
var import_get_token = require("@tamagui/get-token");
|
|
28
|
-
var import_stacks = require("@tamagui/stacks");
|
|
29
|
-
var import_createSwitch = require("./createSwitch");
|
|
22
|
+
var import_core = require("@tamagui/core"), import_get_token = require("@tamagui/get-token"), import_stacks = require("@tamagui/stacks"), import_createSwitch = require("./createSwitch");
|
|
30
23
|
const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
31
24
|
name: "SwitchThumb",
|
|
32
25
|
context: import_createSwitch.SwitchContext,
|
|
@@ -49,12 +42,9 @@ const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
49
42
|
}
|
|
50
43
|
},
|
|
51
44
|
defaultVariants: {
|
|
52
|
-
unstyled:
|
|
45
|
+
unstyled: !1
|
|
53
46
|
}
|
|
54
|
-
})
|
|
55
|
-
const getSwitchHeight = (val) => Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.65);
|
|
56
|
-
const getSwitchWidth = (val) => getSwitchHeight(val) * 2;
|
|
57
|
-
const SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
47
|
+
}), getSwitchHeight = (val) => Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.65), getSwitchWidth = (val) => getSwitchHeight(val) * 2, SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
58
48
|
name: "Switch",
|
|
59
49
|
tag: "button",
|
|
60
50
|
context: import_createSwitch.SwitchContext,
|
|
@@ -82,8 +72,7 @@ const SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
|
82
72
|
},
|
|
83
73
|
size: {
|
|
84
74
|
"...size": (val) => {
|
|
85
|
-
const height = getSwitchHeight(val) + 4;
|
|
86
|
-
const width = getSwitchWidth(val) + 4;
|
|
75
|
+
const height = getSwitchHeight(val) + 4, width = getSwitchWidth(val) + 4;
|
|
87
76
|
return {
|
|
88
77
|
height,
|
|
89
78
|
minHeight: height,
|
|
@@ -93,13 +82,12 @@ const SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
|
93
82
|
}
|
|
94
83
|
},
|
|
95
84
|
defaultVariants: {
|
|
96
|
-
unstyled:
|
|
85
|
+
unstyled: !1
|
|
97
86
|
}
|
|
98
|
-
})
|
|
99
|
-
const Switch = (0, import_createSwitch.createSwitch)({
|
|
87
|
+
}), Switch = (0, import_createSwitch.createSwitch)({
|
|
100
88
|
Frame: SwitchFrame,
|
|
101
89
|
Thumb: SwitchThumb,
|
|
102
|
-
acceptsUnstyled:
|
|
90
|
+
acceptsUnstyled: !0
|
|
103
91
|
});
|
|
104
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
105
93
|
0 && (module.exports = {
|
package/dist/cjs/Switch.js.map
CHANGED
|
@@ -1,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AAM;AAAA,IACnB;AAAA,IAEA,MAAM;AAAA,MACJ,WAAW,CAAC,QAAQ;AAClB,cAAM,SAAS,gBAAgB,GAAG,IAAI,GAChC,QAAQ,eAAe,GAAG,IAAI;AACpC,eAAO;AAAA,UACL;AAAA,UACA,WAAW;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC,GAEY,aAAS,kCAAa;AAAA,EACjC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,iBAAiB;AACnB,CAAC;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
+
var Switch_exports = {};
|
|
17
|
+
__export(Switch_exports, {
|
|
18
|
+
Switch: () => Switch,
|
|
19
|
+
SwitchFrame: () => SwitchFrame,
|
|
20
|
+
SwitchThumb: () => SwitchThumb
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(Switch_exports);
|
|
23
|
+
var import_core = require("@tamagui/core"), import_get_token = require("@tamagui/get-token"), import_stacks = require("@tamagui/stacks"), import_createSwitch = require("./createSwitch");
|
|
24
|
+
const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
25
|
+
name: "SwitchThumb",
|
|
26
|
+
context: import_createSwitch.SwitchContext,
|
|
27
|
+
variants: {
|
|
28
|
+
unstyled: {
|
|
29
|
+
false: {
|
|
30
|
+
size: "$true",
|
|
31
|
+
backgroundColor: "$background",
|
|
32
|
+
borderRadius: 1e3
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
size: {
|
|
36
|
+
"...size": (val) => {
|
|
37
|
+
const size = getSwitchHeight(val);
|
|
38
|
+
return {
|
|
39
|
+
height: size,
|
|
40
|
+
width: size
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
defaultVariants: {
|
|
46
|
+
unstyled: !1
|
|
47
|
+
}
|
|
48
|
+
}), getSwitchHeight = (val) => Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.65), getSwitchWidth = (val) => getSwitchHeight(val) * 2, SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
49
|
+
name: "Switch",
|
|
50
|
+
tag: "button",
|
|
51
|
+
context: import_createSwitch.SwitchContext,
|
|
52
|
+
variants: {
|
|
53
|
+
unstyled: {
|
|
54
|
+
false: {
|
|
55
|
+
size: "$true",
|
|
56
|
+
borderRadius: 1e3,
|
|
57
|
+
borderWidth: 2,
|
|
58
|
+
borderColor: "transparent",
|
|
59
|
+
backgroundColor: "$background",
|
|
60
|
+
focusStyle: {
|
|
61
|
+
borderColor: "$borderColorFocus",
|
|
62
|
+
outlineColor: "$borderColorFocus",
|
|
63
|
+
outlineStyle: "solid",
|
|
64
|
+
outlineWidth: 1
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
checked: {
|
|
69
|
+
true: {}
|
|
70
|
+
},
|
|
71
|
+
frameWidth: {
|
|
72
|
+
":number": () => null
|
|
73
|
+
},
|
|
74
|
+
size: {
|
|
75
|
+
"...size": (val) => {
|
|
76
|
+
const height = getSwitchHeight(val) + 4, width = getSwitchWidth(val) + 4;
|
|
77
|
+
return {
|
|
78
|
+
height,
|
|
79
|
+
minHeight: height,
|
|
80
|
+
width
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
defaultVariants: {
|
|
86
|
+
unstyled: !1
|
|
87
|
+
}
|
|
88
|
+
}), Switch = (0, import_createSwitch.createSwitch)({
|
|
89
|
+
Frame: SwitchFrame,
|
|
90
|
+
Thumb: SwitchThumb,
|
|
91
|
+
acceptsUnstyled: !0
|
|
92
|
+
});
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
Switch,
|
|
96
|
+
SwitchFrame,
|
|
97
|
+
SwitchThumb
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=Switch.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Switch.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD,0BACrD,mBAAwB,+BACxB,gBAAuC,4BAEvC,sBAA4C;AAErC,MAAM,kBAAc,oBAAO,8BAAgB;AAAA,EAChD,MAAM;AAAA,EACN,SAAS;AAAA,EAET,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB,cAAc;AAAA,MAChB;AAAA,IACF;AAAA,IAEA,MAAM;AAAA,MACJ,WAAW,CAAC,QAAQ;AAClB,cAAM,OAAO,gBAAgB,GAAG;AAChC,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC,GAEK,kBAAkB,CAAC,QACvB,KAAK,UAAM,kCAAiB,0BAAQ,GAAG,CAAC,IAAI,IAAI,GAE5C,iBAAiB,CAAC,QAAoB,gBAAgB,GAAG,IAAI,GAEtD,kBAAc,oBAAO,sBAAQ;AAAA,EACxC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,SAAS;AAAA,EAET,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,QACN,cAAc;AAAA,QACd,aAAa;AAAA,QACb,aAAa;AAAA,QACb,iBAAiB;AAAA,QAEjB,YAAY;AAAA,UACV,aAAa;AAAA,UACb,cAAc;AAAA,UACd,cAAc;AAAA,UACd,cAAc;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,IAEA,SAAS;AAAA,MACP,MAAM,CAAC;AAAA,IACT;AAAA,IAEA,YAAY;AAAA,MACV,WAAW,MAAM;AAAA,IACnB;AAAA,IAEA,MAAM;AAAA,MACJ,WAAW,CAAC,QAAQ;AAClB,cAAM,SAAS,gBAAgB,GAAG,IAAI,GAChC,QAAQ,eAAe,GAAG,IAAI;AACpC,eAAO;AAAA,UACL;AAAA,UACA,WAAW;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC,GAEY,aAAS,kCAAa;AAAA,EACjC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,iBAAiB;AACnB,CAAC;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/cjs/createSwitch.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
14
11
|
for (let key of __getOwnPropNames(from))
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
13
|
return to;
|
|
19
14
|
};
|
|
20
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
@@ -22,47 +17,33 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
17
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
18
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
19
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
26
21
|
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
29
23
|
var createSwitch_exports = {};
|
|
30
24
|
__export(createSwitch_exports, {
|
|
31
25
|
SwitchContext: () => SwitchContext,
|
|
32
26
|
createSwitch: () => createSwitch
|
|
33
27
|
});
|
|
34
28
|
module.exports = __toCommonJS(createSwitch_exports);
|
|
35
|
-
var import_jsx_runtime = (
|
|
29
|
+
var import_compose_refs = require("@tamagui/compose-refs"), import_core = require("@tamagui/core"), import_focusable = require("@tamagui/focusable"), import_get_token = require("@tamagui/get-token"), import_label = require("@tamagui/label"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_use_previous = require("@tamagui/use-previous"), React = __toESM(require("react")), import_react_native = require("react-native"), import_jsx_runtime = (
|
|
36
30
|
// @ts-ignore
|
|
37
31
|
require("react/jsx-runtime")
|
|
38
32
|
);
|
|
39
|
-
var import_compose_refs = require("@tamagui/compose-refs");
|
|
40
|
-
var import_core = require("@tamagui/core");
|
|
41
|
-
var import_focusable = require("@tamagui/focusable");
|
|
42
|
-
var import_get_token = require("@tamagui/get-token");
|
|
43
|
-
var import_label = require("@tamagui/label");
|
|
44
|
-
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
45
|
-
var import_use_previous = require("@tamagui/use-previous");
|
|
46
|
-
var React = __toESM(require("react"));
|
|
47
|
-
var import_react_native = require("react-native");
|
|
48
33
|
const SwitchContext = (0, import_core.createStyledContext)({
|
|
49
|
-
checked:
|
|
50
|
-
disabled:
|
|
34
|
+
checked: !1,
|
|
35
|
+
disabled: !1,
|
|
51
36
|
size: void 0,
|
|
52
37
|
frameWidth: 0,
|
|
53
|
-
unstyled:
|
|
38
|
+
unstyled: !1
|
|
54
39
|
});
|
|
55
40
|
function createSwitch({ Frame, Thumb, acceptsUnstyled }) {
|
|
56
|
-
const SwitchThumb = Thumb.styleable(function
|
|
57
|
-
const { size: sizeProp, ...thumbProps } = props;
|
|
58
|
-
const { disabled, checked, unstyled, frameWidth } = React.useContext(SwitchContext);
|
|
59
|
-
const [thumbWidth, setThumbWidth] = React.useState(0);
|
|
60
|
-
const initialChecked = React.useRef(checked).current;
|
|
61
|
-
const distance = frameWidth - thumbWidth;
|
|
41
|
+
const SwitchThumb = Thumb.styleable(function(props, forwardedRef) {
|
|
42
|
+
const { size: sizeProp, ...thumbProps } = props, { disabled, checked, unstyled, frameWidth } = React.useContext(SwitchContext), [thumbWidth, setThumbWidth] = React.useState(0), initialChecked = React.useRef(checked).current, distance = frameWidth - thumbWidth;
|
|
62
43
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
63
44
|
Thumb,
|
|
64
45
|
{
|
|
65
|
-
theme: unstyled ===
|
|
46
|
+
theme: unstyled === !1 && checked ? "active" : null,
|
|
66
47
|
"data-state": getState(checked),
|
|
67
48
|
"data-disabled": disabled ? "" : void 0,
|
|
68
49
|
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
@@ -78,12 +59,9 @@ function createSwitch({ Frame, Thumb, acceptsUnstyled }) {
|
|
|
78
59
|
ref: forwardedRef
|
|
79
60
|
}
|
|
80
61
|
);
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const styledContext = React.useContext(SwitchContext);
|
|
85
|
-
const props = (0, import_core.useProps)(propsIn);
|
|
86
|
-
const {
|
|
62
|
+
}), SwitchComponent = Frame.extractable(
|
|
63
|
+
React.forwardRef(function(propsIn, forwardedRef) {
|
|
64
|
+
const styledContext = React.useContext(SwitchContext), props = (0, import_core.useProps)(propsIn), {
|
|
87
65
|
labeledBy: ariaLabelledby,
|
|
88
66
|
name,
|
|
89
67
|
checked: checkedProp,
|
|
@@ -93,63 +71,36 @@ function createSwitch({ Frame, Thumb, acceptsUnstyled }) {
|
|
|
93
71
|
value = "on",
|
|
94
72
|
onCheckedChange,
|
|
95
73
|
size = styledContext.size ?? "$true",
|
|
96
|
-
unstyled = styledContext.unstyled ??
|
|
74
|
+
unstyled = styledContext.unstyled ?? !1,
|
|
97
75
|
native: nativeProp,
|
|
98
76
|
nativeProps,
|
|
99
77
|
...switchProps
|
|
100
|
-
} = props
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (acceptsUnstyled && _ === void 0 && unstyled === false) {
|
|
109
|
-
_ = 2;
|
|
110
|
-
}
|
|
111
|
-
if (typeof _ === "string") {
|
|
112
|
-
_ = (0, import_core.getVariableValue)((0, import_get_token.getSize)(_));
|
|
113
|
-
}
|
|
114
|
-
return +_;
|
|
115
|
-
})();
|
|
116
|
-
const native = Array.isArray(nativeProp) ? nativeProp : [nativeProp];
|
|
117
|
-
const shouldRenderMobileNative = !import_core.isWeb && nativeProp === true || !import_core.isWeb && native.includes("mobile") || native.includes("android") && import_react_native.Platform.OS === "android" || native.includes("ios") && import_react_native.Platform.OS === "ios";
|
|
118
|
-
const [button, setButton] = React.useState(null);
|
|
119
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => setButton(node));
|
|
120
|
-
const labelId = (0, import_label.useLabelContext)(button);
|
|
121
|
-
const labelledBy = ariaLabelledby || labelId;
|
|
122
|
-
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
123
|
-
const isFormControl = import_core.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
124
|
-
const [frameWidth, setFrameWidth] = React.useState(0);
|
|
125
|
-
const [checked = false, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
78
|
+
} = props, leftBorderWidth = (() => {
|
|
79
|
+
let _;
|
|
80
|
+
for (const key in switchProps)
|
|
81
|
+
(key === "borderWidth" || key === "borderLeftWidth") && (_ = switchProps[key]);
|
|
82
|
+
return acceptsUnstyled && _ === void 0 && unstyled === !1 && (_ = 2), typeof _ == "string" && (_ = (0, import_core.getVariableValue)((0, import_get_token.getSize)(_))), +_;
|
|
83
|
+
})(), native = Array.isArray(nativeProp) ? nativeProp : [nativeProp], shouldRenderMobileNative = !import_core.isWeb && nativeProp === !0 || !import_core.isWeb && native.includes("mobile") || native.includes("android") && import_react_native.Platform.OS === "android" || native.includes("ios") && import_react_native.Platform.OS === "ios", [button, setButton] = React.useState(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => setButton(node)), labelId = (0, import_label.useLabelContext)(button), labelledBy = ariaLabelledby || labelId, hasConsumerStoppedPropagationRef = React.useRef(!1), isFormControl = import_core.isWeb ? button ? !!button.closest("form") : !0 : !1, [frameWidth, setFrameWidth] = React.useState(0), [checked = !1, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
126
84
|
prop: checkedProp,
|
|
127
|
-
defaultProp: defaultChecked ||
|
|
85
|
+
defaultProp: defaultChecked || !1,
|
|
128
86
|
onChange: onCheckedChange,
|
|
129
|
-
transition:
|
|
87
|
+
transition: !0
|
|
130
88
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
if (!import_core.isWeb) {
|
|
142
|
-
React.useEffect(() => {
|
|
143
|
-
if (!props.id)
|
|
144
|
-
return;
|
|
89
|
+
return shouldRenderMobileNative ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
90
|
+
import_react_native.Switch,
|
|
91
|
+
{
|
|
92
|
+
value: checkedProp,
|
|
93
|
+
onValueChange: onCheckedChange,
|
|
94
|
+
...nativeProps
|
|
95
|
+
}
|
|
96
|
+
) : (import_core.isWeb || React.useEffect(() => {
|
|
97
|
+
if (props.id)
|
|
145
98
|
return (0, import_focusable.registerFocusable)(props.id, {
|
|
146
99
|
focus: () => {
|
|
147
100
|
setChecked((x) => !x);
|
|
148
101
|
}
|
|
149
102
|
});
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
103
|
+
}, [props.id, setChecked]), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
153
104
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
154
105
|
Frame,
|
|
155
106
|
{
|
|
@@ -159,7 +110,7 @@ function createSwitch({ Frame, Thumb, acceptsUnstyled }) {
|
|
|
159
110
|
disabled,
|
|
160
111
|
frameWidth: frameWidth ? frameWidth - leftBorderWidth * 2 : 0,
|
|
161
112
|
theme: checked ? "active" : null,
|
|
162
|
-
themeShallow:
|
|
113
|
+
themeShallow: !0,
|
|
163
114
|
role: "switch",
|
|
164
115
|
"aria-checked": checked,
|
|
165
116
|
"aria-labelledby": labelledBy,
|
|
@@ -171,12 +122,7 @@ function createSwitch({ Frame, Thumb, acceptsUnstyled }) {
|
|
|
171
122
|
...switchProps,
|
|
172
123
|
ref: composedRefs,
|
|
173
124
|
onPress: (0, import_core.composeEventHandlers)(props.onPress, (event) => {
|
|
174
|
-
setChecked((prevChecked) => !prevChecked);
|
|
175
|
-
if (import_core.isWeb && isFormControl) {
|
|
176
|
-
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
177
|
-
if (!hasConsumerStoppedPropagationRef.current)
|
|
178
|
-
event.stopPropagation();
|
|
179
|
-
}
|
|
125
|
+
setChecked((prevChecked) => !prevChecked), import_core.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
180
126
|
}),
|
|
181
127
|
onLayout: (0, import_core.composeEventHandlers)(
|
|
182
128
|
props.onLayout,
|
|
@@ -200,57 +146,46 @@ function createSwitch({ Frame, Thumb, acceptsUnstyled }) {
|
|
|
200
146
|
style: { transform: "translateX(-100%)" }
|
|
201
147
|
}
|
|
202
148
|
)
|
|
203
|
-
] });
|
|
149
|
+
] }));
|
|
204
150
|
})
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const prevChecked = (0, import_use_previous.usePrevious)(checked);
|
|
210
|
-
React.useEffect(() => {
|
|
211
|
-
const input = ref.current;
|
|
212
|
-
const inputProto = window.HTMLInputElement.prototype;
|
|
213
|
-
const descriptor = Object.getOwnPropertyDescriptor(
|
|
151
|
+
), BubbleInput = (props) => {
|
|
152
|
+
const { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
|
|
153
|
+
return React.useEffect(() => {
|
|
154
|
+
const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
|
|
214
155
|
inputProto,
|
|
215
156
|
"checked"
|
|
216
|
-
);
|
|
217
|
-
const setChecked = descriptor.set;
|
|
157
|
+
).set;
|
|
218
158
|
if (prevChecked !== checked && setChecked) {
|
|
219
159
|
const event = new Event("click", { bubbles });
|
|
220
|
-
setChecked.call(input, checked);
|
|
221
|
-
input.dispatchEvent(event);
|
|
160
|
+
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
222
161
|
}
|
|
223
|
-
}, [prevChecked, checked, bubbles])
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
"
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
opacity: 0,
|
|
241
|
-
margin: 0
|
|
242
|
-
}
|
|
162
|
+
}, [prevChecked, checked, bubbles]), // @ts-ignore
|
|
163
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
164
|
+
"input",
|
|
165
|
+
{
|
|
166
|
+
type: "checkbox",
|
|
167
|
+
"aria-hidden": !0,
|
|
168
|
+
defaultChecked: checked,
|
|
169
|
+
...inputProps,
|
|
170
|
+
tabIndex: -1,
|
|
171
|
+
ref,
|
|
172
|
+
style: {
|
|
173
|
+
...props.style,
|
|
174
|
+
// ...controlSize,
|
|
175
|
+
position: "absolute",
|
|
176
|
+
pointerEvents: "none",
|
|
177
|
+
opacity: 0,
|
|
178
|
+
margin: 0
|
|
243
179
|
}
|
|
244
|
-
|
|
180
|
+
}
|
|
245
181
|
);
|
|
246
182
|
};
|
|
247
183
|
function getState(checked) {
|
|
248
184
|
return checked ? "checked" : "unchecked";
|
|
249
185
|
}
|
|
250
|
-
|
|
186
|
+
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
251
187
|
Thumb: SwitchThumb
|
|
252
188
|
});
|
|
253
|
-
return Switch;
|
|
254
189
|
}
|
|
255
190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
256
191
|
0 && (module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createSwitch.tsx"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": ["
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC,kCAChC,cAYO,0BACP,mBAAkC,+BAClC,mBAAwB,+BACxB,eAAgC,2BAChC,gCAAqC,4CACrC,sBAA4B,kCAC5B,QAAuB,2BACvB,sBAIO,yBAoDD;AAAA;AAAA;AAAA;AAlDC,MAAM,oBAAgB,iCAM1B;AAAA,EACD,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,UAAU;AACZ,CAAC;AAuBM,SAAS,aAMd,EAAE,OAAO,OAAO,gBAAgB,GAAsD;AACtF,QAAM,cAAc,MAAM,UAAU,SAAqB,OAAO,cAAc;AAC5E,UAAM,EAAE,MAAM,UAAU,GAAG,WAAW,IAAI,OACpC,EAAE,UAAU,SAAS,UAAU,WAAW,IAAI,MAAM,WAAW,aAAa,GA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