@tamagui/switch 3.0.0-beta.1216.1 → 3.0.0-beta.1309.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/Switch.cjs +21 -30
- package/dist/cjs/Switch.native.cjs +22 -33
- package/dist/cjs/Switch.native.js +22 -33
- package/dist/cjs/Switch.native.js.map +1 -1
- package/dist/esm/Switch.mjs +22 -31
- package/dist/esm/Switch.mjs.map +1 -1
- package/dist/esm/Switch.native.js +23 -34
- package/dist/esm/Switch.native.js.map +1 -1
- package/dist/jsx/Switch.mjs +22 -31
- package/dist/jsx/Switch.mjs.map +1 -1
- package/dist/jsx/Switch.native.cjs +22 -33
- package/dist/jsx/Switch.native.js +22 -33
- package/dist/jsx/Switch.native.js.map +1 -1
- package/package.json +7 -7
- package/src/Switch.tsx +25 -35
- package/types/Switch.d.ts +17 -16
- package/types/Switch.d.ts.map +1 -1
package/dist/cjs/Switch.cjs
CHANGED
|
@@ -56,7 +56,7 @@ function createSwitch(createProps) {
|
|
|
56
56
|
Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
57
57
|
Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
58
58
|
const SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
59
|
-
const { size: sizeProp, activeStyle,
|
|
59
|
+
const { size: sizeProp, activeStyle, ...thumbProps } = props;
|
|
60
60
|
const styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
|
|
61
61
|
const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
62
62
|
const size = sizeProp ?? sizeContext ?? true;
|
|
@@ -65,7 +65,7 @@ function createSwitch(createProps) {
|
|
|
65
65
|
const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
66
66
|
const distance = frameWidth - thumbWidth;
|
|
67
67
|
const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
68
|
-
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
|
|
69
69
|
ref: forwardedRef,
|
|
70
70
|
size,
|
|
71
71
|
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
@@ -77,14 +77,9 @@ function createSwitch(createProps) {
|
|
|
77
77
|
...thumbProps,
|
|
78
78
|
...active && activeStyle
|
|
79
79
|
});
|
|
80
|
-
const themeName = theme ?? createProps.componentThemes?.thumb;
|
|
81
|
-
return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
82
|
-
name: themeName,
|
|
83
|
-
children: thumb
|
|
84
|
-
}) : thumb;
|
|
85
80
|
});
|
|
86
81
|
const SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
|
|
87
|
-
const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme,
|
|
82
|
+
const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
|
|
88
83
|
const [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
89
84
|
prop: checkedProp,
|
|
90
85
|
defaultProp: defaultChecked || false,
|
|
@@ -113,34 +108,30 @@ function createSwitch(createProps) {
|
|
|
113
108
|
setFrameInnerWidth(next);
|
|
114
109
|
}
|
|
115
110
|
};
|
|
116
|
-
const frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
|
|
117
|
-
ref: switchRef,
|
|
118
|
-
render: "button",
|
|
119
|
-
...import_core.isWeb && { type: "button" },
|
|
120
|
-
size,
|
|
121
|
-
...props,
|
|
122
|
-
...switchProps,
|
|
123
|
-
disabled,
|
|
124
|
-
...checked && activeStyle,
|
|
125
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
126
|
-
alignSelf: "stretch",
|
|
127
|
-
flex: 1,
|
|
128
|
-
onLayout: handleLayout,
|
|
129
|
-
children: props.children
|
|
130
|
-
})
|
|
131
|
-
});
|
|
132
|
-
const frameTheme = (checked ? activeTheme : void 0) ?? theme ?? createProps.componentThemes?.frame;
|
|
133
111
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
134
112
|
size,
|
|
135
113
|
active: checked,
|
|
136
114
|
disabled,
|
|
137
115
|
frameWidth,
|
|
138
|
-
children:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
116
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
|
|
117
|
+
ref: switchRef,
|
|
118
|
+
render: "button",
|
|
119
|
+
theme: checked ? activeTheme ?? createProps.activeTheme ?? null : null,
|
|
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
|
+
})
|
|
142
133
|
}), bubbleInput] });
|
|
143
|
-
}
|
|
134
|
+
});
|
|
144
135
|
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
145
136
|
Frame,
|
|
146
137
|
Thumb: SwitchThumbComponent
|
|
@@ -60,8 +60,7 @@ function createSwitch(createProps) {
|
|
|
60
60
|
Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
61
61
|
Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
62
62
|
var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
63
|
-
var
|
|
64
|
-
var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
|
|
63
|
+
var { size: sizeProp, activeStyle, ...thumbProps } = props;
|
|
65
64
|
var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
|
|
66
65
|
var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
67
66
|
var _ref;
|
|
@@ -71,7 +70,7 @@ function createSwitch(createProps) {
|
|
|
71
70
|
var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
72
71
|
var distance = frameWidth - thumbWidth;
|
|
73
72
|
var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
74
|
-
|
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
|
|
75
74
|
ref: forwardedRef,
|
|
76
75
|
size,
|
|
77
76
|
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
@@ -83,15 +82,9 @@ function createSwitch(createProps) {
|
|
|
83
82
|
...thumbProps,
|
|
84
83
|
...active && activeStyle
|
|
85
84
|
});
|
|
86
|
-
var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;
|
|
87
|
-
return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
88
|
-
name: themeName,
|
|
89
|
-
children: thumb
|
|
90
|
-
}) : thumb;
|
|
91
85
|
});
|
|
92
86
|
var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
|
|
93
|
-
var
|
|
94
|
-
var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
|
|
87
|
+
var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
|
|
95
88
|
var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
96
89
|
prop: checkedProp,
|
|
97
90
|
defaultProp: defaultChecked || false,
|
|
@@ -121,35 +114,31 @@ function createSwitch(createProps) {
|
|
|
121
114
|
setFrameInnerWidth(next);
|
|
122
115
|
}
|
|
123
116
|
};
|
|
124
|
-
var
|
|
125
|
-
ref: switchRef,
|
|
126
|
-
render: "button",
|
|
127
|
-
...import_core.isWeb && { type: "button" },
|
|
128
|
-
size,
|
|
129
|
-
...props,
|
|
130
|
-
...switchProps,
|
|
131
|
-
disabled,
|
|
132
|
-
...checked && activeStyle,
|
|
133
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
134
|
-
alignSelf: "stretch",
|
|
135
|
-
flex: 1,
|
|
136
|
-
onLayout: handleLayout,
|
|
137
|
-
children: props.children
|
|
138
|
-
})
|
|
139
|
-
});
|
|
140
|
-
var _ref1, _ref2;
|
|
141
|
-
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;
|
|
117
|
+
var _ref1;
|
|
142
118
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
143
119
|
size,
|
|
144
120
|
active: checked,
|
|
145
121
|
disabled,
|
|
146
122
|
frameWidth,
|
|
147
|
-
children:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
123
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
|
|
124
|
+
ref: switchRef,
|
|
125
|
+
render: "button",
|
|
126
|
+
theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,
|
|
127
|
+
...import_core.isWeb && { type: "button" },
|
|
128
|
+
size,
|
|
129
|
+
...props,
|
|
130
|
+
...switchProps,
|
|
131
|
+
disabled,
|
|
132
|
+
...checked && activeStyle,
|
|
133
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
134
|
+
alignSelf: "stretch",
|
|
135
|
+
flex: 1,
|
|
136
|
+
onLayout: handleLayout,
|
|
137
|
+
children: props.children
|
|
138
|
+
})
|
|
139
|
+
})
|
|
151
140
|
}), bubbleInput] });
|
|
152
|
-
}
|
|
141
|
+
});
|
|
153
142
|
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
154
143
|
Frame,
|
|
155
144
|
Thumb: SwitchThumbComponent
|
|
@@ -60,8 +60,7 @@ function createSwitch(createProps) {
|
|
|
60
60
|
Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
61
61
|
Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
62
62
|
var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
63
|
-
var
|
|
64
|
-
var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
|
|
63
|
+
var { size: sizeProp, activeStyle, ...thumbProps } = props;
|
|
65
64
|
var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
|
|
66
65
|
var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
67
66
|
var _ref;
|
|
@@ -71,7 +70,7 @@ function createSwitch(createProps) {
|
|
|
71
70
|
var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
72
71
|
var distance = frameWidth - thumbWidth;
|
|
73
72
|
var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
74
|
-
|
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
|
|
75
74
|
ref: forwardedRef,
|
|
76
75
|
size,
|
|
77
76
|
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
@@ -83,15 +82,9 @@ function createSwitch(createProps) {
|
|
|
83
82
|
...thumbProps,
|
|
84
83
|
...active && activeStyle
|
|
85
84
|
});
|
|
86
|
-
var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;
|
|
87
|
-
return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
88
|
-
name: themeName,
|
|
89
|
-
children: thumb
|
|
90
|
-
}) : thumb;
|
|
91
85
|
});
|
|
92
86
|
var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
|
|
93
|
-
var
|
|
94
|
-
var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
|
|
87
|
+
var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
|
|
95
88
|
var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
96
89
|
prop: checkedProp,
|
|
97
90
|
defaultProp: defaultChecked || false,
|
|
@@ -121,35 +114,31 @@ function createSwitch(createProps) {
|
|
|
121
114
|
setFrameInnerWidth(next);
|
|
122
115
|
}
|
|
123
116
|
};
|
|
124
|
-
var
|
|
125
|
-
ref: switchRef,
|
|
126
|
-
render: "button",
|
|
127
|
-
...import_core.isWeb && { type: "button" },
|
|
128
|
-
size,
|
|
129
|
-
...props,
|
|
130
|
-
...switchProps,
|
|
131
|
-
disabled,
|
|
132
|
-
...checked && activeStyle,
|
|
133
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
134
|
-
alignSelf: "stretch",
|
|
135
|
-
flex: 1,
|
|
136
|
-
onLayout: handleLayout,
|
|
137
|
-
children: props.children
|
|
138
|
-
})
|
|
139
|
-
});
|
|
140
|
-
var _ref1, _ref2;
|
|
141
|
-
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;
|
|
117
|
+
var _ref1;
|
|
142
118
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
143
119
|
size,
|
|
144
120
|
active: checked,
|
|
145
121
|
disabled,
|
|
146
122
|
frameWidth,
|
|
147
|
-
children:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
123
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
|
|
124
|
+
ref: switchRef,
|
|
125
|
+
render: "button",
|
|
126
|
+
theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,
|
|
127
|
+
...import_core.isWeb && { type: "button" },
|
|
128
|
+
size,
|
|
129
|
+
...props,
|
|
130
|
+
...switchProps,
|
|
131
|
+
disabled,
|
|
132
|
+
...checked && activeStyle,
|
|
133
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
134
|
+
alignSelf: "stretch",
|
|
135
|
+
flex: 1,
|
|
136
|
+
onLayout: handleLayout,
|
|
137
|
+
children: props.children
|
|
138
|
+
})
|
|
139
|
+
})
|
|
151
140
|
}), bubbleInput] });
|
|
152
|
-
}
|
|
141
|
+
});
|
|
153
142
|
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
154
143
|
Frame,
|
|
155
144
|
Thumb: SwitchThumbComponent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.native.js","names":[],"sources":["cjs/Switch.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 Switch_exports = {};\n__export(Switch_exports, {\n Switch: () => Switch,\n SwitchFrame: () => SwitchFrame,\n SwitchThumb: () => SwitchThumb,\n SwitchThumbFrame: () => SwitchThumbFrame,\n createSwitch: () => createSwitch\n});\nmodule.exports = __toCommonJS(Switch_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_core = require(\"@tamagui/core\");\nvar import_switch_headless = require(\"@tamagui/switch-headless\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar React = __toESM(require(\"react\"), 1);\nvar import_StyledContext = require(\"./StyledContext\");\nvar import_useSwitchNative = require(\"./useSwitchNative\");\nvar SwitchThumbFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"SwitchThumb\",\n context: import_StyledContext.SwitchStyledContext\n});\nvar SwitchFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"Switch\",\n context: import_StyledContext.SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n var _createProps_Frame;\n var Frame = (_createProps_Frame = createProps.Frame) !== null && _createProps_Frame !== void 0 ? _createProps_Frame : SwitchFrame;\n var _createProps_Thumb;\n var Thumb = (_createProps_Thumb = createProps.Thumb) !== null && _createProps_Thumb !== void 0 ? _createProps_Thumb : SwitchThumbFrame;\n Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;\n Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;\n var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {\n var _createProps_componentThemes;\n var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;\n var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();\n var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n var _ref;\n var size = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref !== void 0 ? _ref : true;\n var initialChecked = React.useRef(active).current;\n var initialWidth = (0, import_core.getVariableValue)(props.width, \"size\");\n var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === \"number\" ? initialWidth : 0);\n var distance = frameWidth - thumbWidth;\n var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n var thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(event) {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n });\n var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;\n return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {\n name: themeName,\n children: thumb\n }) : thumb;\n });\n var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {\n var _createProps_componentThemes;\n var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;\n var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);\n var [frameWidth, setFrameInnerWidth] = React.useState(0);\n var { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(\n props,\n [\n checked,\n setChecked\n ],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n var nativeSwitch = (0, import_useSwitchNative.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 var disabled = props.disabled;\n var _styledContext_size, _ref;\n var size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : true;\n var handleLayout = function(event) {\n var next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n var frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {\n ref: switchRef,\n render: \"button\",\n ...import_core.isWeb && {\n type: \"button\"\n },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {\n alignSelf: \"stretch\",\n flex: 1,\n onLayout: handleLayout,\n children: props.children\n })\n });\n var _ref1, _ref2;\n 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;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {\n children: [\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {\n name: frameTheme,\n children: frame\n }) : frame\n }),\n bubbleInput\n ]\n });\n }, {\n disableTheme: true\n });\n return (0, import_core.withStaticProperties)(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nvar Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nvar SwitchThumb = Switch.Thumb;\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,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OAAuB,iBAAC,GAAG,mBAAmB,KAAI,CAAE,mBAAmB,UAAU,EAC/E,UAAU,CACQ,iBAAC,GAAG,mBAAmB,IAAG,CAAE,qBAAqB,oBAAoB,UAAU;GAC7F;GACA,QAAQ;GACR;GACA;GACA,UAAU,aAA6B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,YAAY,OAAO;IACpF,MAAM;IACN,UAAU;GACZ,CAAC,IAAI;EACP,CAAC,GACD,WACF,EACF,CAAC;CACH,GAAG,EACD,cAAc,KAChB,CAAC;CACD,QAAQ,GAAG,YAAY,qBAAoB,CAAE,iBAAiB;EAC5D;EACA,OAAO;CACT,CAAC;AACH;AACA,IAAI,SAAS,aAAa;CACxB,OAAO;CACP,OAAO;AACT,CAAC;AACD,IAAI,cAAc,OAAO"}
|
|
1
|
+
{"version":3,"file":"Switch.native.js","names":[],"sources":["cjs/Switch.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 Switch_exports = {};\n__export(Switch_exports, {\n Switch: () => Switch,\n SwitchFrame: () => SwitchFrame,\n SwitchThumb: () => SwitchThumb,\n SwitchThumbFrame: () => SwitchThumbFrame,\n createSwitch: () => createSwitch\n});\nmodule.exports = __toCommonJS(Switch_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_core = require(\"@tamagui/core\");\nvar import_switch_headless = require(\"@tamagui/switch-headless\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar React = __toESM(require(\"react\"), 1);\nvar import_StyledContext = require(\"./StyledContext\");\nvar import_useSwitchNative = require(\"./useSwitchNative\");\nvar SwitchThumbFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"SwitchThumb\",\n context: import_StyledContext.SwitchStyledContext\n});\nvar SwitchFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"Switch\",\n context: import_StyledContext.SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n var _createProps_Frame;\n var Frame = (_createProps_Frame = createProps.Frame) !== null && _createProps_Frame !== void 0 ? _createProps_Frame : SwitchFrame;\n var _createProps_Thumb;\n var Thumb = (_createProps_Thumb = createProps.Thumb) !== null && _createProps_Thumb !== void 0 ? _createProps_Thumb : SwitchThumbFrame;\n Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;\n Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;\n var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {\n var { size: sizeProp, activeStyle, ...thumbProps } = props;\n var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();\n var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n var _ref;\n var size = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref !== void 0 ? _ref : true;\n var initialChecked = React.useRef(active).current;\n var initialWidth = (0, import_core.getVariableValue)(props.width, \"size\");\n var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === \"number\" ? initialWidth : 0);\n var distance = frameWidth - thumbWidth;\n var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(event) {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n });\n });\n var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {\n var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;\n var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);\n var [frameWidth, setFrameInnerWidth] = React.useState(0);\n var { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(\n props,\n [\n checked,\n setChecked\n ],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n var nativeSwitch = (0, import_useSwitchNative.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 var disabled = props.disabled;\n var _styledContext_size, _ref;\n var size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : true;\n var handleLayout = function(event) {\n var next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n var _ref1;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {\n children: [\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {\n ref: switchRef,\n render: \"button\",\n // the track and the thumb swap onto one theme while checked, so\n // the fill and the knob move together. the key stays present with\n // a null value so toggling never re-parents the frame.\n theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,\n ...import_core.isWeb && {\n type: \"button\"\n },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {\n alignSelf: \"stretch\",\n flex: 1,\n onLayout: handleLayout,\n children: props.children\n })\n })\n }),\n bubbleInput\n ]\n });\n });\n return (0, import_core.withStaticProperties)(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nvar Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nvar SwitchThumb = Switch.Thumb;\n//# sourceMappingURL=Switch.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,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;KACN,UAAU;KACV,UAAU,MAAM;IAClB,CAAC;GACH,CAAC;EACH,CAAC,GACD,WACF,EACF,CAAC;CACH,CAAC;CACD,QAAQ,GAAG,YAAY,qBAAoB,CAAE,iBAAiB;EAC5D;EACA,OAAO;CACT,CAAC;AACH;AACA,IAAI,SAAS,aAAa;CACxB,OAAO;CACP,OAAO;AACT,CAAC;AACD,IAAI,cAAc,OAAO"}
|
package/dist/esm/Switch.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { View, composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, withStaticProperties } from "@tamagui/core";
|
|
2
2
|
import { useSwitch } from "@tamagui/switch-headless";
|
|
3
3
|
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
4
4
|
import * as React from "react";
|
|
@@ -22,7 +22,7 @@ function createSwitch(createProps) {
|
|
|
22
22
|
Frame.staticConfig.context = SwitchStyledContext;
|
|
23
23
|
Thumb.staticConfig.context = SwitchStyledContext;
|
|
24
24
|
const SwitchThumbComponent = createStyledHOC(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
25
|
-
const { size: sizeProp, activeStyle,
|
|
25
|
+
const { size: sizeProp, activeStyle, ...thumbProps } = props;
|
|
26
26
|
const styledContext = SwitchStyledContext.useStyledContext();
|
|
27
27
|
const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
28
28
|
const size = sizeProp ?? sizeContext ?? true;
|
|
@@ -31,7 +31,7 @@ function createSwitch(createProps) {
|
|
|
31
31
|
const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
32
32
|
const distance = frameWidth - thumbWidth;
|
|
33
33
|
const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
34
|
-
|
|
34
|
+
return /* @__PURE__ */ jsx(Thumb, {
|
|
35
35
|
ref: forwardedRef,
|
|
36
36
|
size,
|
|
37
37
|
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
@@ -43,14 +43,9 @@ function createSwitch(createProps) {
|
|
|
43
43
|
...thumbProps,
|
|
44
44
|
...active && activeStyle
|
|
45
45
|
});
|
|
46
|
-
const themeName = theme ?? createProps.componentThemes?.thumb;
|
|
47
|
-
return themeName ? /* @__PURE__ */ jsx(Theme, {
|
|
48
|
-
name: themeName,
|
|
49
|
-
children: thumb
|
|
50
|
-
}) : thumb;
|
|
51
46
|
});
|
|
52
47
|
const SwitchComponent = createStyledHOC(Frame, function Switch2(_props, forwardedRef) {
|
|
53
|
-
const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme,
|
|
48
|
+
const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
|
|
54
49
|
const [checked, setChecked] = useControllableState({
|
|
55
50
|
prop: checkedProp,
|
|
56
51
|
defaultProp: defaultChecked || false,
|
|
@@ -79,34 +74,30 @@ function createSwitch(createProps) {
|
|
|
79
74
|
setFrameInnerWidth(next);
|
|
80
75
|
}
|
|
81
76
|
};
|
|
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
77
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SwitchStyledContext.Provider, {
|
|
100
78
|
size,
|
|
101
79
|
active: checked,
|
|
102
80
|
disabled,
|
|
103
81
|
frameWidth,
|
|
104
|
-
children:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
82
|
+
children: /* @__PURE__ */ jsx(Frame, {
|
|
83
|
+
ref: switchRef,
|
|
84
|
+
render: "button",
|
|
85
|
+
theme: checked ? activeTheme ?? createProps.activeTheme ?? null : null,
|
|
86
|
+
...isWeb && { type: "button" },
|
|
87
|
+
size,
|
|
88
|
+
...props,
|
|
89
|
+
...switchProps,
|
|
90
|
+
disabled,
|
|
91
|
+
...checked && activeStyle,
|
|
92
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
93
|
+
alignSelf: "stretch",
|
|
94
|
+
flex: 1,
|
|
95
|
+
onLayout: handleLayout,
|
|
96
|
+
children: props.children
|
|
97
|
+
})
|
|
98
|
+
})
|
|
108
99
|
}), bubbleInput] });
|
|
109
|
-
}
|
|
100
|
+
});
|
|
110
101
|
return withStaticProperties(SwitchComponent, {
|
|
111
102
|
Frame,
|
|
112
103
|
Thumb: SwitchThumbComponent
|
package/dist/esm/Switch.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","names":[],"sources":["esm/Switch.js"],"sourcesContent":["import {\n composeEventHandlers,\n createStyledHOC,\n getVariableValue,\n isWeb,\n styled,\n
|
|
1
|
+
{"version":3,"file":"Switch.js","names":[],"sources":["esm/Switch.js"],"sourcesContent":["import {\n composeEventHandlers,\n createStyledHOC,\n getVariableValue,\n isWeb,\n styled,\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, ...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 return /* @__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 }\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 ...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 return /* @__PURE__ */ jsxs(Fragment, { children: [\n /* @__PURE__ */ jsx(\n SwitchStyledContext.Provider,\n {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: /* @__PURE__ */ jsx(\n Frame,\n {\n ref: switchRef,\n render: \"button\",\n theme: checked ? activeTheme ?? createProps.activeTheme ?? null : null,\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 }\n ),\n bubbleInput\n ] });\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":";;;;;;;;;AAeA,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,GAAG,eAAe;EACvD,MAAM,gBAAgB,oBAAoB,iBAAiB;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,SAAS,YAAY;IACvB,mBAAmB,IAAI;GACzB;EACF;EACA,OAAuB,qBAAK,UAAU,EAAE,UAAU,CAChC,oBACd,oBAAoB,UACpB;GACE;GACA,QAAQ;GACR;GACA;GACA,UAA0B,oBACxB,OACA;IACE,KAAK;IACL,QAAQ;IACR,OAAO,UAAU,eAAe,YAAY,eAAe,OAAO;IAClE,GAAG,SAAS,EAAE,MAAM,SAAS;IAC7B;IACA,GAAG;IACH,GAAG;IACH;IACA,GAAG,WAAW;IACd,UAA0B,oBAAI,MAAM;KAAE,WAAW;KAAW,MAAM;KAAG,UAAU;KAAc,UAAU,MAAM;IAAS,CAAC;GACzH,CACF;EACF,CACF,GACA,WACF,EAAE,CAAC;CACL,CACF;CACA,OAAO,qBAAqB,iBAAiB;EAC3C;EACA,OAAO;CACT,CAAC;AACH;AACA,MAAM,SAAS,aAAa;CAC1B,OAAO;CACP,OAAO;AACT,CAAC;AACD,MAAM,cAAc,OAAO"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { View, composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, withStaticProperties } from "@tamagui/core";
|
|
3
3
|
import { useSwitch } from "@tamagui/switch-headless";
|
|
4
4
|
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
5
5
|
import * as React from "react";
|
|
@@ -24,8 +24,7 @@ function createSwitch(createProps) {
|
|
|
24
24
|
Frame.staticConfig.context = SwitchStyledContext;
|
|
25
25
|
Thumb.staticConfig.context = SwitchStyledContext;
|
|
26
26
|
var SwitchThumbComponent = createStyledHOC(Thumb, function SwitchThumb2(props, forwardedRef) {
|
|
27
|
-
var
|
|
28
|
-
var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
|
|
27
|
+
var { size: sizeProp, activeStyle, ...thumbProps } = props;
|
|
29
28
|
var styledContext = SwitchStyledContext.useStyledContext();
|
|
30
29
|
var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
|
|
31
30
|
var _ref;
|
|
@@ -35,7 +34,7 @@ function createSwitch(createProps) {
|
|
|
35
34
|
var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
36
35
|
var distance = frameWidth - thumbWidth;
|
|
37
36
|
var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
38
|
-
|
|
37
|
+
return /* @__PURE__ */ jsx(Thumb, {
|
|
39
38
|
ref: forwardedRef,
|
|
40
39
|
size,
|
|
41
40
|
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
@@ -47,15 +46,9 @@ function createSwitch(createProps) {
|
|
|
47
46
|
...thumbProps,
|
|
48
47
|
...active && activeStyle
|
|
49
48
|
});
|
|
50
|
-
var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;
|
|
51
|
-
return themeName ? /* @__PURE__ */ jsx(Theme, {
|
|
52
|
-
name: themeName,
|
|
53
|
-
children: thumb
|
|
54
|
-
}) : thumb;
|
|
55
49
|
});
|
|
56
50
|
var SwitchComponent = createStyledHOC(Frame, function Switch2(_props, forwardedRef) {
|
|
57
|
-
var
|
|
58
|
-
var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
|
|
51
|
+
var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
|
|
59
52
|
var [checked, setChecked] = useControllableState({
|
|
60
53
|
prop: checkedProp,
|
|
61
54
|
defaultProp: defaultChecked || false,
|
|
@@ -85,35 +78,31 @@ function createSwitch(createProps) {
|
|
|
85
78
|
setFrameInnerWidth(next);
|
|
86
79
|
}
|
|
87
80
|
};
|
|
88
|
-
var
|
|
89
|
-
ref: switchRef,
|
|
90
|
-
render: "button",
|
|
91
|
-
...isWeb && { type: "button" },
|
|
92
|
-
size,
|
|
93
|
-
...props,
|
|
94
|
-
...switchProps,
|
|
95
|
-
disabled,
|
|
96
|
-
...checked && activeStyle,
|
|
97
|
-
children: /* @__PURE__ */ jsx(View, {
|
|
98
|
-
alignSelf: "stretch",
|
|
99
|
-
flex: 1,
|
|
100
|
-
onLayout: handleLayout,
|
|
101
|
-
children: props.children
|
|
102
|
-
})
|
|
103
|
-
});
|
|
104
|
-
var _ref1, _ref2;
|
|
105
|
-
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;
|
|
81
|
+
var _ref1;
|
|
106
82
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SwitchStyledContext.Provider, {
|
|
107
83
|
size,
|
|
108
84
|
active: checked,
|
|
109
85
|
disabled,
|
|
110
86
|
frameWidth,
|
|
111
|
-
children:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
87
|
+
children: /* @__PURE__ */ jsx(Frame, {
|
|
88
|
+
ref: switchRef,
|
|
89
|
+
render: "button",
|
|
90
|
+
theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,
|
|
91
|
+
...isWeb && { type: "button" },
|
|
92
|
+
size,
|
|
93
|
+
...props,
|
|
94
|
+
...switchProps,
|
|
95
|
+
disabled,
|
|
96
|
+
...checked && activeStyle,
|
|
97
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
98
|
+
alignSelf: "stretch",
|
|
99
|
+
flex: 1,
|
|
100
|
+
onLayout: handleLayout,
|
|
101
|
+
children: props.children
|
|
102
|
+
})
|
|
103
|
+
})
|
|
115
104
|
}), bubbleInput] });
|
|
116
|
-
}
|
|
105
|
+
});
|
|
117
106
|
return withStaticProperties(SwitchComponent, {
|
|
118
107
|
Frame,
|
|
119
108
|
Thumb: SwitchThumbComponent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.native.js","names":["_Fragment"],"sources":["esm/Switch.native.js"],"sourcesContent":["import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nimport { composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled,
|
|
1
|
+
{"version":3,"file":"Switch.native.js","names":["_Fragment"],"sources":["esm/Switch.native.js"],"sourcesContent":["import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nimport { composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, View, withStaticProperties } 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\";\nvar SwitchThumbFrame = styled(View, {\n displayName: \"SwitchThumb\",\n context: SwitchStyledContext\n});\nvar SwitchFrame = styled(View, {\n displayName: \"Switch\",\n context: SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n var _createProps_Frame;\n var Frame = (_createProps_Frame = createProps.Frame) !== null && _createProps_Frame !== void 0 ? _createProps_Frame : SwitchFrame;\n var _createProps_Thumb;\n var Thumb = (_createProps_Thumb = createProps.Thumb) !== null && _createProps_Thumb !== void 0 ? _createProps_Thumb : SwitchThumbFrame;\n Frame.staticConfig.context = SwitchStyledContext;\n Thumb.staticConfig.context = SwitchStyledContext;\n var SwitchThumbComponent = createStyledHOC(Thumb, function SwitchThumb2(props, forwardedRef) {\n var { size: sizeProp, activeStyle, ...thumbProps } = props;\n var styledContext = SwitchStyledContext.useStyledContext();\n var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n var _ref;\n var size = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref !== void 0 ? _ref : true;\n var initialChecked = React.useRef(active).current;\n var initialWidth = getVariableValue(props.width, \"size\");\n var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === \"number\" ? initialWidth : 0);\n var distance = frameWidth - thumbWidth;\n var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n return /* @__PURE__ */ _jsx(Thumb, {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: composeEventHandlers(props.onLayout, function(event) {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n });\n });\n var SwitchComponent = createStyledHOC(Frame, function Switch2(_props, forwardedRef) {\n var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;\n var [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n var styledContext = React.useContext(SwitchStyledContext.context);\n var [frameWidth, setFrameInnerWidth] = React.useState(0);\n var { switchProps, bubbleInput, switchRef } = useSwitch(\n props,\n [\n checked,\n setChecked\n ],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n var 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 var disabled = props.disabled;\n var _styledContext_size, _ref;\n var size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : true;\n var handleLayout = function(event) {\n var next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n var _ref1;\n return /* @__PURE__ */ _jsxs(_Fragment, {\n children: [\n /* @__PURE__ */ _jsx(SwitchStyledContext.Provider, {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: /* @__PURE__ */ _jsx(Frame, {\n ref: switchRef,\n render: \"button\",\n // the track and the thumb swap onto one theme while checked, so\n // the fill and the knob move together. the key stays present with\n // a null value so toggling never re-parents the frame.\n theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,\n ...isWeb && {\n type: \"button\"\n },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ _jsx(View, {\n alignSelf: \"stretch\",\n flex: 1,\n onLayout: handleLayout,\n children: props.children\n })\n })\n }),\n bubbleInput\n ]\n });\n });\n return withStaticProperties(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nvar Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nvar SwitchThumb = Switch.Thumb;\nexport {\n Switch,\n SwitchFrame,\n SwitchThumb,\n SwitchThumbFrame,\n createSwitch\n};\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;;;;;;;AAOA,IAAI,mBAAmB,OAAO,MAAM;CAClC,aAAa;CACb,SAAS;AACX,CAAC;AACD,IAAI,cAAc,OAAO,MAAM;CAC7B,aAAa;CACb,SAAS;CACT,QAAQ;CACR,UAAU;AACZ,CAAC;AACD,SAAS,aAAa,aAAa;CACjC,IAAI;CACJ,IAAI,SAAS,qBAAqB,YAAY,WAAW,QAAQ,uBAAuB,KAAK,IAAI,qBAAqB;CACtH,IAAI;CACJ,IAAI,SAAS,qBAAqB,YAAY,WAAW,QAAQ,uBAAuB,KAAK,IAAI,qBAAqB;CACtH,MAAM,aAAa,UAAU;CAC7B,MAAM,aAAa,UAAU;CAC7B,IAAI,uBAAuB,gBAAgB,OAAO,SAAS,aAAa,OAAO,cAAc;EAC3F,IAAI,EAAE,MAAM,UAAU,aAAa,GAAG,eAAe;EACrD,IAAI,gBAAgB,oBAAoB,iBAAiB;EACzD,IAAI,EAAE,MAAM,aAAa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