@tamagui/switch 1.116.0 → 1.116.2

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.
@@ -0,0 +1,25 @@
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 StyledContext_exports = {};
16
+ __export(StyledContext_exports, {
17
+ SwitchStyledContext: () => SwitchStyledContext
18
+ });
19
+ module.exports = __toCommonJS(StyledContext_exports);
20
+ var import_core = require("@tamagui/core");
21
+ const SwitchStyledContext = (0, import_core.createStyledContext)({
22
+ size: void 0,
23
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
24
+ });
25
+ //# sourceMappingURL=StyledContext.js.map
@@ -0,0 +1,84 @@
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
@@ -0,0 +1,145 @@
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
@@ -0,0 +1,28 @@
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/switch",
3
- "version": "1.116.0",
3
+ "version": "1.116.2",
4
4
  "removeSideEffects": true,
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -35,23 +35,23 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@tamagui/compose-refs": "1.116.0",
39
- "@tamagui/constants": "1.116.0",
40
- "@tamagui/core": "1.116.0",
41
- "@tamagui/focusable": "1.116.0",
42
- "@tamagui/get-token": "1.116.0",
43
- "@tamagui/helpers": "1.116.0",
44
- "@tamagui/label": "1.116.0",
45
- "@tamagui/stacks": "1.116.0",
46
- "@tamagui/switch-headless": "1.116.0",
47
- "@tamagui/use-controllable-state": "1.116.0",
48
- "@tamagui/use-previous": "1.116.0"
38
+ "@tamagui/compose-refs": "1.116.2",
39
+ "@tamagui/constants": "1.116.2",
40
+ "@tamagui/core": "1.116.2",
41
+ "@tamagui/focusable": "1.116.2",
42
+ "@tamagui/get-token": "1.116.2",
43
+ "@tamagui/helpers": "1.116.2",
44
+ "@tamagui/label": "1.116.2",
45
+ "@tamagui/stacks": "1.116.2",
46
+ "@tamagui/switch-headless": "1.116.2",
47
+ "@tamagui/use-controllable-state": "1.116.2",
48
+ "@tamagui/use-previous": "1.116.2"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "react": "*"
52
52
  },
53
53
  "devDependencies": {
54
- "@tamagui/build": "1.116.0",
54
+ "@tamagui/build": "1.116.2",
55
55
  "react": "^18.2.0 || ^19.0.0"
56
56
  },
57
57
  "publishConfig": {
File without changes
File without changes