@tamagui/switch 1.123.10 → 1.123.12
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/createSwitch.cjs +28 -24
- package/dist/cjs/createSwitch.js +41 -48
- package/dist/cjs/createSwitch.js.map +1 -1
- package/dist/cjs/createSwitch.native.js +39 -29
- package/dist/cjs/createSwitch.native.js.map +2 -2
- package/dist/esm/createSwitch.js +42 -51
- package/dist/esm/createSwitch.js.map +1 -1
- package/dist/esm/createSwitch.mjs +29 -25
- package/dist/esm/createSwitch.mjs.map +1 -1
- package/dist/esm/createSwitch.native.js +41 -31
- package/dist/esm/createSwitch.native.js.map +2 -2
- package/dist/jsx/createSwitch.js +42 -51
- package/dist/jsx/createSwitch.js.map +1 -1
- package/dist/jsx/createSwitch.mjs +29 -25
- package/dist/jsx/createSwitch.mjs.map +1 -1
- package/dist/jsx/createSwitch.native.js +41 -31
- package/dist/jsx/createSwitch.native.js.map +2 -2
- package/package.json +13 -13
- package/src/createSwitch.tsx +39 -35
- package/types/createSwitch.d.ts.map +1 -1
|
@@ -114,53 +114,53 @@ function createSwitch(createProps) {
|
|
|
114
114
|
}),
|
|
115
115
|
styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context),
|
|
116
116
|
[frameWidth, setFrameWidth] = React.useState(0),
|
|
117
|
-
propsActive = (0, import_core.useProps)(props, {
|
|
118
|
-
noNormalize: !0,
|
|
119
|
-
noExpand: !0,
|
|
120
|
-
resolveValues: "none",
|
|
121
|
-
forComponent: Frame
|
|
122
|
-
}),
|
|
123
117
|
{
|
|
124
118
|
switchProps,
|
|
125
119
|
bubbleInput,
|
|
126
120
|
switchRef
|
|
127
121
|
} = (0, import_switch_headless.useSwitch)(
|
|
128
122
|
// @ts-ignore
|
|
129
|
-
|
|
130
|
-
size: styledContext.size ?? props.size ?? "$true",
|
|
131
|
-
unstyled: styledContext.unstyled ?? props.unstyled ?? !1
|
|
132
|
-
}, propsActive), [checked, setChecked], forwardedRef),
|
|
123
|
+
props, [checked, setChecked], forwardedRef),
|
|
133
124
|
renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
134
|
-
|
|
125
|
+
if (renderNative === "android" || renderNative === "ios") return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native.Switch, {
|
|
135
126
|
value: checked,
|
|
136
127
|
onValueChange: setChecked,
|
|
137
128
|
...nativeProps
|
|
138
|
-
})
|
|
139
|
-
|
|
129
|
+
});
|
|
130
|
+
const disabled = props.disabled,
|
|
131
|
+
value = React.useMemo(() => ({
|
|
140
132
|
checked,
|
|
141
|
-
disabled
|
|
133
|
+
disabled,
|
|
142
134
|
frameWidth
|
|
143
|
-
},
|
|
135
|
+
}), [checked, disabled, frameWidth]),
|
|
136
|
+
handleLayout = React.useCallback(e => {
|
|
137
|
+
setFrameWidth(e.nativeEvent.layout.width);
|
|
138
|
+
}, [setFrameWidth]),
|
|
139
|
+
unstyled = styledContext.unstyled ?? props.unstyled ?? !1;
|
|
140
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(SwitchContext.Provider, {
|
|
141
|
+
value,
|
|
144
142
|
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
|
|
145
143
|
ref: switchRef,
|
|
146
144
|
tag: "button",
|
|
147
145
|
...(import_core.isWeb && {
|
|
148
146
|
type: "button"
|
|
149
147
|
}),
|
|
148
|
+
...(!unstyled && {
|
|
149
|
+
size: styledContext.size ?? props.size ?? "$true"
|
|
150
|
+
}),
|
|
151
|
+
unstyled,
|
|
152
|
+
...props,
|
|
150
153
|
...switchProps,
|
|
151
154
|
...(!disableActiveTheme && !props.unstyled && {
|
|
152
155
|
theme: checked ? "active" : null,
|
|
153
156
|
themeShallow: !0
|
|
154
157
|
}),
|
|
155
158
|
checked,
|
|
156
|
-
disabled
|
|
157
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
setFrameWidth(e.nativeEvent.layout.width);
|
|
162
|
-
},
|
|
163
|
-
children: switchProps.children
|
|
159
|
+
disabled,
|
|
160
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native.View, {
|
|
161
|
+
style: measureContainerStyle,
|
|
162
|
+
onLayout: handleLayout,
|
|
163
|
+
children: props.children
|
|
164
164
|
})
|
|
165
165
|
}), bubbleInput]
|
|
166
166
|
});
|
|
@@ -170,4 +170,8 @@ function createSwitch(createProps) {
|
|
|
170
170
|
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
171
171
|
Thumb: SwitchThumbComponent
|
|
172
172
|
});
|
|
173
|
-
}
|
|
173
|
+
}
|
|
174
|
+
const measureContainerStyle = {
|
|
175
|
+
alignSelf: "stretch",
|
|
176
|
+
flex: 1
|
|
177
|
+
};
|
package/dist/cjs/createSwitch.js
CHANGED
|
@@ -81,58 +81,47 @@ function createSwitch(createProps) {
|
|
|
81
81
|
defaultProp: defaultChecked || !1,
|
|
82
82
|
onChange: onCheckedChange,
|
|
83
83
|
transition: !0
|
|
84
|
-
}), styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context), [frameWidth, setFrameWidth] = React.useState(0),
|
|
85
|
-
noNormalize: !0,
|
|
86
|
-
noExpand: !0,
|
|
87
|
-
resolveValues: "none",
|
|
88
|
-
forComponent: Frame
|
|
89
|
-
}), { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(
|
|
84
|
+
}), styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context), [frameWidth, setFrameWidth] = React.useState(0), { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(
|
|
90
85
|
// @ts-ignore
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
size: styledContext.size ?? props.size ?? "$true",
|
|
94
|
-
unstyled: styledContext.unstyled ?? props.unstyled ?? !1
|
|
95
|
-
},
|
|
96
|
-
propsActive
|
|
97
|
-
),
|
|
86
|
+
props,
|
|
98
87
|
[checked, setChecked],
|
|
99
88
|
forwardedRef
|
|
100
89
|
), renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
),
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
);
|
|
90
|
+
if (renderNative === "android" || renderNative === "ios")
|
|
91
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, { value: checked, onValueChange: setChecked, ...nativeProps });
|
|
92
|
+
const disabled = props.disabled, value = React.useMemo(
|
|
93
|
+
() => ({ checked, disabled, frameWidth }),
|
|
94
|
+
[checked, disabled, frameWidth]
|
|
95
|
+
), handleLayout = React.useCallback(
|
|
96
|
+
(e) => {
|
|
97
|
+
setFrameWidth(e.nativeEvent.layout.width);
|
|
98
|
+
},
|
|
99
|
+
[setFrameWidth]
|
|
100
|
+
), unstyled = styledContext.unstyled ?? props.unstyled ?? !1;
|
|
101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SwitchContext.Provider, { value, children: [
|
|
102
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
103
|
+
Frame,
|
|
104
|
+
{
|
|
105
|
+
ref: switchRef,
|
|
106
|
+
tag: "button",
|
|
107
|
+
...import_core.isWeb && { type: "button" },
|
|
108
|
+
...!unstyled && {
|
|
109
|
+
size: styledContext.size ?? props.size ?? "$true"
|
|
110
|
+
},
|
|
111
|
+
unstyled,
|
|
112
|
+
...props,
|
|
113
|
+
...switchProps,
|
|
114
|
+
...!disableActiveTheme && !props.unstyled && {
|
|
115
|
+
theme: checked ? "active" : null,
|
|
116
|
+
themeShallow: !0
|
|
117
|
+
},
|
|
118
|
+
checked,
|
|
119
|
+
disabled,
|
|
120
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: measureContainerStyle, onLayout: handleLayout, children: props.children })
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
bubbleInput
|
|
124
|
+
] });
|
|
136
125
|
},
|
|
137
126
|
{
|
|
138
127
|
disableTheme: !0
|
|
@@ -142,4 +131,8 @@ function createSwitch(createProps) {
|
|
|
142
131
|
Thumb: SwitchThumbComponent
|
|
143
132
|
});
|
|
144
133
|
}
|
|
134
|
+
const measureContainerStyle = {
|
|
135
|
+
alignSelf: "stretch",
|
|
136
|
+
flex: 1
|
|
137
|
+
};
|
|
145
138
|
//# sourceMappingURL=createSwitch.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createSwitch.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAKO,0BACP,mBAAkC,+BAKlC,yBAA0B,qCAC1B,gCAAqC,4CACrC,QAAuB,2BAMvB,sBAA6C,yBAE7C,uBAAoC,4BACpC,gBAA+D,qBAoFvD;AAhED,MAAM,gBAAgB,MAAM,cAIhC;AAAA,EACD,SAAS;AAAA,EACT,UAAU;AAAA,EACV,YAAY;AACd,CAAC;AAKM,SAAS,aAGd,aAAqE;AACrE,QAAM;AAAA,IACJ;AAAA,IACA,QAAQ,cAAAA;AAAA,IACR,QAAQ;AAAA,EAC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AAU,WAAW;AAAA,cAC5B,cAAc;AAAA,YAChB;AAAA,YAEF;AAAA,YACA;AAAA,YAEA,sDAAC,4BAAK,OAAO,uBAAuB,UAAU,cAC3C,gBAAM,UACT;AAAA;AAAA,QACF;AAAA,QAEC;AAAA,SACH;AAAA,IAEJ;AAAA,IACA;AAAA,MACE,cAAc;AAAA,IAChB;AAAA,EACF;AAEA,aAAO,kCAAqB,iBAAiB;AAAA,IAC3C,OAAO;AAAA,EACT,CAAC;AACH;AAEA,MAAM,wBAAwB;AAAA,EAC5B,WAAW;AAAA,EACX,MAAM;AACR;",
|
|
5
5
|
"names": ["DefaultSwitchFrame", "NativeSwitch"]
|
|
6
6
|
}
|
|
@@ -48,7 +48,6 @@ function createSwitch(createProps) {
|
|
|
48
48
|
},
|
|
49
49
|
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
50
50
|
x,
|
|
51
|
-
// TODO: remove ViewProps cast
|
|
52
51
|
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(e) {
|
|
53
52
|
return setThumbWidth(e.nativeEvent.layout.width);
|
|
54
53
|
}),
|
|
@@ -63,17 +62,9 @@ function createSwitch(createProps) {
|
|
|
63
62
|
defaultProp: defaultChecked || !1,
|
|
64
63
|
onChange: onCheckedChange,
|
|
65
64
|
transition: !0
|
|
66
|
-
}), styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context), [frameWidth, setFrameWidth] = React.useState(0),
|
|
67
|
-
noNormalize: !0,
|
|
68
|
-
noExpand: !0,
|
|
69
|
-
resolveValues: "none",
|
|
70
|
-
forComponent: Frame
|
|
71
|
-
}), _styledContext_size, _ref, _styledContext_unstyled, _ref1, { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(
|
|
65
|
+
}), styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context), [frameWidth, setFrameWidth] = React.useState(0), { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(
|
|
72
66
|
// @ts-ignore
|
|
73
|
-
|
|
74
|
-
size: (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : "$true",
|
|
75
|
-
unstyled: (_ref1 = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : props.unstyled) !== null && _ref1 !== void 0 ? _ref1 : !1
|
|
76
|
-
}, propsActive),
|
|
67
|
+
props,
|
|
77
68
|
[
|
|
78
69
|
checked,
|
|
79
70
|
setChecked
|
|
@@ -84,8 +75,8 @@ function createSwitch(createProps) {
|
|
|
84
75
|
if (props.id && !props.disabled)
|
|
85
76
|
return (0, import_focusable.registerFocusable)(props.id, {
|
|
86
77
|
focusAndSelect: function() {
|
|
87
|
-
setChecked == null || setChecked(function(
|
|
88
|
-
return !
|
|
78
|
+
setChecked == null || setChecked(function(value2) {
|
|
79
|
+
return !value2;
|
|
89
80
|
});
|
|
90
81
|
},
|
|
91
82
|
focus: function() {
|
|
@@ -96,16 +87,29 @@ function createSwitch(createProps) {
|
|
|
96
87
|
props.disabled
|
|
97
88
|
]);
|
|
98
89
|
var renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
90
|
+
if (renderNative === "android" || renderNative === "ios")
|
|
91
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, {
|
|
92
|
+
value: checked,
|
|
93
|
+
onValueChange: setChecked,
|
|
94
|
+
...nativeProps
|
|
95
|
+
});
|
|
96
|
+
var disabled = props.disabled, value = React.useMemo(function() {
|
|
97
|
+
return {
|
|
105
98
|
checked,
|
|
106
|
-
disabled
|
|
99
|
+
disabled,
|
|
107
100
|
frameWidth
|
|
108
|
-
}
|
|
101
|
+
};
|
|
102
|
+
}, [
|
|
103
|
+
checked,
|
|
104
|
+
disabled,
|
|
105
|
+
frameWidth
|
|
106
|
+
]), handleLayout = React.useCallback(function(e) {
|
|
107
|
+
setFrameWidth(e.nativeEvent.layout.width);
|
|
108
|
+
}, [
|
|
109
|
+
setFrameWidth
|
|
110
|
+
]), _styledContext_unstyled, _ref, unstyled = (_ref = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : props.unstyled) !== null && _ref !== void 0 ? _ref : !1, _styledContext_size, _ref1;
|
|
111
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SwitchContext.Provider, {
|
|
112
|
+
value,
|
|
109
113
|
children: [
|
|
110
114
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
|
|
111
115
|
ref: switchRef,
|
|
@@ -113,6 +117,11 @@ function createSwitch(createProps) {
|
|
|
113
117
|
...import_core.isWeb && {
|
|
114
118
|
type: "button"
|
|
115
119
|
},
|
|
120
|
+
...!unstyled && {
|
|
121
|
+
size: (_ref1 = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref1 !== void 0 ? _ref1 : "$true"
|
|
122
|
+
},
|
|
123
|
+
unstyled,
|
|
124
|
+
...props,
|
|
116
125
|
...switchProps,
|
|
117
126
|
...!disableActiveTheme && !props.unstyled && {
|
|
118
127
|
theme: checked ? "active" : null,
|
|
@@ -120,14 +129,11 @@ function createSwitch(createProps) {
|
|
|
120
129
|
},
|
|
121
130
|
// expected variants
|
|
122
131
|
checked,
|
|
123
|
-
disabled
|
|
124
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
setFrameWidth(e.nativeEvent.layout.width);
|
|
129
|
-
},
|
|
130
|
-
children: switchProps.children
|
|
132
|
+
disabled,
|
|
133
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {
|
|
134
|
+
style: measureContainerStyle,
|
|
135
|
+
onLayout: handleLayout,
|
|
136
|
+
children: props.children
|
|
131
137
|
})
|
|
132
138
|
}),
|
|
133
139
|
bubbleInput
|
|
@@ -140,6 +146,10 @@ function createSwitch(createProps) {
|
|
|
140
146
|
Thumb: SwitchThumbComponent
|
|
141
147
|
});
|
|
142
148
|
}
|
|
149
|
+
var measureContainerStyle = {
|
|
150
|
+
alignSelf: "stretch",
|
|
151
|
+
flex: 1
|
|
152
|
+
};
|
|
143
153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
144
154
|
0 && (module.exports = {
|
|
145
155
|
SwitchContext,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Users/n8/tamagui/code/ui/switch/src/createSwitch.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDACA,
|
|
5
|
-
"names": ["SwitchContext", "React", "createContext", "checked", "disabled", "frameWidth", "createSwitch", "createProps", "disableActiveTheme", "Frame", "DefaultSwitchFrame", "Thumb", "SwitchThumb", "process", "env", "NODE_ENV", "staticConfig", "context", "SwitchStyledContext", "console", "warn", "SwitchThumbComponent", "styleable", "props", "forwardedRef", "size", "sizeProp", "unstyled", "unstyledProp", "nativeID", "thumbProps", "useContext", "styledContext", "useStyledContext", "unstyledContext", "sizeContext", "TAMAGUI_HEADLESS", "initialChecked", "useRef", "current", "thumbWidth", "setThumbWidth", "useState", "distance", "x", "_jsx", "ref", "theme", "alignSelf", "onLayout", "composeEventHandlers", "e", "nativeEvent", "layout", "width", "SwitchComponent", "_props", "native", "nativeProps", "checkedProp", "defaultChecked", "onCheckedChange", "setChecked", "useControllableState", "prop", "defaultProp", "onChange", "transition", "setFrameWidth", "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDACA,cAKO,0BACP,mBAAkC,+BAKlC,yBAA0B,qCAC1B,gCAAqC,4CACrC,QAAuB,2BAMvB,sBAA6C,yBAE7C,uBAAoC,4BACpC,gB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hF;QAASC;QAAUC;MAAW;OACvC;MAACF;MAASC;MAAUC;KAAW,GAG3B+E,eAAenF,MAAMoF,YACzB,SAAClC,GAAAA;AACCiB,oBAAcjB,EAAEC,YAAYC,OAAOC,KAAK;IAC1C,GACA;MAACc;KAAc,GAGApC,yBAAAA,MAAXL,YAAWK,QAAAA,0BAAAA,cAAcL,cAAQ,QAAtBK,4BAAAA,SAAAA,0BAA0BT,MAAMI,cAAQ,QAAxCK,SAAAA,SAAAA,OAA4C,IAS/CA,qBAAAA;AAPd,WACE,uCAAAsD,MAACtF,cAAcuF,UAAQ;MAACV;;QACtB,uCAAAhC,KAACpC,OAAAA;UACCqC,KAAKyB;UACLiB,KAAI;UACH,GAAIC,qBAAS;YAAEC,MAAM;UAAS;UAC9B,GAAI,CAAC/D,YAAY;YAChBF,OAAMO,SAAAA,sBAAAA,cAAcP,UAAI,QAAlBO,wBAAAA,SAAAA,sBAAsBT,MAAME,UAAI,QAAhCO,UAAAA,SAAAA,QAAoC;UAC5C;UACAL;UACC,GAAGJ;UACH,GAAI8C;UACJ,GAAI,CAAC7D,sBACJ,CAACe,MAAMI,YAAY;YACjBoB,OAAO5C,UAAU,WAAW;YAC5BwF,cAAc;UAChB;;UAEFxF;UACAC;oBAEA,uCAAAyC,KAAC+C,0BAAAA;YAAKC,OAAOC;YAAuB7C,UAAUmC;sBAC3C7D,MAAMwE;;;QAIVzB;;;EAGP,GACA;IACE0B,cAAc;EAChB,CAAA;AAGF,aAAOC,kCAAqB1C,iBAAiB;IAC3C5C,OAAOU;EACT,CAAA;AACF;AAEA,IAAMyE,wBAAwB;EAC5B9C,WAAW;EACXkD,MAAM;AACR;",
|
|
5
|
+
"names": ["SwitchContext", "React", "createContext", "checked", "disabled", "frameWidth", "createSwitch", "createProps", "disableActiveTheme", "Frame", "DefaultSwitchFrame", "Thumb", "SwitchThumb", "process", "env", "NODE_ENV", "staticConfig", "context", "SwitchStyledContext", "console", "warn", "SwitchThumbComponent", "styleable", "props", "forwardedRef", "size", "sizeProp", "unstyled", "unstyledProp", "nativeID", "thumbProps", "useContext", "styledContext", "useStyledContext", "unstyledContext", "sizeContext", "TAMAGUI_HEADLESS", "initialChecked", "useRef", "current", "thumbWidth", "setThumbWidth", "useState", "distance", "x", "_jsx", "ref", "theme", "alignSelf", "onLayout", "composeEventHandlers", "e", "nativeEvent", "layout", "width", "SwitchComponent", "_props", "native", "nativeProps", "checkedProp", "defaultChecked", "onCheckedChange", "setChecked", "useControllableState", "prop", "defaultProp", "onChange", "transition", "setFrameWidth", "switchProps", "bubbleInput", "switchRef", "useSwitch", "useEffect", "id", "registerFocusable", "focusAndSelect", "value", "focus", "renderNative", "shouldRenderNativePlatform", "NativeSwitch", "onValueChange", "useMemo", "handleLayout", "useCallback", "_jsxs", "Provider", "tag", "isWeb", "type", "themeShallow", "View", "style", "measureContainerStyle", "children", "disableTheme", "withStaticProperties", "flex"]
|
|
6
6
|
}
|
package/dist/esm/createSwitch.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Stack,
|
|
3
2
|
composeEventHandlers,
|
|
4
3
|
isWeb,
|
|
5
4
|
shouldRenderNativePlatform,
|
|
6
|
-
useProps,
|
|
7
5
|
withStaticProperties
|
|
8
6
|
} from "@tamagui/core";
|
|
9
7
|
|
|
10
8
|
import { useSwitch } from "@tamagui/switch-headless";
|
|
11
9
|
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
12
10
|
import * as React from "react";
|
|
13
|
-
import { Switch as NativeSwitch } from "react-native-web";
|
|
11
|
+
import { Switch as NativeSwitch, View } from "react-native-web";
|
|
14
12
|
import { SwitchStyledContext } from "./StyledContext";
|
|
15
13
|
import { SwitchFrame as DefaultSwitchFrame, SwitchThumb } from "./Switch";
|
|
16
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -68,58 +66,47 @@ function createSwitch(createProps) {
|
|
|
68
66
|
defaultProp: defaultChecked || !1,
|
|
69
67
|
onChange: onCheckedChange,
|
|
70
68
|
transition: !0
|
|
71
|
-
}), styledContext = React.useContext(SwitchStyledContext.context), [frameWidth, setFrameWidth] = React.useState(0),
|
|
72
|
-
noNormalize: !0,
|
|
73
|
-
noExpand: !0,
|
|
74
|
-
resolveValues: "none",
|
|
75
|
-
forComponent: Frame
|
|
76
|
-
}), { switchProps, bubbleInput, switchRef } = useSwitch(
|
|
69
|
+
}), styledContext = React.useContext(SwitchStyledContext.context), [frameWidth, setFrameWidth] = React.useState(0), { switchProps, bubbleInput, switchRef } = useSwitch(
|
|
77
70
|
// @ts-ignore
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
size: styledContext.size ?? props.size ?? "$true",
|
|
81
|
-
unstyled: styledContext.unstyled ?? props.unstyled ?? !1
|
|
82
|
-
},
|
|
83
|
-
propsActive
|
|
84
|
-
),
|
|
71
|
+
props,
|
|
85
72
|
[checked, setChecked],
|
|
86
73
|
forwardedRef
|
|
87
74
|
), renderNative = shouldRenderNativePlatform(native);
|
|
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
|
-
);
|
|
75
|
+
if (renderNative === "android" || renderNative === "ios")
|
|
76
|
+
return /* @__PURE__ */ jsx(NativeSwitch, { value: checked, onValueChange: setChecked, ...nativeProps });
|
|
77
|
+
const disabled = props.disabled, value = React.useMemo(
|
|
78
|
+
() => ({ checked, disabled, frameWidth }),
|
|
79
|
+
[checked, disabled, frameWidth]
|
|
80
|
+
), handleLayout = React.useCallback(
|
|
81
|
+
(e) => {
|
|
82
|
+
setFrameWidth(e.nativeEvent.layout.width);
|
|
83
|
+
},
|
|
84
|
+
[setFrameWidth]
|
|
85
|
+
), unstyled = styledContext.unstyled ?? props.unstyled ?? !1;
|
|
86
|
+
return /* @__PURE__ */ jsxs(SwitchContext.Provider, { value, children: [
|
|
87
|
+
/* @__PURE__ */ jsx(
|
|
88
|
+
Frame,
|
|
89
|
+
{
|
|
90
|
+
ref: switchRef,
|
|
91
|
+
tag: "button",
|
|
92
|
+
...isWeb && { type: "button" },
|
|
93
|
+
...!unstyled && {
|
|
94
|
+
size: styledContext.size ?? props.size ?? "$true"
|
|
95
|
+
},
|
|
96
|
+
unstyled,
|
|
97
|
+
...props,
|
|
98
|
+
...switchProps,
|
|
99
|
+
...!disableActiveTheme && !props.unstyled && {
|
|
100
|
+
theme: checked ? "active" : null,
|
|
101
|
+
themeShallow: !0
|
|
102
|
+
},
|
|
103
|
+
checked,
|
|
104
|
+
disabled,
|
|
105
|
+
children: /* @__PURE__ */ jsx(View, { style: measureContainerStyle, onLayout: handleLayout, children: props.children })
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
bubbleInput
|
|
109
|
+
] });
|
|
123
110
|
},
|
|
124
111
|
{
|
|
125
112
|
disableTheme: !0
|
|
@@ -129,6 +116,10 @@ function createSwitch(createProps) {
|
|
|
129
116
|
Thumb: SwitchThumbComponent
|
|
130
117
|
});
|
|
131
118
|
}
|
|
119
|
+
const measureContainerStyle = {
|
|
120
|
+
alignSelf: "stretch",
|
|
121
|
+
flex: 1
|
|
122
|
+
};
|
|
132
123
|
export {
|
|
133
124
|
SwitchContext,
|
|
134
125
|
createSwitch
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createSwitch.tsx"],
|
|
4
|
-
"mappings": "AACA;AAAA,EACE;AA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ACxB,wBAAc,EAAE,YAAY,OAAO,KAAK;AAAA,QAC1C;AAAA,QACA,CAAC,aAAa;AAAA,MAChB,GAEM,WAAW,cAAc,YAAY,MAAM,YAAY;AAE7D,aACE,qBAAC,cAAc,UAAd,EAAuB,OACtB;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,KAAK;AAAA,YACL,KAAI;AAAA,YACH,GAAI,SAAS,EAAE,MAAM,SAAS;AAAA,YAC9B,GAAI,CAAC,YAAY;AAAA,cAChB,MAAM,cAAc,QAAQ,MAAM,QAAQ;AAAA,YAC5C;AAAA,YACA;AAAA,YACC,GAAG;AAAA,YACH,GAAI;AAAA,YACJ,GAAI,CAAC,sBACJ,CAAC,MAAM,YAAY;AAAA,cACjB,OAAO,UAAU,WAAW;AAAA,cAC5B,cAAc;AAAA,YAChB;AAAA,YAEF;AAAA,YACA;AAAA,YAEA,8BAAC,QAAK,OAAO,uBAAuB,UAAU,cAC3C,gBAAM,UACT;AAAA;AAAA,QACF;AAAA,QAEC;AAAA,SACH;AAAA,IAEJ;AAAA,IACA;AAAA,MACE,cAAc;AAAA,IAChB;AAAA,EACF;AAEA,SAAO,qBAAqB,iBAAiB;AAAA,IAC3C,OAAO;AAAA,EACT,CAAC;AACH;AAEA,MAAM,wBAAwB;AAAA,EAC5B,WAAW;AAAA,EACX,MAAM;AACR;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { composeEventHandlers, isWeb, shouldRenderNativePlatform, 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";
|
|
5
|
-
import { Switch as NativeSwitch } from "react-native-web";
|
|
5
|
+
import { Switch as NativeSwitch, View } from "react-native-web";
|
|
6
6
|
import { SwitchStyledContext } from "./StyledContext.mjs";
|
|
7
7
|
import { SwitchFrame as DefaultSwitchFrame, SwitchThumb } from "./Switch.mjs";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -76,53 +76,53 @@ function createSwitch(createProps) {
|
|
|
76
76
|
}),
|
|
77
77
|
styledContext = React.useContext(SwitchStyledContext.context),
|
|
78
78
|
[frameWidth, setFrameWidth] = React.useState(0),
|
|
79
|
-
propsActive = useProps(props, {
|
|
80
|
-
noNormalize: !0,
|
|
81
|
-
noExpand: !0,
|
|
82
|
-
resolveValues: "none",
|
|
83
|
-
forComponent: Frame
|
|
84
|
-
}),
|
|
85
79
|
{
|
|
86
80
|
switchProps,
|
|
87
81
|
bubbleInput,
|
|
88
82
|
switchRef
|
|
89
83
|
} = useSwitch(
|
|
90
84
|
// @ts-ignore
|
|
91
|
-
|
|
92
|
-
size: styledContext.size ?? props.size ?? "$true",
|
|
93
|
-
unstyled: styledContext.unstyled ?? props.unstyled ?? !1
|
|
94
|
-
}, propsActive), [checked, setChecked], forwardedRef),
|
|
85
|
+
props, [checked, setChecked], forwardedRef),
|
|
95
86
|
renderNative = shouldRenderNativePlatform(native);
|
|
96
|
-
|
|
87
|
+
if (renderNative === "android" || renderNative === "ios") return /* @__PURE__ */jsx(NativeSwitch, {
|
|
97
88
|
value: checked,
|
|
98
89
|
onValueChange: setChecked,
|
|
99
90
|
...nativeProps
|
|
100
|
-
})
|
|
101
|
-
|
|
91
|
+
});
|
|
92
|
+
const disabled = props.disabled,
|
|
93
|
+
value = React.useMemo(() => ({
|
|
102
94
|
checked,
|
|
103
|
-
disabled
|
|
95
|
+
disabled,
|
|
104
96
|
frameWidth
|
|
105
|
-
},
|
|
97
|
+
}), [checked, disabled, frameWidth]),
|
|
98
|
+
handleLayout = React.useCallback(e => {
|
|
99
|
+
setFrameWidth(e.nativeEvent.layout.width);
|
|
100
|
+
}, [setFrameWidth]),
|
|
101
|
+
unstyled = styledContext.unstyled ?? props.unstyled ?? !1;
|
|
102
|
+
return /* @__PURE__ */jsxs(SwitchContext.Provider, {
|
|
103
|
+
value,
|
|
106
104
|
children: [/* @__PURE__ */jsx(Frame, {
|
|
107
105
|
ref: switchRef,
|
|
108
106
|
tag: "button",
|
|
109
107
|
...(isWeb && {
|
|
110
108
|
type: "button"
|
|
111
109
|
}),
|
|
110
|
+
...(!unstyled && {
|
|
111
|
+
size: styledContext.size ?? props.size ?? "$true"
|
|
112
|
+
}),
|
|
113
|
+
unstyled,
|
|
114
|
+
...props,
|
|
112
115
|
...switchProps,
|
|
113
116
|
...(!disableActiveTheme && !props.unstyled && {
|
|
114
117
|
theme: checked ? "active" : null,
|
|
115
118
|
themeShallow: !0
|
|
116
119
|
}),
|
|
117
120
|
checked,
|
|
118
|
-
disabled
|
|
119
|
-
children: /* @__PURE__ */jsx(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
setFrameWidth(e.nativeEvent.layout.width);
|
|
124
|
-
},
|
|
125
|
-
children: switchProps.children
|
|
121
|
+
disabled,
|
|
122
|
+
children: /* @__PURE__ */jsx(View, {
|
|
123
|
+
style: measureContainerStyle,
|
|
124
|
+
onLayout: handleLayout,
|
|
125
|
+
children: props.children
|
|
126
126
|
})
|
|
127
127
|
}), bubbleInput]
|
|
128
128
|
});
|
|
@@ -133,5 +133,9 @@ function createSwitch(createProps) {
|
|
|
133
133
|
Thumb: SwitchThumbComponent
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
+
const measureContainerStyle = {
|
|
137
|
+
alignSelf: "stretch",
|
|
138
|
+
flex: 1
|
|
139
|
+
};
|
|
136
140
|
export { SwitchContext, createSwitch };
|
|
137
141
|
//# sourceMappingURL=createSwitch.mjs.map
|