@tamagui/switch 1.89.26 → 1.89.27-1708112217600
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.native.js +1 -2
- package/dist/cjs/StyledContext.native.js.map +3 -3
- package/dist/cjs/Switch.native.js +10 -7
- package/dist/cjs/Switch.native.js.map +3 -3
- package/dist/cjs/createSwitch.native.js +189 -103
- package/dist/cjs/createSwitch.native.js.map +3 -3
- package/dist/cjs/index.native.js +1 -1
- package/dist/cjs/index.native.js.map +3 -3
- package/dist/esm/StyledContext.native.js +1 -1
- package/dist/esm/StyledContext.native.js.map +3 -3
- package/dist/esm/Switch.native.js +10 -6
- package/dist/esm/Switch.native.js.map +3 -3
- package/dist/esm/createSwitch.native.js +189 -111
- package/dist/esm/createSwitch.native.js.map +3 -3
- package/dist/esm/index.native.js +1 -1
- package/dist/esm/index.native.js.map +3 -3
- package/dist/jsx/StyledContext.native.js +1 -1
- package/dist/jsx/StyledContext.native.js.map +3 -3
- package/dist/jsx/Switch.native.js +10 -6
- package/dist/jsx/Switch.native.js.map +3 -3
- package/dist/jsx/createSwitch.native.js +189 -111
- package/dist/jsx/createSwitch.native.js.map +3 -3
- package/dist/jsx/index.native.js +1 -1
- package/dist/jsx/index.native.js.map +3 -3
- package/package.json +14 -14
|
@@ -18,8 +18,7 @@ __export(StyledContext_exports, {
|
|
|
18
18
|
SwitchStyledContext: () => SwitchStyledContext
|
|
19
19
|
});
|
|
20
20
|
module.exports = __toCommonJS(StyledContext_exports);
|
|
21
|
-
var import_core = require("@tamagui/core")
|
|
22
|
-
const SwitchStyledContext = (0, import_core.createStyledContext)({
|
|
21
|
+
var import_core = require("@tamagui/core"), SwitchStyledContext = (0, import_core.createStyledContext)({
|
|
23
22
|
size: void 0,
|
|
24
23
|
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
25
24
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/StyledContext.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch/src/StyledContext.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AACA;;;;;kBAAoC,0BAEvBA,0BAAsBC,iCAGhC;EACDC,MAAMC;EACNC,UAAUC,QAAQC,IAAIC,qBAAqB;AAC7C,CAAA;",
|
|
5
|
+
"names": ["SwitchStyledContext", "createStyledContext", "size", "undefined", "unstyled", "process", "env", "TAMAGUI_HEADLESS"]
|
|
6
6
|
}
|
|
@@ -19,8 +19,7 @@ __export(Switch_exports, {
|
|
|
19
19
|
SwitchThumb: () => SwitchThumb
|
|
20
20
|
});
|
|
21
21
|
module.exports = __toCommonJS(Switch_exports);
|
|
22
|
-
var import_core = require("@tamagui/core"), import_get_token = require("@tamagui/get-token"), import_stacks = require("@tamagui/stacks"), import_StyledContext = require("./StyledContext")
|
|
23
|
-
const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
22
|
+
var import_core = require("@tamagui/core"), import_get_token = require("@tamagui/get-token"), import_stacks = require("@tamagui/stacks"), import_StyledContext = require("./StyledContext"), SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
24
23
|
name: "SwitchThumb",
|
|
25
24
|
context: import_StyledContext.SwitchStyledContext,
|
|
26
25
|
variants: {
|
|
@@ -35,8 +34,8 @@ const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
35
34
|
true: {}
|
|
36
35
|
},
|
|
37
36
|
size: {
|
|
38
|
-
"...size": (val)
|
|
39
|
-
|
|
37
|
+
"...size": function(val) {
|
|
38
|
+
var size = getSwitchHeight(val);
|
|
40
39
|
return {
|
|
41
40
|
height: size,
|
|
42
41
|
width: size
|
|
@@ -47,7 +46,11 @@ const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
47
46
|
defaultVariants: {
|
|
48
47
|
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
49
48
|
}
|
|
50
|
-
}), getSwitchHeight = (val)
|
|
49
|
+
}), getSwitchHeight = function(val) {
|
|
50
|
+
return Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.65);
|
|
51
|
+
}, getSwitchWidth = function(val) {
|
|
52
|
+
return getSwitchHeight(val) * 2;
|
|
53
|
+
}, SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
51
54
|
name: "Switch",
|
|
52
55
|
tag: "button",
|
|
53
56
|
context: import_StyledContext.SwitchStyledContext,
|
|
@@ -69,8 +72,8 @@ const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
69
72
|
true: {}
|
|
70
73
|
},
|
|
71
74
|
size: {
|
|
72
|
-
"...size": (val)
|
|
73
|
-
|
|
75
|
+
"...size": function(val) {
|
|
76
|
+
var height = getSwitchHeight(val) + 4, width = getSwitchWidth(val) + 4;
|
|
74
77
|
return {
|
|
75
78
|
height,
|
|
76
79
|
minHeight: height,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/Switch.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch/src/Switch.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AACA;;;;;;kBAAyC,0BACzC,mBAAwB,+BACxB,gBAAuC,4BAEvC,uBAAoC,4BAEvBA,kBAAcC,oBAAOC,8BAAgB;EAChDC,MAAM;EACNC,SAASC;EAETC,UAAU;IACRC,UAAU;MACRC,OAAO;QACLC,MAAM;QACNC,iBAAiB;QACjBC,cAAc;MAChB;IACF;IAEAC,SAAS;MACPC,MAAM,CAAC;IACT;IAEAJ,MAAM;MACJ,WAAW,SAACK,KAAAA;AACV,YAAML,OAAOM,gBAAgBD,GAAAA;AAC7B,eAAO;UACLE,QAAQP;UACRQ,OAAOR;QACT;MACF;IACF;EACF;EAEAS,iBAAiB;IACfX,UAAUY,QAAQC,IAAIC,qBAAqB;EAC7C;AACF,CAAA,GAEMN,kBAAkB,SAACD,KAAAA;SACvBQ,KAAKC,UAAMC,kCAAiBC,0BAAQX,GAAAA,CAAAA,IAAQ,IAAA;GAExCY,iBAAiB,SAACZ,KAAAA;SAAoBC,gBAAgBD,GAAAA,IAAO;GAEtDa,kBAAc1B,oBAAO2B,sBAAQ;EACxCzB,MAAM;EACN0B,KAAK;EACLzB,SAASC;EAETC,UAAU;IACRC,UAAU;MACRC,OAAO;QACLG,cAAc;QACdD,iBAAiB;QACjBoB,aAAa;QACbC,aAAa;QAEbC,YAAY;UACVC,cAAc;UACdC,cAAc;UACdC,cAAc;QAChB;MACF;IACF;IAEAvB,SAAS;MACPC,MAAM,CAAC;IACT;IAEAJ,MAAM;MACJ,WAAW,SAACK,KAAAA;AACV,YAAME,SAASD,gBAAgBD,GAAAA,IAAO,GAChCG,QAAQS,eAAeZ,GAAAA,IAAO;AACpC,eAAO;UACLE;UACAoB,WAAWpB;UACXC;QACF;MACF;IACF;EACF;EAEAC,iBAAiB;IACfX,UAAUY,QAAQC,IAAIC,qBAAqB;EAC7C;AACF,CAAA;",
|
|
5
|
+
"names": ["SwitchThumb", "styled", "ThemeableStack", "name", "context", "SwitchStyledContext", "variants", "unstyled", "false", "size", "backgroundColor", "borderRadius", "checked", "true", "val", "getSwitchHeight", "height", "width", "defaultVariants", "process", "env", "TAMAGUI_HEADLESS", "Math", "round", "getVariableValue", "getSize", "getSwitchWidth", "SwitchFrame", "YStack", "tag", "borderWidth", "borderColor", "focusStyle", "outlineColor", "outlineStyle", "outlineWidth", "minHeight"]
|
|
6
6
|
}
|
|
@@ -27,114 +27,200 @@ __export(createSwitch_exports, {
|
|
|
27
27
|
createSwitch: () => createSwitch
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(createSwitch_exports);
|
|
30
|
-
var import_core = require("@tamagui/core"), import_switch_headless = require("@tamagui/switch-headless"), import_use_controllable_state = require("@tamagui/use-controllable-state"), React = __toESM(require("react")), import_react_native = require("react-native"), import_StyledContext = require("./StyledContext"), import_Switch = require("./Switch")
|
|
31
|
-
|
|
30
|
+
var import_core = require("@tamagui/core"), import_switch_headless = require("@tamagui/switch-headless"), import_use_controllable_state = require("@tamagui/use-controllable-state"), React = __toESM(require("react")), import_react_native = require("react-native"), import_StyledContext = require("./StyledContext"), import_Switch = require("./Switch");
|
|
31
|
+
function _array_like_to_array(arr, len) {
|
|
32
|
+
(len == null || len > arr.length) && (len = arr.length);
|
|
33
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
34
|
+
arr2[i] = arr[i];
|
|
35
|
+
return arr2;
|
|
36
|
+
}
|
|
37
|
+
function _array_with_holes(arr) {
|
|
38
|
+
if (Array.isArray(arr))
|
|
39
|
+
return arr;
|
|
40
|
+
}
|
|
41
|
+
function _define_property(obj, key, value) {
|
|
42
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
43
|
+
value,
|
|
44
|
+
enumerable: !0,
|
|
45
|
+
configurable: !0,
|
|
46
|
+
writable: !0
|
|
47
|
+
}) : obj[key] = value, obj;
|
|
48
|
+
}
|
|
49
|
+
function _iterable_to_array_limit(arr, i) {
|
|
50
|
+
var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
51
|
+
if (_i != null) {
|
|
52
|
+
var _arr = [], _n = !0, _d = !1, _s, _e;
|
|
53
|
+
try {
|
|
54
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
|
|
55
|
+
;
|
|
56
|
+
} catch (err) {
|
|
57
|
+
_d = !0, _e = err;
|
|
58
|
+
} finally {
|
|
59
|
+
try {
|
|
60
|
+
!_n && _i.return != null && _i.return();
|
|
61
|
+
} finally {
|
|
62
|
+
if (_d)
|
|
63
|
+
throw _e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return _arr;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function _non_iterable_rest() {
|
|
70
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
71
|
+
}
|
|
72
|
+
function _object_spread(target) {
|
|
73
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
74
|
+
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
75
|
+
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
76
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
77
|
+
}))), ownKeys2.forEach(function(key) {
|
|
78
|
+
_define_property(target, key, source[key]);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return target;
|
|
82
|
+
}
|
|
83
|
+
function ownKeys(object, enumerableOnly) {
|
|
84
|
+
var keys = Object.keys(object);
|
|
85
|
+
if (Object.getOwnPropertySymbols) {
|
|
86
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
87
|
+
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
88
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
89
|
+
})), keys.push.apply(keys, symbols);
|
|
90
|
+
}
|
|
91
|
+
return keys;
|
|
92
|
+
}
|
|
93
|
+
function _object_spread_props(target, source) {
|
|
94
|
+
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
95
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
96
|
+
}), target;
|
|
97
|
+
}
|
|
98
|
+
function _object_without_properties(source, excluded) {
|
|
99
|
+
if (source == null)
|
|
100
|
+
return {};
|
|
101
|
+
var target = _object_without_properties_loose(source, excluded), key, i;
|
|
102
|
+
if (Object.getOwnPropertySymbols) {
|
|
103
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
104
|
+
for (i = 0; i < sourceSymbolKeys.length; i++)
|
|
105
|
+
key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
|
|
106
|
+
}
|
|
107
|
+
return target;
|
|
108
|
+
}
|
|
109
|
+
function _object_without_properties_loose(source, excluded) {
|
|
110
|
+
if (source == null)
|
|
111
|
+
return {};
|
|
112
|
+
var target = {}, sourceKeys = Object.keys(source), key, i;
|
|
113
|
+
for (i = 0; i < sourceKeys.length; i++)
|
|
114
|
+
key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
|
|
115
|
+
return target;
|
|
116
|
+
}
|
|
117
|
+
function _sliced_to_array(arr, i) {
|
|
118
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
119
|
+
}
|
|
120
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
121
|
+
if (o) {
|
|
122
|
+
if (typeof o == "string")
|
|
123
|
+
return _array_like_to_array(o, minLen);
|
|
124
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
125
|
+
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
|
|
126
|
+
return Array.from(n);
|
|
127
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
128
|
+
return _array_like_to_array(o, minLen);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
var SwitchContext = /* @__PURE__ */ React.createContext({
|
|
32
132
|
checked: !1,
|
|
33
133
|
disabled: !1,
|
|
34
134
|
frameWidth: 0
|
|
35
135
|
});
|
|
36
136
|
function createSwitch(createProps) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
children: switchProps.children
|
|
125
|
-
}
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
),
|
|
129
|
-
bubbleInput
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
disableTheme: !0
|
|
136
|
-
}
|
|
137
|
-
);
|
|
137
|
+
var disableActiveTheme = createProps.disableActiveTheme, _createProps_Frame = createProps.Frame, Frame = _createProps_Frame === void 0 ? import_Switch.SwitchFrame : _createProps_Frame, _createProps_Thumb = createProps.Thumb, Thumb = _createProps_Thumb === void 0 ? import_Switch.SwitchThumb : _createProps_Thumb;
|
|
138
|
+
process.env.NODE_ENV === "development" && (Frame !== import_Switch.SwitchFrame && Frame.staticConfig.context || Thumb !== import_Switch.SwitchThumb && Thumb.staticConfig.context) && console.warn("Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden."), Frame.staticConfig.context = import_StyledContext.SwitchStyledContext, Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
139
|
+
var SwitchThumbComponent = Thumb.styleable(function(props, forwardedRef) {
|
|
140
|
+
var sizeProp = props.size, unstyledProp = props.unstyled, nativeID = props.nativeID, thumbProps = _object_without_properties(props, [
|
|
141
|
+
"size",
|
|
142
|
+
"unstyled",
|
|
143
|
+
"nativeID"
|
|
144
|
+
]), context = React.useContext(SwitchContext), checked = context.checked, disabled = context.disabled, frameWidth = context.frameWidth, styledContext = import_StyledContext.SwitchStyledContext.useStyledContext(), unstyledContext = styledContext.unstyled, sizeContext = styledContext.size, _ref, unstyled = process.env.TAMAGUI_HEADLESS === "1" ? !0 : (_ref = unstyledProp ?? unstyledContext) !== null && _ref !== void 0 ? _ref : !1, _ref1, size = (_ref1 = sizeProp ?? sizeContext) !== null && _ref1 !== void 0 ? _ref1 : "$true", initialChecked = React.useRef(checked).current, _React_useState = _sliced_to_array(React.useState(0), 2), thumbWidth = _React_useState[0], setThumbWidth = _React_useState[1], distance = frameWidth - thumbWidth, x = initialChecked ? checked ? 0 : -distance : checked ? distance : 0;
|
|
145
|
+
return /* @__PURE__ */ React.createElement(Thumb, _object_spread(_object_spread_props(_object_spread({
|
|
146
|
+
ref: forwardedRef,
|
|
147
|
+
unstyled
|
|
148
|
+
}, unstyled === !1 && _object_spread({
|
|
149
|
+
size
|
|
150
|
+
}, !disableActiveTheme && {
|
|
151
|
+
theme: checked ? "active" : null
|
|
152
|
+
})), {
|
|
153
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
154
|
+
x,
|
|
155
|
+
// TODO: remove ViewProps cast
|
|
156
|
+
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(e) {
|
|
157
|
+
return setThumbWidth(e.nativeEvent.layout.width);
|
|
158
|
+
}),
|
|
159
|
+
// expected variants
|
|
160
|
+
checked,
|
|
161
|
+
disabled
|
|
162
|
+
}), thumbProps));
|
|
163
|
+
}), SwitchComponent = Frame.styleable(function(_props, forwardedRef) {
|
|
164
|
+
var native = _props.native, nativeProps = _props.nativeProps, checkedProp = _props.checked, defaultChecked = _props.defaultChecked, onCheckedChange = _props.onCheckedChange, props = _object_without_properties(_props, [
|
|
165
|
+
"native",
|
|
166
|
+
"nativeProps",
|
|
167
|
+
"checked",
|
|
168
|
+
"defaultChecked",
|
|
169
|
+
"onCheckedChange"
|
|
170
|
+
]), _useControllableState = _sliced_to_array((0, import_use_controllable_state.useControllableState)({
|
|
171
|
+
prop: checkedProp,
|
|
172
|
+
defaultProp: defaultChecked || !1,
|
|
173
|
+
onChange: onCheckedChange,
|
|
174
|
+
transition: !0
|
|
175
|
+
}), 2), checked = _useControllableState[0], setChecked = _useControllableState[1], styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context), _React_useState = _sliced_to_array(React.useState(0), 2), frameWidth = _React_useState[0], setFrameWidth = _React_useState[1], propsActive = (0, import_core.useProps)(props, {
|
|
176
|
+
noNormalize: !0,
|
|
177
|
+
noExpand: !0,
|
|
178
|
+
resolveValues: "none",
|
|
179
|
+
forComponent: Frame
|
|
180
|
+
}), _styledContext_size, _ref;
|
|
181
|
+
propsActive.size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : "$true";
|
|
182
|
+
var _styledContext_unstyled, _ref1;
|
|
183
|
+
propsActive.unstyled = (_ref1 = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : props.unstyled) !== null && _ref1 !== void 0 ? _ref1 : !1;
|
|
184
|
+
var _useSwitch = (0, import_switch_headless.useSwitch)(
|
|
185
|
+
// @ts-ignore
|
|
186
|
+
propsActive,
|
|
187
|
+
[
|
|
188
|
+
checked,
|
|
189
|
+
setChecked
|
|
190
|
+
],
|
|
191
|
+
forwardedRef
|
|
192
|
+
), switchProps = _useSwitch.switchProps, bubbleInput = _useSwitch.bubbleInput, switchRef = _useSwitch.switchRef, renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
193
|
+
return renderNative === "android" || renderNative === "ios" ? /* @__PURE__ */ React.createElement(import_react_native.Switch, _object_spread({
|
|
194
|
+
value: checked,
|
|
195
|
+
onValueChange: setChecked
|
|
196
|
+
}, nativeProps)) : /* @__PURE__ */ React.createElement(SwitchContext.Provider, {
|
|
197
|
+
value: {
|
|
198
|
+
checked,
|
|
199
|
+
disabled: switchProps.disabled,
|
|
200
|
+
frameWidth
|
|
201
|
+
}
|
|
202
|
+
}, /* @__PURE__ */ React.createElement(Frame, _object_spread_props(_object_spread({
|
|
203
|
+
ref: switchRef,
|
|
204
|
+
tag: "button"
|
|
205
|
+
}, import_core.isWeb && {
|
|
206
|
+
type: "button"
|
|
207
|
+
}, switchProps, !disableActiveTheme && {
|
|
208
|
+
theme: checked ? "active" : null,
|
|
209
|
+
themeShallow: !0
|
|
210
|
+
}), {
|
|
211
|
+
// expected variants
|
|
212
|
+
checked,
|
|
213
|
+
disabled: switchProps.disabled
|
|
214
|
+
}), /* @__PURE__ */ React.createElement(import_core.Stack, {
|
|
215
|
+
alignSelf: "stretch",
|
|
216
|
+
flex: 1,
|
|
217
|
+
onLayout: function(e) {
|
|
218
|
+
setFrameWidth(e.nativeEvent.layout.width);
|
|
219
|
+
}
|
|
220
|
+
}, switchProps.children)), bubbleInput);
|
|
221
|
+
}, {
|
|
222
|
+
disableTheme: !0
|
|
223
|
+
});
|
|
138
224
|
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
139
225
|
Thumb: SwitchThumbComponent
|
|
140
226
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/createSwitch.tsx"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": ["DefaultSwitchFrame", "NativeSwitch"]
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch/src/createSwitch.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kBAOO,0BAKP,yBAA0B,qCAC1B,gCAAqC,4CACrC,QAAuB,2BAEvB,sBAAuC,yBAEvC,uBAAoC,4BACpC,gBAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBxD,IAAMA,gBAAgBC,sBAAMC,cAIhC;EACDC,SAAS;EACTC,UAAU;EACVC,YAAY;AACd,CAAA;AAKO,SAASC,aAGdC,aAAmE;AACnE,MACEC,qBAGED,YAHFC,oBAAAA,qBAGED,YAFFE,OAAAA,QAAAA,uBAAAA,SAAQC,cAAAA,cAAAA,oBAAAA,qBAENH,YADFI,OAAAA,QAAAA,uBAAAA,SAAQC,4BAAAA;AAOV,EAAIC,QAAQC,IAAIC,aAAa,kBAExBN,UAAUC,cAAAA,eAAsBD,MAAMO,aAAaC,WACnDN,UAAUC,6BAAeD,MAAMK,aAAaC,YAE7CC,QAAQC,KACL,2IAAA,GAKPV,MAAMO,aAAaC,UAAUG,0CAC7BT,MAAMK,aAAaC,UAAUG;AAE7B,MAAMC,uBAAuBV,MAAMW,UACjC,SAAqBC,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AehB;OAAgBT,WAAAA,CAAAA,IAK/D,sBAAA,cAACzD,cAAcmF,UAAQ;MACrBF,OAAO;QAAE9E;QAASC,UAAUuE,YAAYvE;QAAUC;MAAW;OAE7D,sBAAA,cAACI,OAAAA,qBAAAA,eAAAA;MACCoC,KAAKgC;MACLO,KAAI;OACCC,qBAAS;MAAEC,MAAM;IAAS,GAC1BX,aACA,CAACnE,sBAAsB;MAC1BsC,OAAO3C,UAAU,WAAW;MAC5BoF,cAAc;IAChB,CAAA,GAAA;;MAEApF;MACAC,UAAUuE,YAAYvE;QAEtB,sBAAA,cAACoF,mBAAAA;MACCzC,WAAU;MACV0C,MAAM;MACNzC,UAAU,SAACE,GAAAA;AACTiB,sBAAcjB,EAAEC,YAAYC,OAAOC,KAAK;MAC1C;OAECsB,YAAYe,QAAQ,CAAA,GAIxBd,WAAAA;EAGP,GACA;IACEe,cAAc;EAChB,CAAA;AAGF,aAAOC,kCAAqBtC,iBAAiB;IAC3C3C,OAAOU;EACT,CAAA;AACF;",
|
|
5
|
+
"names": ["SwitchContext", "React", "createContext", "checked", "disabled", "frameWidth", "createSwitch", "createProps", "disableActiveTheme", "Frame", "DefaultSwitchFrame", "Thumb", "SwitchThumb", "process", "env", "NODE_ENV", "staticConfig", "context", "console", "warn", "SwitchStyledContext", "SwitchThumbComponent", "styleable", "props", "forwardedRef", "sizeProp", "size", "unstyledProp", "unstyled", "nativeID", "thumbProps", "useContext", "styledContext", "useStyledContext", "unstyledContext", "sizeContext", "TAMAGUI_HEADLESS", "initialChecked", "useRef", "current", "useState", "thumbWidth", "setThumbWidth", "distance", "x", "ref", "theme", "alignSelf", "onLayout", "composeEventHandlers", "e", "nativeEvent", "layout", "width", "SwitchComponent", "_props", "native", "nativeProps", "checkedProp", "defaultChecked", "onCheckedChange", "useControllableState", "prop", "defaultProp", "onChange", "transition", "setChecked", "setFrameWidth", "propsActive", "useProps", "noNormalize", "noExpand", "resolveValues", "forComponent", "useSwitch", "switchProps", "bubbleInput", "switchRef", "renderNative", "shouldRenderNativePlatform", "NativeSwitch", "value", "onValueChange", "Provider", "tag", "isWeb", "type", "themeShallow", "Stack", "flex", "children", "disableTheme", "withStaticProperties"]
|
|
6
6
|
}
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -22,7 +22,7 @@ var import_createSwitch = require("./createSwitch"), import_Switch = require("./
|
|
|
22
22
|
__reExport(src_exports, require("./createSwitch"), module.exports);
|
|
23
23
|
__reExport(src_exports, require("./StyledContext"), module.exports);
|
|
24
24
|
__reExport(src_exports, require("./Switch"), module.exports);
|
|
25
|
-
|
|
25
|
+
var Switch = (0, import_createSwitch.createSwitch)({
|
|
26
26
|
Frame: import_Switch.SwitchFrame,
|
|
27
27
|
Thumb: import_Switch.SwitchThumb
|
|
28
28
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;AAAA
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch/src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;;;;;0BAA6B,2BAC7B,gBAAyC;AAEzC,wBAAc,2BAHd;AAIA,wBAAc,4BAJd;AAKA,wBAAc,qBALd;AAOO,IAAMA,aAASC,kCAAa;EACjCC,OAAOC;EACPC,OAAOC;AACT,CAAA;",
|
|
5
|
+
"names": ["Switch", "createSwitch", "Frame", "SwitchFrame", "Thumb", "SwitchThumb"]
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/StyledContext.tsx"],
|
|
4
|
-
"mappings": "AACA,
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch/src/StyledContext.tsx"],
|
|
4
|
+
"mappings": "AACA,SAASA,2BAA2B;AAE7B,IAAMC,sBAAsBD,oBAGhC;EACDE,MAAMC;EACNC,UAAUC,QAAQC,IAAIC,qBAAqB;AAC7C,CAAA;",
|
|
5
|
+
"names": ["createStyledContext", "SwitchStyledContext", "size", "undefined", "unstyled", "process", "env", "TAMAGUI_HEADLESS"]
|
|
6
6
|
}
|
|
@@ -2,7 +2,7 @@ import { getVariableValue, styled } from "@tamagui/core";
|
|
|
2
2
|
import { getSize } from "@tamagui/get-token";
|
|
3
3
|
import { ThemeableStack, YStack } from "@tamagui/stacks";
|
|
4
4
|
import { SwitchStyledContext } from "./StyledContext";
|
|
5
|
-
|
|
5
|
+
var SwitchThumb = styled(ThemeableStack, {
|
|
6
6
|
name: "SwitchThumb",
|
|
7
7
|
context: SwitchStyledContext,
|
|
8
8
|
variants: {
|
|
@@ -17,8 +17,8 @@ const SwitchThumb = styled(ThemeableStack, {
|
|
|
17
17
|
true: {}
|
|
18
18
|
},
|
|
19
19
|
size: {
|
|
20
|
-
"...size": (val)
|
|
21
|
-
|
|
20
|
+
"...size": function(val) {
|
|
21
|
+
var size = getSwitchHeight(val);
|
|
22
22
|
return {
|
|
23
23
|
height: size,
|
|
24
24
|
width: size
|
|
@@ -29,7 +29,11 @@ const SwitchThumb = styled(ThemeableStack, {
|
|
|
29
29
|
defaultVariants: {
|
|
30
30
|
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
31
31
|
}
|
|
32
|
-
}), getSwitchHeight = (val)
|
|
32
|
+
}), getSwitchHeight = function(val) {
|
|
33
|
+
return Math.round(getVariableValue(getSize(val)) * 0.65);
|
|
34
|
+
}, getSwitchWidth = function(val) {
|
|
35
|
+
return getSwitchHeight(val) * 2;
|
|
36
|
+
}, SwitchFrame = styled(YStack, {
|
|
33
37
|
name: "Switch",
|
|
34
38
|
tag: "button",
|
|
35
39
|
context: SwitchStyledContext,
|
|
@@ -51,8 +55,8 @@ const SwitchThumb = styled(ThemeableStack, {
|
|
|
51
55
|
true: {}
|
|
52
56
|
},
|
|
53
57
|
size: {
|
|
54
|
-
"...size": (val)
|
|
55
|
-
|
|
58
|
+
"...size": function(val) {
|
|
59
|
+
var height = getSwitchHeight(val) + 4, width = getSwitchWidth(val) + 4;
|
|
56
60
|
return {
|
|
57
61
|
height,
|
|
58
62
|
minHeight: height,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/Switch.tsx"],
|
|
4
|
-
"mappings": "AACA,
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch/src/Switch.tsx"],
|
|
4
|
+
"mappings": "AACA,SAASA,kBAAkBC,cAAc;AACzC,SAASC,eAAe;AACxB,SAASC,gBAAgBC,cAAc;AAEvC,SAASC,2BAA2B;AAE7B,IAAMC,cAAcL,OAAOE,gBAAgB;EAChDI,MAAM;EACNC,SAASH;EAETI,UAAU;IACRC,UAAU;MACRC,OAAO;QACLC,MAAM;QACNC,iBAAiB;QACjBC,cAAc;MAChB;IACF;IAEAC,SAAS;MACPC,MAAM,CAAC;IACT;IAEAJ,MAAM;MACJ,WAAW,SAACK,KAAAA;AACV,YAAML,OAAOM,gBAAgBD,GAAAA;AAC7B,eAAO;UACLE,QAAQP;UACRQ,OAAOR;QACT;MACF;IACF;EACF;EAEAS,iBAAiB;IACfX,UAAUY,QAAQC,IAAIC,qBAAqB;EAC7C;AACF,CAAA,GAEMN,kBAAkB,SAACD,KAAAA;SACvBQ,KAAKC,MAAM1B,iBAAiBE,QAAQe,GAAAA,CAAAA,IAAQ,IAAA;GAExCU,iBAAiB,SAACV,KAAAA;SAAoBC,gBAAgBD,GAAAA,IAAO;GAEtDW,cAAc3B,OAAOG,QAAQ;EACxCG,MAAM;EACNsB,KAAK;EACLrB,SAASH;EAETI,UAAU;IACRC,UAAU;MACRC,OAAO;QACLG,cAAc;QACdD,iBAAiB;QACjBiB,aAAa;QACbC,aAAa;QAEbC,YAAY;UACVC,cAAc;UACdC,cAAc;UACdC,cAAc;QAChB;MACF;IACF;IAEApB,SAAS;MACPC,MAAM,CAAC;IACT;IAEAJ,MAAM;MACJ,WAAW,SAACK,KAAAA;AACV,YAAME,SAASD,gBAAgBD,GAAAA,IAAO,GAChCG,QAAQO,eAAeV,GAAAA,IAAO;AACpC,eAAO;UACLE;UACAiB,WAAWjB;UACXC;QACF;MACF;IACF;EACF;EAEAC,iBAAiB;IACfX,UAAUY,QAAQC,IAAIC,qBAAqB;EAC7C;AACF,CAAA;",
|
|
5
|
+
"names": ["getVariableValue", "styled", "getSize", "ThemeableStack", "YStack", "SwitchStyledContext", "SwitchThumb", "name", "context", "variants", "unstyled", "false", "size", "backgroundColor", "borderRadius", "checked", "true", "val", "getSwitchHeight", "height", "width", "defaultVariants", "process", "env", "TAMAGUI_HEADLESS", "Math", "round", "getSwitchWidth", "SwitchFrame", "tag", "borderWidth", "borderColor", "focusStyle", "outlineColor", "outlineStyle", "outlineWidth", "minHeight"]
|
|
6
6
|
}
|