@tamagui/switch 2.0.0-rc.4 → 2.0.0-rc.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/StyledContext.cjs +14 -12
- package/dist/cjs/StyledContext.native.js +20 -18
- package/dist/cjs/StyledContext.native.js.map +1 -1
- package/dist/cjs/Switch.cjs +76 -74
- package/dist/cjs/Switch.native.js +81 -80
- package/dist/cjs/Switch.native.js.map +1 -1
- package/dist/cjs/createSwitch.cjs +156 -144
- package/dist/cjs/createSwitch.native.js +161 -153
- package/dist/cjs/createSwitch.native.js.map +1 -1
- package/dist/cjs/index.cjs +15 -13
- package/dist/cjs/index.native.js +20 -18
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +7 -5
- package/dist/cjs/types.native.js +7 -5
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useSwitchNative.cjs +12 -10
- package/dist/cjs/useSwitchNative.native.js +40 -33
- package/dist/cjs/useSwitchNative.native.js.map +1 -1
- package/dist/esm/StyledContext.mjs +2 -2
- package/dist/esm/StyledContext.native.js +2 -2
- package/dist/esm/Switch.mjs +61 -61
- package/dist/esm/Switch.mjs.map +1 -1
- package/dist/esm/Switch.native.js +65 -66
- package/dist/esm/Switch.native.js.map +1 -1
- package/dist/esm/createSwitch.mjs +124 -114
- package/dist/esm/createSwitch.mjs.map +1 -1
- package/dist/esm/createSwitch.native.js +129 -123
- package/dist/esm/createSwitch.native.js.map +1 -1
- package/dist/esm/index.js +8 -11
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/useSwitchNative.native.js +11 -6
- package/dist/esm/useSwitchNative.native.js.map +1 -1
- package/dist/jsx/StyledContext.mjs +2 -2
- package/dist/jsx/StyledContext.native.js +20 -18
- package/dist/jsx/StyledContext.native.js.map +1 -1
- package/dist/jsx/Switch.mjs +61 -61
- package/dist/jsx/Switch.mjs.map +1 -1
- package/dist/jsx/Switch.native.js +81 -80
- package/dist/jsx/Switch.native.js.map +1 -1
- package/dist/jsx/createSwitch.mjs +124 -114
- package/dist/jsx/createSwitch.mjs.map +1 -1
- package/dist/jsx/createSwitch.native.js +161 -153
- package/dist/jsx/createSwitch.native.js.map +1 -1
- package/dist/jsx/index.js +8 -11
- package/dist/jsx/index.js.map +1 -6
- package/dist/jsx/index.native.js +20 -18
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/types.native.js +7 -5
- package/dist/jsx/useSwitchNative.native.js +40 -33
- package/dist/jsx/useSwitchNative.native.js.map +1 -1
- package/package.json +17 -20
- package/types/createSwitch.d.ts +4 -4
- package/types/index.d.ts +4 -4
- package/dist/cjs/StyledContext.js +0 -28
- package/dist/cjs/StyledContext.js.map +0 -6
- package/dist/cjs/Switch.js +0 -93
- package/dist/cjs/Switch.js.map +0 -6
- package/dist/cjs/createSwitch.js +0 -146
- package/dist/cjs/createSwitch.js.map +0 -6
- package/dist/cjs/index.js +0 -31
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/types.js +0 -14
- package/dist/cjs/types.js.map +0 -6
- package/dist/cjs/useSwitchNative.js +0 -23
- package/dist/cjs/useSwitchNative.js.map +0 -6
- package/dist/esm/StyledContext.js +0 -12
- package/dist/esm/StyledContext.js.map +0 -6
- package/dist/esm/Switch.js +0 -79
- package/dist/esm/Switch.js.map +0 -6
- package/dist/esm/createSwitch.js +0 -135
- package/dist/esm/createSwitch.js.map +0 -6
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -6
- package/dist/esm/useSwitchNative.js +0 -7
- package/dist/esm/useSwitchNative.js.map +0 -6
- package/dist/jsx/StyledContext.js +0 -12
- package/dist/jsx/StyledContext.js.map +0 -6
- package/dist/jsx/Switch.js +0 -79
- package/dist/jsx/Switch.js.map +0 -6
- package/dist/jsx/createSwitch.js +0 -135
- package/dist/jsx/createSwitch.js.map +0 -6
- package/dist/jsx/types.js +0 -1
- package/dist/jsx/types.js.map +0 -6
- package/dist/jsx/useSwitchNative.js +0 -7
- package/dist/jsx/useSwitchNative.js.map +0 -6
|
@@ -11,127 +11,137 @@ function createSwitch(createProps) {
|
|
|
11
11
|
Frame = DefaultSwitchFrame,
|
|
12
12
|
Thumb = SwitchThumb
|
|
13
13
|
} = createProps;
|
|
14
|
-
process.env.NODE_ENV === "development"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
14
|
+
if (process.env.NODE_ENV === "development") {
|
|
15
|
+
if (Frame !== DefaultSwitchFrame && Frame.staticConfig.context && Frame.staticConfig.context !== SwitchStyledContext || Thumb !== SwitchThumb && Thumb.staticConfig.context && Thumb.staticConfig.context !== SwitchStyledContext) {
|
|
16
|
+
console.warn(`Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
Frame.staticConfig.context = SwitchStyledContext;
|
|
20
|
+
Thumb.staticConfig.context = SwitchStyledContext;
|
|
21
|
+
const SwitchThumbComponent = Thumb.styleable(function SwitchThumb2(props, forwardedRef) {
|
|
22
|
+
const {
|
|
23
|
+
size: sizeProp,
|
|
24
|
+
unstyled: unstyledProp,
|
|
25
|
+
activeStyle,
|
|
26
|
+
...thumbProps
|
|
27
|
+
} = props;
|
|
28
|
+
const styledContext = SwitchStyledContext.useStyledContext();
|
|
29
|
+
const {
|
|
30
|
+
unstyled: unstyledContext,
|
|
31
|
+
size: sizeContext,
|
|
32
|
+
active,
|
|
33
|
+
disabled,
|
|
34
|
+
frameWidth = 0
|
|
35
|
+
} = styledContext;
|
|
36
|
+
const unstyled = process.env.TAMAGUI_HEADLESS === "1" ? true : unstyledProp ?? unstyledContext ?? false;
|
|
37
|
+
const size = sizeProp ?? sizeContext ?? "$true";
|
|
38
|
+
const initialChecked = React.useRef(active).current;
|
|
39
|
+
const initialWidth = getVariableValue(props.width || size, "size");
|
|
40
|
+
const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
41
|
+
const distance = frameWidth - thumbWidth;
|
|
42
|
+
const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
43
|
+
return /* @__PURE__ */jsx(Thumb, {
|
|
44
|
+
ref: forwardedRef,
|
|
45
|
+
unstyled,
|
|
46
|
+
...(unstyled === false && {
|
|
47
|
+
size
|
|
48
|
+
}),
|
|
49
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
50
|
+
x,
|
|
51
|
+
onLayout: composeEventHandlers(props.onLayout, e => {
|
|
52
|
+
const next = e.nativeEvent.layout.width;
|
|
53
|
+
setThumbWidth(next);
|
|
54
|
+
}),
|
|
55
|
+
disabled,
|
|
56
|
+
...thumbProps,
|
|
57
|
+
...(active && activeStyle)
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
const SwitchComponent = Frame.styleable(function SwitchFrame(_props, forwardedRef) {
|
|
61
|
+
const {
|
|
62
|
+
native,
|
|
63
|
+
nativeProps,
|
|
64
|
+
checked: checkedProp,
|
|
65
|
+
defaultChecked,
|
|
66
|
+
onCheckedChange,
|
|
67
|
+
activeStyle,
|
|
68
|
+
unstyled: unstyledProp,
|
|
69
|
+
activeTheme: activeThemeProp,
|
|
70
|
+
...props
|
|
71
|
+
} = _props;
|
|
72
|
+
const [checked, setChecked] = useControllableState({
|
|
73
|
+
prop: checkedProp,
|
|
74
|
+
defaultProp: defaultChecked || false,
|
|
75
|
+
onChange: onCheckedChange,
|
|
76
|
+
transition: true
|
|
77
|
+
});
|
|
78
|
+
const styledContext = React.useContext(SwitchStyledContext.context);
|
|
79
|
+
const [frameWidth, setFrameInnerWidth] = React.useState(0);
|
|
80
|
+
const {
|
|
81
|
+
switchProps,
|
|
82
|
+
bubbleInput,
|
|
83
|
+
switchRef
|
|
84
|
+
} = useSwitch(props, [checked, setChecked],
|
|
85
|
+
// @ts-ignore TODO tamagui react 19 type error
|
|
86
|
+
forwardedRef);
|
|
87
|
+
const nativeSwitch = useSwitchNative({
|
|
88
|
+
id: props.id,
|
|
89
|
+
disabled: props.disabled,
|
|
90
|
+
native,
|
|
91
|
+
nativeProps,
|
|
92
|
+
checked,
|
|
93
|
+
setChecked
|
|
94
|
+
});
|
|
95
|
+
if (nativeSwitch) {
|
|
96
|
+
return nativeSwitch;
|
|
97
|
+
}
|
|
98
|
+
const disabled = props.disabled;
|
|
99
|
+
const handleLayout = e => {
|
|
100
|
+
const next = e.nativeEvent.layout.width;
|
|
101
|
+
if (next !== frameWidth) {
|
|
102
|
+
setFrameInnerWidth(next);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const unstyled = styledContext.unstyled ?? unstyledProp ?? false;
|
|
106
|
+
return /* @__PURE__ */jsxs(Fragment, {
|
|
107
|
+
children: [/* @__PURE__ */jsx(SwitchStyledContext.Provider, {
|
|
108
|
+
size: styledContext.size ?? props.size ?? "$true",
|
|
39
109
|
unstyled,
|
|
40
|
-
|
|
41
|
-
size
|
|
42
|
-
}),
|
|
43
|
-
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
44
|
-
x,
|
|
45
|
-
onLayout: composeEventHandlers(props.onLayout, e => {
|
|
46
|
-
const next = e.nativeEvent.layout.width;
|
|
47
|
-
setThumbWidth(next);
|
|
48
|
-
}),
|
|
110
|
+
active: checked,
|
|
49
111
|
disabled,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
activeStyle,
|
|
62
|
-
unstyled: unstyledProp,
|
|
63
|
-
activeTheme: activeThemeProp,
|
|
64
|
-
...props
|
|
65
|
-
} = _props,
|
|
66
|
-
[checked, setChecked] = useControllableState({
|
|
67
|
-
prop: checkedProp,
|
|
68
|
-
defaultProp: defaultChecked || !1,
|
|
69
|
-
onChange: onCheckedChange,
|
|
70
|
-
transition: !0
|
|
71
|
-
}),
|
|
72
|
-
styledContext = React.useContext(SwitchStyledContext.context),
|
|
73
|
-
[frameWidth, setFrameInnerWidth] = React.useState(0),
|
|
74
|
-
{
|
|
75
|
-
switchProps,
|
|
76
|
-
bubbleInput,
|
|
77
|
-
switchRef
|
|
78
|
-
} = useSwitch(props, [checked, setChecked],
|
|
79
|
-
// @ts-ignore TODO tamagui react 19 type error
|
|
80
|
-
forwardedRef),
|
|
81
|
-
nativeSwitch = useSwitchNative({
|
|
82
|
-
id: props.id,
|
|
83
|
-
disabled: props.disabled,
|
|
84
|
-
native,
|
|
85
|
-
nativeProps,
|
|
86
|
-
checked,
|
|
87
|
-
setChecked
|
|
88
|
-
});
|
|
89
|
-
if (nativeSwitch) return nativeSwitch;
|
|
90
|
-
const disabled = props.disabled,
|
|
91
|
-
handleLayout = e => {
|
|
92
|
-
const next = e.nativeEvent.layout.width;
|
|
93
|
-
next !== frameWidth && setFrameInnerWidth(next);
|
|
94
|
-
},
|
|
95
|
-
unstyled = styledContext.unstyled ?? unstyledProp ?? !1;
|
|
96
|
-
return /* @__PURE__ */jsxs(Fragment, {
|
|
97
|
-
children: [/* @__PURE__ */jsx(SwitchStyledContext.Provider, {
|
|
98
|
-
size: styledContext.size ?? props.size ?? "$true",
|
|
112
|
+
frameWidth,
|
|
113
|
+
children: /* @__PURE__ */jsx(Frame, {
|
|
114
|
+
ref: switchRef,
|
|
115
|
+
render: "button",
|
|
116
|
+
theme: activeThemeProp ?? null,
|
|
117
|
+
...(isWeb && {
|
|
118
|
+
type: "button"
|
|
119
|
+
}),
|
|
120
|
+
...(!unstyled && {
|
|
121
|
+
size: styledContext.size ?? props.size ?? "$true"
|
|
122
|
+
}),
|
|
99
123
|
unstyled,
|
|
100
|
-
|
|
124
|
+
...props,
|
|
125
|
+
...switchProps,
|
|
101
126
|
disabled,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
render: "button",
|
|
106
|
-
theme: activeThemeProp ?? null,
|
|
107
|
-
...(isWeb && {
|
|
108
|
-
type: "button"
|
|
109
|
-
}),
|
|
110
|
-
...(!unstyled && {
|
|
111
|
-
size: styledContext.size ?? props.size ?? "$true"
|
|
127
|
+
...(checked && {
|
|
128
|
+
...(!unstyled && !activeStyle && {
|
|
129
|
+
backgroundColor: "$backgroundActive"
|
|
112
130
|
}),
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}),
|
|
121
|
-
...activeStyle
|
|
122
|
-
}),
|
|
123
|
-
children: /* @__PURE__ */jsx(View, {
|
|
124
|
-
alignSelf: "stretch",
|
|
125
|
-
flex: 1,
|
|
126
|
-
onLayout: handleLayout,
|
|
127
|
-
children: props.children
|
|
128
|
-
})
|
|
131
|
+
...activeStyle
|
|
132
|
+
}),
|
|
133
|
+
children: /* @__PURE__ */jsx(View, {
|
|
134
|
+
alignSelf: "stretch",
|
|
135
|
+
flex: 1,
|
|
136
|
+
onLayout: handleLayout,
|
|
137
|
+
children: props.children
|
|
129
138
|
})
|
|
130
|
-
})
|
|
131
|
-
})
|
|
132
|
-
}, {
|
|
133
|
-
disableTheme: !0
|
|
139
|
+
})
|
|
140
|
+
}), bubbleInput]
|
|
134
141
|
});
|
|
142
|
+
}, {
|
|
143
|
+
disableTheme: true
|
|
144
|
+
});
|
|
135
145
|
return withStaticProperties(SwitchComponent, {
|
|
136
146
|
Thumb: SwitchThumbComponent
|
|
137
147
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["composeEventHandlers","getVariableValue","isWeb","View","withStaticProperties","useSwitch","useControllableState","React","SwitchStyledContext","SwitchFrame","DefaultSwitchFrame","SwitchThumb","useSwitchNative","Fragment","jsx","jsxs","createSwitch","createProps","Frame","Thumb","process","env","NODE_ENV","staticConfig","context","console","warn","SwitchThumbComponent","styleable","props","forwardedRef","size","sizeProp","unstyled","unstyledProp","activeStyle","thumbProps","styledContext","useStyledContext","unstyledContext","sizeContext","active","disabled","frameWidth","TAMAGUI_HEADLESS","initialChecked","useRef","current","initialWidth","width","thumbWidth","setThumbWidth","useState","distance","x","ref","alignSelf","onLayout","e","next","nativeEvent","layout","SwitchComponent","_props","native","nativeProps","checked","checkedProp","defaultChecked","onCheckedChange","activeTheme","activeThemeProp","setChecked","prop","defaultProp","onChange","transition","useContext","setFrameInnerWidth","switchProps","bubbleInput","switchRef","nativeSwitch","id","handleLayout","children","Provider","render","theme","type","backgroundColor","flex","disableTheme"],"sources":["../../src/createSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SACEA,oBAAA,EACAC,gBAAA,EACAC,KAAA,EACAC,IAAA,EACAC,oBAAA,QACK;AACP,SAASC,SAAA,QAAiB;AAC1B,SAASC,oBAAA,QAA4B;AACrC,YAAYC,KAAA,MAAW;AAEvB,SAASC,mBAAA,QAA2B;AACpC,SAASC,WAAA,IAAeC,kBAAA,EAAoBC,WAAA,QAAmB;AAQ/D,SAASC,eAAA,QAAuB;AAwDxB,SA6EAC,QAAA,EA7EAC,GAAA,EA6EAC,IAAA,QA7EA;AApDD,SAASC,aAGdC,WAAA,EAAuC;EACvC,MAAM;IAAEC,KAAA,GAAQR,kBAAA;IAAoBS,KAAA,GAAQR;EAAY,IAAIM,WAAA;
|
|
1
|
+
{"version":3,"names":["composeEventHandlers","getVariableValue","isWeb","View","withStaticProperties","useSwitch","useControllableState","React","SwitchStyledContext","SwitchFrame","DefaultSwitchFrame","SwitchThumb","useSwitchNative","Fragment","jsx","jsxs","createSwitch","createProps","Frame","Thumb","process","env","NODE_ENV","staticConfig","context","console","warn","SwitchThumbComponent","styleable","SwitchThumb2","props","forwardedRef","size","sizeProp","unstyled","unstyledProp","activeStyle","thumbProps","styledContext","useStyledContext","unstyledContext","sizeContext","active","disabled","frameWidth","TAMAGUI_HEADLESS","initialChecked","useRef","current","initialWidth","width","thumbWidth","setThumbWidth","useState","distance","x","ref","alignSelf","onLayout","e","next","nativeEvent","layout","SwitchComponent","_props","native","nativeProps","checked","checkedProp","defaultChecked","onCheckedChange","activeTheme","activeThemeProp","setChecked","prop","defaultProp","onChange","transition","useContext","setFrameInnerWidth","switchProps","bubbleInput","switchRef","nativeSwitch","id","handleLayout","children","Provider","render","theme","type","backgroundColor","flex","disableTheme"],"sources":["../../src/createSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SACEA,oBAAA,EACAC,gBAAA,EACAC,KAAA,EACAC,IAAA,EACAC,oBAAA,QACK;AACP,SAASC,SAAA,QAAiB;AAC1B,SAASC,oBAAA,QAA4B;AACrC,YAAYC,KAAA,MAAW;AAEvB,SAASC,mBAAA,QAA2B;AACpC,SAASC,WAAA,IAAeC,kBAAA,EAAoBC,WAAA,QAAmB;AAQ/D,SAASC,eAAA,QAAuB;AAwDxB,SA6EAC,QAAA,EA7EAC,GAAA,EA6EAC,IAAA,QA7EA;AApDD,SAASC,aAGdC,WAAA,EAAuC;EACvC,MAAM;IAAEC,KAAA,GAAQR,kBAAA;IAAoBS,KAAA,GAAQR;EAAY,IAAIM,WAAA;EAK5D,IAAIG,OAAA,CAAQC,GAAA,CAAIC,QAAA,KAAa,eAAe;IAC1C,IACGJ,KAAA,KAAUR,kBAAA,IACTQ,KAAA,CAAMK,YAAA,CAAaC,OAAA,IACnBN,KAAA,CAAMK,YAAA,CAAaC,OAAA,KAAYhB,mBAAA,IAChCW,KAAA,KAAUR,WAAA,IACTQ,KAAA,CAAMI,YAAA,CAAaC,OAAA,IACnBL,KAAA,CAAMI,YAAA,CAAaC,OAAA,KAAYhB,mBAAA,EACjC;MACAiB,OAAA,CAAQC,IAAA,CACN,2IACF;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AAAxD,KAAA,CAAMwD;UAAA,CACT;QAAA,CACF;MAAA,CACF,GAECL,WAAA;IAAA,CACH;EAEJ,GACA;IACEY,YAAA,EAAc;EAChB,CACF;EAEA,OAAOzF,oBAAA,CAAqB2D,eAAA,EAAiB;IAC3C5C,KAAA,EAAOQ;EACT,CAAC;AACH","ignoreList":[]}
|
|
@@ -4,181 +4,189 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var createSwitch_exports = {};
|
|
35
37
|
__export(createSwitch_exports, {
|
|
36
38
|
createSwitch: () => createSwitch
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(createSwitch_exports);
|
|
39
|
-
var import_jsx_runtime = require("react/jsx-runtime")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
var import_core = require("@tamagui/core");
|
|
43
|
+
var import_switch_headless = require("@tamagui/switch-headless");
|
|
44
|
+
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
45
|
+
var React = __toESM(require("react"), 1);
|
|
46
|
+
var import_StyledContext = require("./StyledContext.native.js");
|
|
47
|
+
var import_Switch = require("./Switch.native.js");
|
|
48
|
+
var import_useSwitchNative = require("./useSwitchNative.native.js");
|
|
47
49
|
function createSwitch(createProps) {
|
|
48
50
|
var {
|
|
49
51
|
Frame = import_Switch.SwitchFrame,
|
|
50
52
|
Thumb = import_Switch.SwitchThumb
|
|
51
53
|
} = createProps;
|
|
52
|
-
process.env.NODE_ENV === "development"
|
|
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
|
-
|
|
54
|
+
if (process.env.NODE_ENV === "development") {
|
|
55
|
+
if (Frame !== import_Switch.SwitchFrame && Frame.staticConfig.context && Frame.staticConfig.context !== import_StyledContext.SwitchStyledContext || Thumb !== import_Switch.SwitchThumb && Thumb.staticConfig.context && Thumb.staticConfig.context !== import_StyledContext.SwitchStyledContext) {
|
|
56
|
+
console.warn(`Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
60
|
+
Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
61
|
+
var SwitchThumbComponent = Thumb.styleable(function SwitchThumb2(props, forwardedRef) {
|
|
62
|
+
var {
|
|
63
|
+
size: sizeProp,
|
|
64
|
+
unstyled: unstyledProp,
|
|
65
|
+
activeStyle,
|
|
66
|
+
...thumbProps
|
|
67
|
+
} = props;
|
|
68
|
+
var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
|
|
69
|
+
var {
|
|
70
|
+
unstyled: unstyledContext,
|
|
71
|
+
size: sizeContext,
|
|
72
|
+
active,
|
|
73
|
+
disabled,
|
|
74
|
+
frameWidth = 0
|
|
75
|
+
} = styledContext;
|
|
76
|
+
var _ref;
|
|
77
|
+
var unstyled = process.env.TAMAGUI_HEADLESS === "1" ? true : (_ref = unstyledProp !== null && unstyledProp !== void 0 ? unstyledProp : unstyledContext) !== null && _ref !== void 0 ? _ref : false;
|
|
78
|
+
var _ref1;
|
|
79
|
+
var size = (_ref1 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref1 !== void 0 ? _ref1 : "$true";
|
|
80
|
+
var initialChecked = React.useRef(active).current;
|
|
81
|
+
var initialWidth = (0, import_core.getVariableValue)(props.width || size, "size");
|
|
82
|
+
var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
83
|
+
var distance = frameWidth - thumbWidth;
|
|
84
|
+
var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
85
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Thumb, {
|
|
86
|
+
ref: forwardedRef,
|
|
87
|
+
unstyled,
|
|
88
|
+
...(unstyled === false && {
|
|
89
|
+
size
|
|
90
|
+
}),
|
|
91
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
92
|
+
x,
|
|
93
|
+
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function (e) {
|
|
94
|
+
var next = e.nativeEvent.layout.width;
|
|
95
|
+
setThumbWidth(next);
|
|
96
|
+
}),
|
|
97
|
+
disabled,
|
|
98
|
+
...thumbProps,
|
|
99
|
+
...(active && activeStyle)
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
var SwitchComponent = Frame.styleable(function SwitchFrame(_props, forwardedRef) {
|
|
103
|
+
var {
|
|
104
|
+
native,
|
|
105
|
+
nativeProps,
|
|
106
|
+
checked: checkedProp,
|
|
107
|
+
defaultChecked,
|
|
108
|
+
onCheckedChange,
|
|
109
|
+
activeStyle,
|
|
110
|
+
unstyled: unstyledProp,
|
|
111
|
+
activeTheme: activeThemeProp,
|
|
112
|
+
...props
|
|
113
|
+
} = _props;
|
|
114
|
+
var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
115
|
+
prop: checkedProp,
|
|
116
|
+
defaultProp: defaultChecked || false,
|
|
117
|
+
onChange: onCheckedChange,
|
|
118
|
+
transition: true
|
|
119
|
+
});
|
|
120
|
+
var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
|
|
121
|
+
var [frameWidth, setFrameInnerWidth] = React.useState(0);
|
|
122
|
+
var {
|
|
123
|
+
switchProps,
|
|
124
|
+
bubbleInput,
|
|
125
|
+
switchRef
|
|
126
|
+
} = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
|
|
127
|
+
// @ts-ignore TODO tamagui react 19 type error
|
|
128
|
+
forwardedRef);
|
|
129
|
+
var nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
|
|
130
|
+
id: props.id,
|
|
131
|
+
disabled: props.disabled,
|
|
132
|
+
native,
|
|
133
|
+
nativeProps,
|
|
134
|
+
checked,
|
|
135
|
+
setChecked
|
|
136
|
+
});
|
|
137
|
+
if (nativeSwitch) {
|
|
138
|
+
return nativeSwitch;
|
|
139
|
+
}
|
|
140
|
+
var disabled = props.disabled;
|
|
141
|
+
var handleLayout = function (e) {
|
|
142
|
+
var next = e.nativeEvent.layout.width;
|
|
143
|
+
if (next !== frameWidth) {
|
|
144
|
+
setFrameInnerWidth(next);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var _styledContext_unstyled, _ref;
|
|
148
|
+
var unstyled = (_ref = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : unstyledProp) !== null && _ref !== void 0 ? _ref : false;
|
|
149
|
+
var _styledContext_size, _ref1, _styledContext_size1, _ref2;
|
|
150
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
151
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
152
|
+
size: (_ref1 = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref1 !== void 0 ? _ref1 : "$true",
|
|
79
153
|
unstyled,
|
|
80
|
-
|
|
81
|
-
size
|
|
82
|
-
}),
|
|
83
|
-
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
84
|
-
x,
|
|
85
|
-
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function (e) {
|
|
86
|
-
var next = e.nativeEvent.layout.width;
|
|
87
|
-
setThumbWidth(next);
|
|
88
|
-
}),
|
|
154
|
+
active: checked,
|
|
89
155
|
disabled,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
unstyled: unstyledProp,
|
|
103
|
-
activeTheme: activeThemeProp,
|
|
104
|
-
...props
|
|
105
|
-
} = _props,
|
|
106
|
-
[checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
107
|
-
prop: checkedProp,
|
|
108
|
-
defaultProp: defaultChecked || !1,
|
|
109
|
-
onChange: onCheckedChange,
|
|
110
|
-
transition: !0
|
|
111
|
-
}),
|
|
112
|
-
styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context),
|
|
113
|
-
[frameWidth, setFrameInnerWidth] = React.useState(0),
|
|
114
|
-
{
|
|
115
|
-
switchProps,
|
|
116
|
-
bubbleInput,
|
|
117
|
-
switchRef
|
|
118
|
-
} = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
|
|
119
|
-
// @ts-ignore TODO tamagui react 19 type error
|
|
120
|
-
forwardedRef),
|
|
121
|
-
nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
|
|
122
|
-
id: props.id,
|
|
123
|
-
disabled: props.disabled,
|
|
124
|
-
native,
|
|
125
|
-
nativeProps,
|
|
126
|
-
checked,
|
|
127
|
-
setChecked
|
|
128
|
-
});
|
|
129
|
-
if (nativeSwitch) return nativeSwitch;
|
|
130
|
-
var disabled = props.disabled,
|
|
131
|
-
handleLayout = function (e) {
|
|
132
|
-
var next = e.nativeEvent.layout.width;
|
|
133
|
-
next !== frameWidth && setFrameInnerWidth(next);
|
|
134
|
-
},
|
|
135
|
-
_styledContext_unstyled,
|
|
136
|
-
_ref,
|
|
137
|
-
unstyled = (_ref = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : unstyledProp) !== null && _ref !== void 0 ? _ref : !1,
|
|
138
|
-
_styledContext_size,
|
|
139
|
-
_ref1,
|
|
140
|
-
_styledContext_size1,
|
|
141
|
-
_ref2;
|
|
142
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
143
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
144
|
-
size: (_ref1 = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref1 !== void 0 ? _ref1 : "$true",
|
|
156
|
+
frameWidth,
|
|
157
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
|
|
158
|
+
ref: switchRef,
|
|
159
|
+
render: "button",
|
|
160
|
+
// activeThemeProp should be a theme name string like "active", not a style object
|
|
161
|
+
theme: activeThemeProp !== null && activeThemeProp !== void 0 ? activeThemeProp : null,
|
|
162
|
+
...(import_core.isWeb && {
|
|
163
|
+
type: "button"
|
|
164
|
+
}),
|
|
165
|
+
...(!unstyled && {
|
|
166
|
+
size: (_ref2 = (_styledContext_size1 = styledContext.size) !== null && _styledContext_size1 !== void 0 ? _styledContext_size1 : props.size) !== null && _ref2 !== void 0 ? _ref2 : "$true"
|
|
167
|
+
}),
|
|
145
168
|
unstyled,
|
|
146
|
-
|
|
169
|
+
...props,
|
|
170
|
+
...switchProps,
|
|
147
171
|
disabled,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
render: "button",
|
|
152
|
-
// activeThemeProp should be a theme name string like "active", not a style object
|
|
153
|
-
theme: activeThemeProp ?? null,
|
|
154
|
-
...(import_core.isWeb && {
|
|
155
|
-
type: "button"
|
|
156
|
-
}),
|
|
157
|
-
...(!unstyled && {
|
|
158
|
-
size: (_ref2 = (_styledContext_size1 = styledContext.size) !== null && _styledContext_size1 !== void 0 ? _styledContext_size1 : props.size) !== null && _ref2 !== void 0 ? _ref2 : "$true"
|
|
172
|
+
...(checked && {
|
|
173
|
+
...(!unstyled && !activeStyle && {
|
|
174
|
+
backgroundColor: "$backgroundActive"
|
|
159
175
|
}),
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}),
|
|
168
|
-
...activeStyle
|
|
169
|
-
}),
|
|
170
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
171
|
-
alignSelf: "stretch",
|
|
172
|
-
flex: 1,
|
|
173
|
-
onLayout: handleLayout,
|
|
174
|
-
children: props.children
|
|
175
|
-
})
|
|
176
|
+
...activeStyle
|
|
177
|
+
}),
|
|
178
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
179
|
+
alignSelf: "stretch",
|
|
180
|
+
flex: 1,
|
|
181
|
+
onLayout: handleLayout,
|
|
182
|
+
children: props.children
|
|
176
183
|
})
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
}, {
|
|
180
|
-
disableTheme: !0
|
|
184
|
+
})
|
|
185
|
+
}), bubbleInput]
|
|
181
186
|
});
|
|
187
|
+
}, {
|
|
188
|
+
disableTheme: true
|
|
189
|
+
});
|
|
182
190
|
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
183
191
|
Thumb: SwitchThumbComponent
|
|
184
192
|
});
|