@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
|
@@ -2,172 +2,184 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var createSwitch_exports = {};
|
|
33
35
|
__export(createSwitch_exports, {
|
|
34
36
|
createSwitch: () => createSwitch
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(createSwitch_exports);
|
|
37
|
-
var import_core = require("@tamagui/core")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
var import_core = require("@tamagui/core");
|
|
40
|
+
var import_switch_headless = require("@tamagui/switch-headless");
|
|
41
|
+
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
42
|
+
var React = __toESM(require("react"), 1);
|
|
43
|
+
var import_StyledContext = require("./StyledContext.cjs");
|
|
44
|
+
var import_Switch = require("./Switch.cjs");
|
|
45
|
+
var import_useSwitchNative = require("./useSwitchNative.cjs");
|
|
46
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
47
|
function createSwitch(createProps) {
|
|
46
48
|
const {
|
|
47
49
|
Frame = import_Switch.SwitchFrame,
|
|
48
50
|
Thumb = import_Switch.SwitchThumb
|
|
49
51
|
} = createProps;
|
|
50
|
-
process.env.NODE_ENV === "development"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
if (process.env.NODE_ENV === "development") {
|
|
53
|
+
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) {
|
|
54
|
+
console.warn(`Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
58
|
+
Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
59
|
+
const SwitchThumbComponent = Thumb.styleable(function SwitchThumb2(props, forwardedRef) {
|
|
60
|
+
const {
|
|
61
|
+
size: sizeProp,
|
|
62
|
+
unstyled: unstyledProp,
|
|
63
|
+
activeStyle,
|
|
64
|
+
...thumbProps
|
|
65
|
+
} = props;
|
|
66
|
+
const styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
|
|
67
|
+
const {
|
|
68
|
+
unstyled: unstyledContext,
|
|
69
|
+
size: sizeContext,
|
|
70
|
+
active,
|
|
71
|
+
disabled,
|
|
72
|
+
frameWidth = 0
|
|
73
|
+
} = styledContext;
|
|
74
|
+
const unstyled = process.env.TAMAGUI_HEADLESS === "1" ? true : unstyledProp ?? unstyledContext ?? false;
|
|
75
|
+
const size = sizeProp ?? sizeContext ?? "$true";
|
|
76
|
+
const initialChecked = React.useRef(active).current;
|
|
77
|
+
const initialWidth = (0, import_core.getVariableValue)(props.width || size, "size");
|
|
78
|
+
const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
|
|
79
|
+
const distance = frameWidth - thumbWidth;
|
|
80
|
+
const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
|
|
81
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Thumb, {
|
|
82
|
+
ref: forwardedRef,
|
|
83
|
+
unstyled,
|
|
84
|
+
...(unstyled === false && {
|
|
85
|
+
size
|
|
86
|
+
}),
|
|
87
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
88
|
+
x,
|
|
89
|
+
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, e => {
|
|
90
|
+
const next = e.nativeEvent.layout.width;
|
|
91
|
+
setThumbWidth(next);
|
|
92
|
+
}),
|
|
93
|
+
disabled,
|
|
94
|
+
...thumbProps,
|
|
95
|
+
...(active && activeStyle)
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
const SwitchComponent = Frame.styleable(function SwitchFrame(_props, forwardedRef) {
|
|
99
|
+
const {
|
|
100
|
+
native,
|
|
101
|
+
nativeProps,
|
|
102
|
+
checked: checkedProp,
|
|
103
|
+
defaultChecked,
|
|
104
|
+
onCheckedChange,
|
|
105
|
+
activeStyle,
|
|
106
|
+
unstyled: unstyledProp,
|
|
107
|
+
activeTheme: activeThemeProp,
|
|
108
|
+
...props
|
|
109
|
+
} = _props;
|
|
110
|
+
const [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
111
|
+
prop: checkedProp,
|
|
112
|
+
defaultProp: defaultChecked || false,
|
|
113
|
+
onChange: onCheckedChange,
|
|
114
|
+
transition: true
|
|
115
|
+
});
|
|
116
|
+
const styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
|
|
117
|
+
const [frameWidth, setFrameInnerWidth] = React.useState(0);
|
|
118
|
+
const {
|
|
119
|
+
switchProps,
|
|
120
|
+
bubbleInput,
|
|
121
|
+
switchRef
|
|
122
|
+
} = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
|
|
123
|
+
// @ts-ignore TODO tamagui react 19 type error
|
|
124
|
+
forwardedRef);
|
|
125
|
+
const nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
|
|
126
|
+
id: props.id,
|
|
127
|
+
disabled: props.disabled,
|
|
128
|
+
native,
|
|
129
|
+
nativeProps,
|
|
130
|
+
checked,
|
|
131
|
+
setChecked
|
|
132
|
+
});
|
|
133
|
+
if (nativeSwitch) {
|
|
134
|
+
return nativeSwitch;
|
|
135
|
+
}
|
|
136
|
+
const disabled = props.disabled;
|
|
137
|
+
const handleLayout = e => {
|
|
138
|
+
const next = e.nativeEvent.layout.width;
|
|
139
|
+
if (next !== frameWidth) {
|
|
140
|
+
setFrameInnerWidth(next);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const unstyled = styledContext.unstyled ?? unstyledProp ?? false;
|
|
144
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
145
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
146
|
+
size: styledContext.size ?? props.size ?? "$true",
|
|
75
147
|
unstyled,
|
|
76
|
-
|
|
77
|
-
size
|
|
78
|
-
}),
|
|
79
|
-
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
80
|
-
x,
|
|
81
|
-
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, e => {
|
|
82
|
-
const next = e.nativeEvent.layout.width;
|
|
83
|
-
setThumbWidth(next);
|
|
84
|
-
}),
|
|
148
|
+
active: checked,
|
|
85
149
|
disabled,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
activeStyle,
|
|
98
|
-
unstyled: unstyledProp,
|
|
99
|
-
activeTheme: activeThemeProp,
|
|
100
|
-
...props
|
|
101
|
-
} = _props,
|
|
102
|
-
[checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
103
|
-
prop: checkedProp,
|
|
104
|
-
defaultProp: defaultChecked || !1,
|
|
105
|
-
onChange: onCheckedChange,
|
|
106
|
-
transition: !0
|
|
107
|
-
}),
|
|
108
|
-
styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context),
|
|
109
|
-
[frameWidth, setFrameInnerWidth] = React.useState(0),
|
|
110
|
-
{
|
|
111
|
-
switchProps,
|
|
112
|
-
bubbleInput,
|
|
113
|
-
switchRef
|
|
114
|
-
} = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
|
|
115
|
-
// @ts-ignore TODO tamagui react 19 type error
|
|
116
|
-
forwardedRef),
|
|
117
|
-
nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
|
|
118
|
-
id: props.id,
|
|
119
|
-
disabled: props.disabled,
|
|
120
|
-
native,
|
|
121
|
-
nativeProps,
|
|
122
|
-
checked,
|
|
123
|
-
setChecked
|
|
124
|
-
});
|
|
125
|
-
if (nativeSwitch) return nativeSwitch;
|
|
126
|
-
const disabled = props.disabled,
|
|
127
|
-
handleLayout = e => {
|
|
128
|
-
const next = e.nativeEvent.layout.width;
|
|
129
|
-
next !== frameWidth && setFrameInnerWidth(next);
|
|
130
|
-
},
|
|
131
|
-
unstyled = styledContext.unstyled ?? unstyledProp ?? !1;
|
|
132
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
133
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
|
|
134
|
-
size: styledContext.size ?? props.size ?? "$true",
|
|
150
|
+
frameWidth,
|
|
151
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
|
|
152
|
+
ref: switchRef,
|
|
153
|
+
render: "button",
|
|
154
|
+
theme: activeThemeProp ?? null,
|
|
155
|
+
...(import_core.isWeb && {
|
|
156
|
+
type: "button"
|
|
157
|
+
}),
|
|
158
|
+
...(!unstyled && {
|
|
159
|
+
size: styledContext.size ?? props.size ?? "$true"
|
|
160
|
+
}),
|
|
135
161
|
unstyled,
|
|
136
|
-
|
|
162
|
+
...props,
|
|
163
|
+
...switchProps,
|
|
137
164
|
disabled,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
render: "button",
|
|
142
|
-
theme: activeThemeProp ?? null,
|
|
143
|
-
...(import_core.isWeb && {
|
|
144
|
-
type: "button"
|
|
145
|
-
}),
|
|
146
|
-
...(!unstyled && {
|
|
147
|
-
size: styledContext.size ?? props.size ?? "$true"
|
|
165
|
+
...(checked && {
|
|
166
|
+
...(!unstyled && !activeStyle && {
|
|
167
|
+
backgroundColor: "$backgroundActive"
|
|
148
168
|
}),
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}),
|
|
157
|
-
...activeStyle
|
|
158
|
-
}),
|
|
159
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
160
|
-
alignSelf: "stretch",
|
|
161
|
-
flex: 1,
|
|
162
|
-
onLayout: handleLayout,
|
|
163
|
-
children: props.children
|
|
164
|
-
})
|
|
169
|
+
...activeStyle
|
|
170
|
+
}),
|
|
171
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
172
|
+
alignSelf: "stretch",
|
|
173
|
+
flex: 1,
|
|
174
|
+
onLayout: handleLayout,
|
|
175
|
+
children: props.children
|
|
165
176
|
})
|
|
166
|
-
})
|
|
167
|
-
})
|
|
168
|
-
}, {
|
|
169
|
-
disableTheme: !0
|
|
177
|
+
})
|
|
178
|
+
}), bubbleInput]
|
|
170
179
|
});
|
|
180
|
+
}, {
|
|
181
|
+
disableTheme: true
|
|
182
|
+
});
|
|
171
183
|
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
172
184
|
Thumb: SwitchThumbComponent
|
|
173
185
|
});
|