@tamagui/switch 1.114.3 → 1.115.0
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.js → StyledContext.cjs} +16 -11
- package/dist/cjs/Switch.cjs +95 -0
- package/dist/cjs/createSwitch.cjs +173 -0
- package/dist/cjs/index.cjs +35 -0
- package/package.json +15 -14
- package/dist/cjs/Switch.js +0 -84
- package/dist/cjs/createSwitch.js +0 -145
- package/dist/cjs/index.js +0 -28
- /package/dist/cjs/{StyledContext.js.map → StyledContext.cjs.map} +0 -0
- /package/dist/cjs/{Switch.js.map → Switch.cjs.map} +0 -0
- /package/dist/cjs/{createSwitch.js.map → createSwitch.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
|
@@ -3,15 +3,21 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
15
21
|
var StyledContext_exports = {};
|
|
16
22
|
__export(StyledContext_exports, {
|
|
17
23
|
SwitchStyledContext: () => SwitchStyledContext
|
|
@@ -21,5 +27,4 @@ var import_core = require("@tamagui/core");
|
|
|
21
27
|
const SwitchStyledContext = (0, import_core.createStyledContext)({
|
|
22
28
|
size: void 0,
|
|
23
29
|
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
24
|
-
});
|
|
25
|
-
//# sourceMappingURL=StyledContext.js.map
|
|
30
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var Switch_exports = {};
|
|
22
|
+
__export(Switch_exports, {
|
|
23
|
+
SwitchFrame: () => SwitchFrame,
|
|
24
|
+
SwitchThumb: () => SwitchThumb
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(Switch_exports);
|
|
27
|
+
var import_core = require("@tamagui/core"),
|
|
28
|
+
import_get_token = require("@tamagui/get-token"),
|
|
29
|
+
import_stacks = require("@tamagui/stacks");
|
|
30
|
+
const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
31
|
+
name: "SwitchThumb",
|
|
32
|
+
variants: {
|
|
33
|
+
unstyled: {
|
|
34
|
+
false: {
|
|
35
|
+
size: "$true",
|
|
36
|
+
backgroundColor: "$background",
|
|
37
|
+
borderRadius: 1e3
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
checked: {
|
|
41
|
+
true: {}
|
|
42
|
+
},
|
|
43
|
+
size: {
|
|
44
|
+
"...size": val => {
|
|
45
|
+
const size = getSwitchHeight(val);
|
|
46
|
+
return {
|
|
47
|
+
height: size,
|
|
48
|
+
width: size
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
defaultVariants: {
|
|
54
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
getSwitchHeight = val => Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.65),
|
|
58
|
+
getSwitchWidth = val => getSwitchHeight(val) * 2,
|
|
59
|
+
SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
60
|
+
name: "Switch",
|
|
61
|
+
tag: "button",
|
|
62
|
+
tabIndex: 0,
|
|
63
|
+
variants: {
|
|
64
|
+
unstyled: {
|
|
65
|
+
false: {
|
|
66
|
+
borderRadius: 1e3,
|
|
67
|
+
backgroundColor: "$background",
|
|
68
|
+
borderWidth: 2,
|
|
69
|
+
borderColor: "$background",
|
|
70
|
+
focusVisibleStyle: {
|
|
71
|
+
outlineColor: "$outlineColor",
|
|
72
|
+
outlineStyle: "solid",
|
|
73
|
+
outlineWidth: 2
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
checked: {
|
|
78
|
+
true: {}
|
|
79
|
+
},
|
|
80
|
+
size: {
|
|
81
|
+
"...size": val => {
|
|
82
|
+
const height = getSwitchHeight(val) + 4,
|
|
83
|
+
width = getSwitchWidth(val) + 4;
|
|
84
|
+
return {
|
|
85
|
+
height,
|
|
86
|
+
minHeight: height,
|
|
87
|
+
width
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
defaultVariants: {
|
|
93
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
94
|
+
}
|
|
95
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var createSwitch_exports = {};
|
|
33
|
+
__export(createSwitch_exports, {
|
|
34
|
+
SwitchContext: () => SwitchContext,
|
|
35
|
+
createSwitch: () => createSwitch
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(createSwitch_exports);
|
|
38
|
+
var import_core = require("@tamagui/core"),
|
|
39
|
+
import_focusable = require("@tamagui/focusable"),
|
|
40
|
+
import_switch_headless = require("@tamagui/switch-headless"),
|
|
41
|
+
import_use_controllable_state = require("@tamagui/use-controllable-state"),
|
|
42
|
+
React = __toESM(require("react")),
|
|
43
|
+
import_react_native = require("react-native-web"),
|
|
44
|
+
import_StyledContext = require("./StyledContext.cjs"),
|
|
45
|
+
import_Switch = require("./Switch.cjs"),
|
|
46
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
+
const SwitchContext = React.createContext({
|
|
48
|
+
checked: !1,
|
|
49
|
+
disabled: !1,
|
|
50
|
+
frameWidth: 0
|
|
51
|
+
});
|
|
52
|
+
function createSwitch(createProps) {
|
|
53
|
+
const {
|
|
54
|
+
disableActiveTheme,
|
|
55
|
+
Frame = import_Switch.SwitchFrame,
|
|
56
|
+
Thumb = import_Switch.SwitchThumb
|
|
57
|
+
} = createProps;
|
|
58
|
+
process.env.NODE_ENV === "development" && (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) && console.warn("Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden."), Frame.staticConfig.context = import_StyledContext.SwitchStyledContext, Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
59
|
+
const SwitchThumbComponent = Thumb.styleable(function (props, forwardedRef) {
|
|
60
|
+
const {
|
|
61
|
+
size: sizeProp,
|
|
62
|
+
unstyled: unstyledProp,
|
|
63
|
+
nativeID,
|
|
64
|
+
...thumbProps
|
|
65
|
+
} = props,
|
|
66
|
+
context = React.useContext(SwitchContext),
|
|
67
|
+
{
|
|
68
|
+
checked,
|
|
69
|
+
disabled,
|
|
70
|
+
frameWidth
|
|
71
|
+
} = context,
|
|
72
|
+
styledContext = import_StyledContext.SwitchStyledContext.useStyledContext(),
|
|
73
|
+
{
|
|
74
|
+
unstyled: unstyledContext,
|
|
75
|
+
size: sizeContext
|
|
76
|
+
} = styledContext,
|
|
77
|
+
unstyled = process.env.TAMAGUI_HEADLESS === "1" ? !0 : unstyledProp ?? unstyledContext ?? !1,
|
|
78
|
+
size = sizeProp ?? sizeContext ?? "$true",
|
|
79
|
+
initialChecked = React.useRef(checked).current,
|
|
80
|
+
[thumbWidth, setThumbWidth] = React.useState(0),
|
|
81
|
+
distance = frameWidth - thumbWidth,
|
|
82
|
+
x = initialChecked ? checked ? 0 : -distance : checked ? distance : 0;
|
|
83
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Thumb, {
|
|
84
|
+
ref: forwardedRef,
|
|
85
|
+
unstyled,
|
|
86
|
+
...(unstyled === !1 && {
|
|
87
|
+
size,
|
|
88
|
+
...(!disableActiveTheme && {
|
|
89
|
+
theme: checked ? "active" : null
|
|
90
|
+
})
|
|
91
|
+
}),
|
|
92
|
+
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
93
|
+
x,
|
|
94
|
+
onLayout: (0, import_core.composeEventHandlers)(props.onLayout, e => setThumbWidth(e.nativeEvent.layout.width)),
|
|
95
|
+
checked,
|
|
96
|
+
disabled,
|
|
97
|
+
...thumbProps
|
|
98
|
+
});
|
|
99
|
+
}),
|
|
100
|
+
SwitchComponent = Frame.styleable(function (_props, forwardedRef) {
|
|
101
|
+
const {
|
|
102
|
+
native,
|
|
103
|
+
nativeProps,
|
|
104
|
+
checked: checkedProp,
|
|
105
|
+
defaultChecked,
|
|
106
|
+
onCheckedChange,
|
|
107
|
+
...props
|
|
108
|
+
} = _props,
|
|
109
|
+
[checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
110
|
+
prop: checkedProp,
|
|
111
|
+
defaultProp: defaultChecked || !1,
|
|
112
|
+
onChange: onCheckedChange,
|
|
113
|
+
transition: !0
|
|
114
|
+
}),
|
|
115
|
+
styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context),
|
|
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
|
+
{
|
|
124
|
+
switchProps,
|
|
125
|
+
bubbleInput,
|
|
126
|
+
switchRef
|
|
127
|
+
} = (0, import_switch_headless.useSwitch)(
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
Object.assign({
|
|
130
|
+
size: styledContext.size ?? props.size ?? "$true",
|
|
131
|
+
unstyled: styledContext.unstyled ?? props.unstyled ?? !1
|
|
132
|
+
}, propsActive), [checked, setChecked], forwardedRef),
|
|
133
|
+
renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
134
|
+
return renderNative === "android" || renderNative === "ios" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native.Switch, {
|
|
135
|
+
value: checked,
|
|
136
|
+
onValueChange: setChecked,
|
|
137
|
+
...nativeProps
|
|
138
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime.jsxs)(SwitchContext.Provider, {
|
|
139
|
+
value: {
|
|
140
|
+
checked,
|
|
141
|
+
disabled: switchProps.disabled,
|
|
142
|
+
frameWidth
|
|
143
|
+
},
|
|
144
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
|
|
145
|
+
ref: switchRef,
|
|
146
|
+
tag: "button",
|
|
147
|
+
...(import_core.isWeb && {
|
|
148
|
+
type: "button"
|
|
149
|
+
}),
|
|
150
|
+
...switchProps,
|
|
151
|
+
...(!disableActiveTheme && {
|
|
152
|
+
theme: checked ? "active" : null,
|
|
153
|
+
themeShallow: !0
|
|
154
|
+
}),
|
|
155
|
+
checked,
|
|
156
|
+
disabled: switchProps.disabled,
|
|
157
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Stack, {
|
|
158
|
+
alignSelf: "stretch",
|
|
159
|
+
flex: 1,
|
|
160
|
+
onLayout: e => {
|
|
161
|
+
setFrameWidth(e.nativeEvent.layout.width);
|
|
162
|
+
},
|
|
163
|
+
children: switchProps.children
|
|
164
|
+
})
|
|
165
|
+
}), bubbleInput]
|
|
166
|
+
});
|
|
167
|
+
}, {
|
|
168
|
+
disableTheme: !0
|
|
169
|
+
});
|
|
170
|
+
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
171
|
+
Thumb: SwitchThumbComponent
|
|
172
|
+
});
|
|
173
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
},
|
|
18
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
20
|
+
value: !0
|
|
21
|
+
}), mod);
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
Switch: () => Switch
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
var import_createSwitch = require("./createSwitch.cjs"),
|
|
28
|
+
import_Switch = require("./Switch.cjs");
|
|
29
|
+
__reExport(src_exports, require("./createSwitch.cjs"), module.exports);
|
|
30
|
+
__reExport(src_exports, require("./StyledContext.cjs"), module.exports);
|
|
31
|
+
__reExport(src_exports, require("./Switch.cjs"), module.exports);
|
|
32
|
+
const Switch = (0, import_createSwitch.createSwitch)({
|
|
33
|
+
Frame: import_Switch.SwitchFrame,
|
|
34
|
+
Thumb: import_Switch.SwitchThumb
|
|
35
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/switch",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.0",
|
|
4
4
|
"removeSideEffects": true,
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css"
|
|
@@ -30,27 +30,28 @@
|
|
|
30
30
|
"react-native": "./dist/cjs/index.native.js",
|
|
31
31
|
"types": "./types/index.d.ts",
|
|
32
32
|
"import": "./dist/esm/index.mjs",
|
|
33
|
-
"require": "./dist/cjs/index.
|
|
33
|
+
"require": "./dist/cjs/index.cjs",
|
|
34
|
+
"default": "./dist/cjs/index.native.js"
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@tamagui/compose-refs": "1.
|
|
38
|
-
"@tamagui/constants": "1.
|
|
39
|
-
"@tamagui/core": "1.
|
|
40
|
-
"@tamagui/focusable": "1.
|
|
41
|
-
"@tamagui/get-token": "1.
|
|
42
|
-
"@tamagui/helpers": "1.
|
|
43
|
-
"@tamagui/label": "1.
|
|
44
|
-
"@tamagui/stacks": "1.
|
|
45
|
-
"@tamagui/switch-headless": "1.
|
|
46
|
-
"@tamagui/use-controllable-state": "1.
|
|
47
|
-
"@tamagui/use-previous": "1.
|
|
38
|
+
"@tamagui/compose-refs": "1.115.0",
|
|
39
|
+
"@tamagui/constants": "1.115.0",
|
|
40
|
+
"@tamagui/core": "1.115.0",
|
|
41
|
+
"@tamagui/focusable": "1.115.0",
|
|
42
|
+
"@tamagui/get-token": "1.115.0",
|
|
43
|
+
"@tamagui/helpers": "1.115.0",
|
|
44
|
+
"@tamagui/label": "1.115.0",
|
|
45
|
+
"@tamagui/stacks": "1.115.0",
|
|
46
|
+
"@tamagui/switch-headless": "1.115.0",
|
|
47
|
+
"@tamagui/use-controllable-state": "1.115.0",
|
|
48
|
+
"@tamagui/use-previous": "1.115.0"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"react": "*"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@tamagui/build": "1.
|
|
54
|
+
"@tamagui/build": "1.115.0",
|
|
54
55
|
"react": "^18.2.0 || ^19.0.0"
|
|
55
56
|
},
|
|
56
57
|
"publishConfig": {
|
package/dist/cjs/Switch.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var Switch_exports = {};
|
|
16
|
-
__export(Switch_exports, {
|
|
17
|
-
SwitchFrame: () => SwitchFrame,
|
|
18
|
-
SwitchThumb: () => SwitchThumb
|
|
19
|
-
});
|
|
20
|
-
module.exports = __toCommonJS(Switch_exports);
|
|
21
|
-
var import_core = require("@tamagui/core"), import_get_token = require("@tamagui/get-token"), import_stacks = require("@tamagui/stacks");
|
|
22
|
-
const SwitchThumb = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
23
|
-
name: "SwitchThumb",
|
|
24
|
-
variants: {
|
|
25
|
-
unstyled: {
|
|
26
|
-
false: {
|
|
27
|
-
size: "$true",
|
|
28
|
-
backgroundColor: "$background",
|
|
29
|
-
borderRadius: 1e3
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
checked: {
|
|
33
|
-
true: {}
|
|
34
|
-
},
|
|
35
|
-
size: {
|
|
36
|
-
"...size": (val) => {
|
|
37
|
-
const size = getSwitchHeight(val);
|
|
38
|
-
return {
|
|
39
|
-
height: size,
|
|
40
|
-
width: size
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
defaultVariants: {
|
|
46
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
47
|
-
}
|
|
48
|
-
}), getSwitchHeight = (val) => Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.65), getSwitchWidth = (val) => getSwitchHeight(val) * 2, SwitchFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
49
|
-
name: "Switch",
|
|
50
|
-
tag: "button",
|
|
51
|
-
tabIndex: 0,
|
|
52
|
-
variants: {
|
|
53
|
-
unstyled: {
|
|
54
|
-
false: {
|
|
55
|
-
borderRadius: 1e3,
|
|
56
|
-
backgroundColor: "$background",
|
|
57
|
-
borderWidth: 2,
|
|
58
|
-
borderColor: "$background",
|
|
59
|
-
focusVisibleStyle: {
|
|
60
|
-
outlineColor: "$outlineColor",
|
|
61
|
-
outlineStyle: "solid",
|
|
62
|
-
outlineWidth: 2
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
checked: {
|
|
67
|
-
true: {}
|
|
68
|
-
},
|
|
69
|
-
size: {
|
|
70
|
-
"...size": (val) => {
|
|
71
|
-
const height = getSwitchHeight(val) + 4, width = getSwitchWidth(val) + 4;
|
|
72
|
-
return {
|
|
73
|
-
height,
|
|
74
|
-
minHeight: height,
|
|
75
|
-
width
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
defaultVariants: {
|
|
81
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
//# sourceMappingURL=Switch.js.map
|
package/dist/cjs/createSwitch.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var createSwitch_exports = {};
|
|
24
|
-
__export(createSwitch_exports, {
|
|
25
|
-
SwitchContext: () => SwitchContext,
|
|
26
|
-
createSwitch: () => createSwitch
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(createSwitch_exports);
|
|
29
|
-
var import_core = require("@tamagui/core"), import_focusable = require("@tamagui/focusable"), import_switch_headless = require("@tamagui/switch-headless"), import_use_controllable_state = require("@tamagui/use-controllable-state"), React = __toESM(require("react")), import_react_native = require("react-native-web"), import_StyledContext = require("./StyledContext"), import_Switch = require("./Switch"), import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
-
const SwitchContext = React.createContext({
|
|
31
|
-
checked: !1,
|
|
32
|
-
disabled: !1,
|
|
33
|
-
frameWidth: 0
|
|
34
|
-
});
|
|
35
|
-
function createSwitch(createProps) {
|
|
36
|
-
const {
|
|
37
|
-
disableActiveTheme,
|
|
38
|
-
Frame = import_Switch.SwitchFrame,
|
|
39
|
-
Thumb = import_Switch.SwitchThumb
|
|
40
|
-
} = createProps;
|
|
41
|
-
process.env.NODE_ENV === "development" && (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) && console.warn(
|
|
42
|
-
"Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden."
|
|
43
|
-
), Frame.staticConfig.context = import_StyledContext.SwitchStyledContext, Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
|
|
44
|
-
const SwitchThumbComponent = Thumb.styleable(
|
|
45
|
-
function(props, forwardedRef) {
|
|
46
|
-
const { size: sizeProp, unstyled: unstyledProp, nativeID, ...thumbProps } = props, context = React.useContext(SwitchContext), { checked, disabled, frameWidth } = context, styledContext = import_StyledContext.SwitchStyledContext.useStyledContext(), { unstyled: unstyledContext, size: sizeContext } = styledContext, unstyled = process.env.TAMAGUI_HEADLESS === "1" ? !0 : unstyledProp ?? unstyledContext ?? !1, size = sizeProp ?? sizeContext ?? "$true", initialChecked = React.useRef(checked).current, [thumbWidth, setThumbWidth] = React.useState(0), distance = frameWidth - thumbWidth, x = initialChecked ? checked ? 0 : -distance : checked ? distance : 0;
|
|
47
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
48
|
-
Thumb,
|
|
49
|
-
{
|
|
50
|
-
ref: forwardedRef,
|
|
51
|
-
unstyled,
|
|
52
|
-
...unstyled === !1 && {
|
|
53
|
-
size,
|
|
54
|
-
...!disableActiveTheme && {
|
|
55
|
-
theme: checked ? "active" : null
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
alignSelf: initialChecked ? "flex-end" : "flex-start",
|
|
59
|
-
x,
|
|
60
|
-
onLayout: (0, import_core.composeEventHandlers)(
|
|
61
|
-
props.onLayout,
|
|
62
|
-
(e) => setThumbWidth(e.nativeEvent.layout.width)
|
|
63
|
-
),
|
|
64
|
-
checked,
|
|
65
|
-
disabled,
|
|
66
|
-
...thumbProps
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
), SwitchComponent = Frame.styleable(
|
|
71
|
-
function(_props, forwardedRef) {
|
|
72
|
-
const {
|
|
73
|
-
native,
|
|
74
|
-
nativeProps,
|
|
75
|
-
checked: checkedProp,
|
|
76
|
-
defaultChecked,
|
|
77
|
-
onCheckedChange,
|
|
78
|
-
...props
|
|
79
|
-
} = _props, [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
80
|
-
prop: checkedProp,
|
|
81
|
-
defaultProp: defaultChecked || !1,
|
|
82
|
-
onChange: onCheckedChange,
|
|
83
|
-
transition: !0
|
|
84
|
-
}), styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context), [frameWidth, setFrameWidth] = React.useState(0), propsActive = (0, import_core.useProps)(props, {
|
|
85
|
-
noNormalize: !0,
|
|
86
|
-
noExpand: !0,
|
|
87
|
-
resolveValues: "none",
|
|
88
|
-
forComponent: Frame
|
|
89
|
-
}), { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
Object.assign(
|
|
92
|
-
{
|
|
93
|
-
size: styledContext.size ?? props.size ?? "$true",
|
|
94
|
-
unstyled: styledContext.unstyled ?? props.unstyled ?? !1
|
|
95
|
-
},
|
|
96
|
-
propsActive
|
|
97
|
-
),
|
|
98
|
-
[checked, setChecked],
|
|
99
|
-
forwardedRef
|
|
100
|
-
), renderNative = (0, import_core.shouldRenderNativePlatform)(native);
|
|
101
|
-
return renderNative === "android" || renderNative === "ios" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Switch, { value: checked, onValueChange: setChecked, ...nativeProps }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
102
|
-
SwitchContext.Provider,
|
|
103
|
-
{
|
|
104
|
-
value: { checked, disabled: switchProps.disabled, frameWidth },
|
|
105
|
-
children: [
|
|
106
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
107
|
-
Frame,
|
|
108
|
-
{
|
|
109
|
-
ref: switchRef,
|
|
110
|
-
tag: "button",
|
|
111
|
-
...import_core.isWeb && { type: "button" },
|
|
112
|
-
...switchProps,
|
|
113
|
-
...!disableActiveTheme && {
|
|
114
|
-
theme: checked ? "active" : null,
|
|
115
|
-
themeShallow: !0
|
|
116
|
-
},
|
|
117
|
-
checked,
|
|
118
|
-
disabled: switchProps.disabled,
|
|
119
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
120
|
-
import_core.Stack,
|
|
121
|
-
{
|
|
122
|
-
alignSelf: "stretch",
|
|
123
|
-
flex: 1,
|
|
124
|
-
onLayout: (e) => {
|
|
125
|
-
setFrameWidth(e.nativeEvent.layout.width);
|
|
126
|
-
},
|
|
127
|
-
children: switchProps.children
|
|
128
|
-
}
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
),
|
|
132
|
-
bubbleInput
|
|
133
|
-
]
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
disableTheme: !0
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
return (0, import_core.withStaticProperties)(SwitchComponent, {
|
|
142
|
-
Thumb: SwitchThumbComponent
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=createSwitch.js.map
|
package/dist/cjs/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var src_exports = {};
|
|
16
|
-
__export(src_exports, {
|
|
17
|
-
Switch: () => Switch
|
|
18
|
-
});
|
|
19
|
-
module.exports = __toCommonJS(src_exports);
|
|
20
|
-
var import_createSwitch = require("./createSwitch"), import_Switch = require("./Switch");
|
|
21
|
-
__reExport(src_exports, require("./createSwitch"), module.exports);
|
|
22
|
-
__reExport(src_exports, require("./StyledContext"), module.exports);
|
|
23
|
-
__reExport(src_exports, require("./Switch"), module.exports);
|
|
24
|
-
const Switch = (0, import_createSwitch.createSwitch)({
|
|
25
|
-
Frame: import_Switch.SwitchFrame,
|
|
26
|
-
Thumb: import_Switch.SwitchThumb
|
|
27
|
-
});
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|