@tamagui/switch 3.0.0-beta.1216.1 → 3.0.0-beta.1310.1

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.
@@ -1,4 +1,4 @@
1
- import { Theme, View, composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, withStaticProperties } from "@tamagui/core";
1
+ import { View, composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, 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";
@@ -22,7 +22,7 @@ function createSwitch(createProps) {
22
22
  Frame.staticConfig.context = SwitchStyledContext;
23
23
  Thumb.staticConfig.context = SwitchStyledContext;
24
24
  const SwitchThumbComponent = createStyledHOC(Thumb, function SwitchThumb2(props, forwardedRef) {
25
- const { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
25
+ const { size: sizeProp, activeStyle, ...thumbProps } = props;
26
26
  const styledContext = SwitchStyledContext.useStyledContext();
27
27
  const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
28
28
  const size = sizeProp ?? sizeContext ?? true;
@@ -31,7 +31,7 @@ function createSwitch(createProps) {
31
31
  const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
32
32
  const distance = frameWidth - thumbWidth;
33
33
  const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
34
- const thumb = /* @__PURE__ */ jsx(Thumb, {
34
+ return /* @__PURE__ */ jsx(Thumb, {
35
35
  ref: forwardedRef,
36
36
  size,
37
37
  alignSelf: initialChecked ? "flex-end" : "flex-start",
@@ -43,14 +43,9 @@ function createSwitch(createProps) {
43
43
  ...thumbProps,
44
44
  ...active && activeStyle
45
45
  });
46
- const themeName = theme ?? createProps.componentThemes?.thumb;
47
- return themeName ? /* @__PURE__ */ jsx(Theme, {
48
- name: themeName,
49
- children: thumb
50
- }) : thumb;
51
46
  });
52
47
  const SwitchComponent = createStyledHOC(Frame, function Switch2(_props, forwardedRef) {
53
- const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
48
+ const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
54
49
  const [checked, setChecked] = useControllableState({
55
50
  prop: checkedProp,
56
51
  defaultProp: defaultChecked || false,
@@ -79,34 +74,30 @@ function createSwitch(createProps) {
79
74
  setFrameInnerWidth(next);
80
75
  }
81
76
  };
82
- const frame = /* @__PURE__ */ jsx(Frame, {
83
- ref: switchRef,
84
- render: "button",
85
- ...isWeb && { type: "button" },
86
- size,
87
- ...props,
88
- ...switchProps,
89
- disabled,
90
- ...checked && activeStyle,
91
- children: /* @__PURE__ */ jsx(View, {
92
- alignSelf: "stretch",
93
- flex: 1,
94
- onLayout: handleLayout,
95
- children: props.children
96
- })
97
- });
98
- const frameTheme = (checked ? activeTheme : void 0) ?? theme ?? createProps.componentThemes?.frame;
99
77
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SwitchStyledContext.Provider, {
100
78
  size,
101
79
  active: checked,
102
80
  disabled,
103
81
  frameWidth,
104
- children: frameTheme ? /* @__PURE__ */ jsx(Theme, {
105
- name: frameTheme,
106
- children: frame
107
- }) : frame
82
+ children: /* @__PURE__ */ jsx(Frame, {
83
+ ref: switchRef,
84
+ render: "button",
85
+ theme: checked ? activeTheme ?? createProps.activeTheme ?? null : null,
86
+ ...isWeb && { type: "button" },
87
+ size,
88
+ ...props,
89
+ ...switchProps,
90
+ disabled,
91
+ ...checked && activeStyle,
92
+ children: /* @__PURE__ */ jsx(View, {
93
+ alignSelf: "stretch",
94
+ flex: 1,
95
+ onLayout: handleLayout,
96
+ children: props.children
97
+ })
98
+ })
108
99
  }), bubbleInput] });
109
- }, { disableTheme: true });
100
+ });
110
101
  return withStaticProperties(SwitchComponent, {
111
102
  Frame,
112
103
  Thumb: SwitchThumbComponent
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.js","names":[],"sources":["jsx/Switch.js"],"sourcesContent":["import {\n composeEventHandlers,\n createStyledHOC,\n getVariableValue,\n isWeb,\n styled,\n Theme,\n View,\n withStaticProperties\n} from \"@tamagui/core\";\nimport { useSwitch } from \"@tamagui/switch-headless\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport * as React from \"react\";\nimport { SwitchStyledContext } from \"./StyledContext\";\nimport { useSwitchNative } from \"./useSwitchNative\";\nimport { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nconst SwitchThumbFrame = styled(View, {\n displayName: \"SwitchThumb\",\n context: SwitchStyledContext\n});\nconst SwitchFrame = styled(View, {\n displayName: \"Switch\",\n context: SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n const Frame = createProps.Frame ?? SwitchFrame;\n const Thumb = createProps.Thumb ?? SwitchThumbFrame;\n Frame.staticConfig.context = SwitchStyledContext;\n Thumb.staticConfig.context = SwitchStyledContext;\n const SwitchThumbComponent = createStyledHOC(\n Thumb,\n function SwitchThumb2(props, forwardedRef) {\n const { size: sizeProp, activeStyle, theme, ...thumbProps } = props;\n const styledContext = SwitchStyledContext.useStyledContext();\n const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n const size = sizeProp ?? sizeContext ?? true;\n const initialChecked = React.useRef(active).current;\n const initialWidth = getVariableValue(props.width, \"size\");\n const [thumbWidth, setThumbWidth] = React.useState(\n typeof initialWidth === \"number\" ? initialWidth : 0\n );\n const distance = frameWidth - thumbWidth;\n const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n const thumb = /* @__PURE__ */ jsx(\n Thumb,\n {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: composeEventHandlers(props.onLayout, (event) => {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n }\n );\n const themeName = theme ?? createProps.componentThemes?.thumb;\n return themeName ? /* @__PURE__ */ jsx(Theme, { name: themeName, children: thumb }) : thumb;\n }\n );\n const SwitchComponent = createStyledHOC(\n Frame,\n function Switch2(_props, forwardedRef) {\n const {\n native,\n nativeProps,\n checked: checkedProp,\n defaultChecked,\n onCheckedChange,\n activeStyle,\n activeTheme,\n theme,\n ...props\n } = _props;\n const [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n const styledContext = React.useContext(SwitchStyledContext.context);\n const [frameWidth, setFrameInnerWidth] = React.useState(0);\n const { switchProps, bubbleInput, switchRef } = useSwitch(\n props,\n [checked, setChecked],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n const nativeSwitch = useSwitchNative({\n id: props.id,\n disabled: props.disabled,\n native,\n nativeProps,\n checked,\n setChecked\n });\n if (nativeSwitch) {\n return nativeSwitch;\n }\n const disabled = props.disabled;\n const size = styledContext.size ?? props.size ?? true;\n const handleLayout = (event) => {\n const next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n const frame = /* @__PURE__ */ jsx(\n Frame,\n {\n ref: switchRef,\n render: \"button\",\n ...isWeb && { type: \"button\" },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ jsx(View, { alignSelf: \"stretch\", flex: 1, onLayout: handleLayout, children: props.children })\n }\n );\n const frameTheme = (checked ? activeTheme : void 0) ?? theme ?? createProps.componentThemes?.frame;\n return /* @__PURE__ */ jsxs(Fragment, { children: [\n /* @__PURE__ */ jsx(\n SwitchStyledContext.Provider,\n {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: frameTheme ? /* @__PURE__ */ jsx(Theme, { name: frameTheme, children: frame }) : frame\n }\n ),\n bubbleInput\n ] });\n },\n {\n disableTheme: true\n }\n );\n return withStaticProperties(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nconst Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nconst SwitchThumb = Switch.Thumb;\nexport {\n Switch,\n SwitchFrame,\n SwitchThumb,\n SwitchThumbFrame,\n createSwitch\n};\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;;;;;;;AAgBA,MAAM,mBAAmB,OAAO,MAAM;CACpC,aAAa;CACb,SAAS;AACX,CAAC;AACD,MAAM,cAAc,OAAO,MAAM;CAC/B,aAAa;CACb,SAAS;CACT,QAAQ;CACR,UAAU;AACZ,CAAC;AACD,SAAS,aAAa,aAAa;CACjC,MAAM,QAAQ,YAAY,SAAS;CACnC,MAAM,QAAQ,YAAY,SAAS;CACnC,MAAM,aAAa,UAAU;CAC7B,MAAM,aAAa,UAAU;CAC7B,MAAM,uBAAuB,gBAC3B,OACA,SAAS,aAAa,OAAO,cAAc;EACzC,MAAM,EAAE,MAAM,UAAU,aAAa,OAAO,GAAG,eAAe;EAC9D,MAAM,gBAAgB,oBAAoB,iBAAiB;EAC3D,MAAM,EAAE,MAAM,aAAa,QAAQ,UAAU,aAAa,MAAM;EAChE,MAAM,OAAO,YAAY,eAAe;EACxC,MAAM,iBAAiB,MAAM,OAAO,MAAM,CAAC,CAAC;EAC5C,MAAM,eAAe,iBAAiB,MAAM,OAAO,MAAM;EACzD,MAAM,CAAC,YAAY,iBAAiB,MAAM,SACxC,OAAO,iBAAiB,WAAW,eAAe,CACpD;EACA,MAAM,WAAW,aAAa;EAC9B,MAAM,IAAI,iBAAiB,SAAS,IAAI,CAAC,WAAW,SAAS,WAAW;EACxE,MAAM,QAAwB,oBAC5B,OACA;GACE,KAAK;GACL;GACA,WAAW,iBAAiB,aAAa;GACzC;GACA,UAAU,qBAAqB,MAAM,WAAW,UAAU;IACxD,cAAc,MAAM,YAAY,OAAO,KAAK;GAC9C,CAAC;GACD;GACA,GAAG;GACH,GAAG,UAAU;EACf,CACF;EACA,MA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ACA;GACA,UAAU,aAA6B,oBAAI,OAAO;IAAE,MAAM;IAAY,UAAU;GAAM,CAAC,IAAI;EAC7F,CACF,GACA,WACF,EAAE,CAAC;CACL,GACA,EACE,cAAc,KAChB,CACF;CACA,OAAO,qBAAqB,iBAAiB;EAC3C;EACA,OAAO;CACT,CAAC;AACH;AACA,MAAM,SAAS,aAAa;CAC1B,OAAO;CACP,OAAO;AACT,CAAC;AACD,MAAM,cAAc,OAAO"}
1
+ {"version":3,"file":"Switch.js","names":[],"sources":["jsx/Switch.js"],"sourcesContent":["import {\n composeEventHandlers,\n createStyledHOC,\n getVariableValue,\n isWeb,\n styled,\n View,\n withStaticProperties\n} from \"@tamagui/core\";\nimport { useSwitch } from \"@tamagui/switch-headless\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport * as React from \"react\";\nimport { SwitchStyledContext } from \"./StyledContext\";\nimport { useSwitchNative } from \"./useSwitchNative\";\nimport { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nconst SwitchThumbFrame = styled(View, {\n displayName: \"SwitchThumb\",\n context: SwitchStyledContext\n});\nconst SwitchFrame = styled(View, {\n displayName: \"Switch\",\n context: SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n const Frame = createProps.Frame ?? SwitchFrame;\n const Thumb = createProps.Thumb ?? SwitchThumbFrame;\n Frame.staticConfig.context = SwitchStyledContext;\n Thumb.staticConfig.context = SwitchStyledContext;\n const SwitchThumbComponent = createStyledHOC(\n Thumb,\n function SwitchThumb2(props, forwardedRef) {\n const { size: sizeProp, activeStyle, ...thumbProps } = props;\n const styledContext = SwitchStyledContext.useStyledContext();\n const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n const size = sizeProp ?? sizeContext ?? true;\n const initialChecked = React.useRef(active).current;\n const initialWidth = getVariableValue(props.width, \"size\");\n const [thumbWidth, setThumbWidth] = React.useState(\n typeof initialWidth === \"number\" ? initialWidth : 0\n );\n const distance = frameWidth - thumbWidth;\n const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n return /* @__PURE__ */ jsx(\n Thumb,\n {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: composeEventHandlers(props.onLayout, (event) => {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n }\n );\n }\n );\n const SwitchComponent = createStyledHOC(\n Frame,\n function Switch2(_props, forwardedRef) {\n const {\n native,\n nativeProps,\n checked: checkedProp,\n defaultChecked,\n onCheckedChange,\n activeStyle,\n activeTheme,\n ...props\n } = _props;\n const [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n const styledContext = React.useContext(SwitchStyledContext.context);\n const [frameWidth, setFrameInnerWidth] = React.useState(0);\n const { switchProps, bubbleInput, switchRef } = useSwitch(\n props,\n [checked, setChecked],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n const nativeSwitch = useSwitchNative({\n id: props.id,\n disabled: props.disabled,\n native,\n nativeProps,\n checked,\n setChecked\n });\n if (nativeSwitch) {\n return nativeSwitch;\n }\n const disabled = props.disabled;\n const size = styledContext.size ?? props.size ?? true;\n const handleLayout = (event) => {\n const next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n return /* @__PURE__ */ jsxs(Fragment, { children: [\n /* @__PURE__ */ jsx(\n SwitchStyledContext.Provider,\n {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: /* @__PURE__ */ jsx(\n Frame,\n {\n ref: switchRef,\n render: \"button\",\n theme: checked ? activeTheme ?? createProps.activeTheme ?? null : null,\n ...isWeb && { type: \"button\" },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ jsx(View, { alignSelf: \"stretch\", flex: 1, onLayout: handleLayout, children: props.children })\n }\n )\n }\n ),\n bubbleInput\n ] });\n }\n );\n return withStaticProperties(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nconst Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nconst SwitchThumb = Switch.Thumb;\nexport {\n Switch,\n SwitchFrame,\n SwitchThumb,\n SwitchThumbFrame,\n createSwitch\n};\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;;;;;;;AAeA,MAAM,mBAAmB,OAAO,MAAM;CACpC,aAAa;CACb,SAAS;AACX,CAAC;AACD,MAAM,cAAc,OAAO,MAAM;CAC/B,aAAa;CACb,SAAS;CACT,QAAQ;CACR,UAAU;AACZ,CAAC;AACD,SAAS,aAAa,aAAa;CACjC,MAAM,QAAQ,YAAY,SAAS;CACnC,MAAM,QAAQ,YAAY,SAAS;CACnC,MAAM,aAAa,UAAU;CAC7B,MAAM,aAAa,UAAU;CAC7B,MAAM,uBAAuB,gBAC3B,OACA,SAAS,aAAa,OAAO,cAAc;EACzC,MAAM,EAAE,MAAM,UAAU,aAAa,GAAG,eAAe;EACvD,MAAM,gBAAgB,oBAAoB,iBAAiB;EAC3D,MAAM,EAAE,MAAM,aAAa,QAAQ,UAAU,aAAa,MAAM;EAChE,MAAM,OAAO,YAAY,eAAe;EACxC,MAAM,iBAAiB,MAAM,OAAO,MAAM,CAAC,CAAC;EAC5C,MAAM,eAAe,iBAAiB,MAAM,OAAO,MAAM;EACzD,MAAM,CAAC,YAAY,iBAAiB,MAAM,SACxC,OAAO,iBAAiB,WAAW,eAAe,CACpD;EACA,MAAM,WAAW,aAAa;EAC9B,MAAM,IAAI,iBAAiB,SAAS,IAAI,CAAC,WAAW,SAAS,WAAW;EACxE,OAAuB,oBACrB,OACA;GACE,KAAK;GACL;GACA,WAAW,iBAAiB,aAAa;GACzC;GACA,UAAU,qBAAqB,MAAM,WAAW,UAAU;IACxD,cAAc,MAAM,YAAY,OAAO,KAAK;GAC9C,CAAC;GACD;GACA,GAAG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AAM,SAAS,aAAa;CAC1B,OAAO;CACP,OAAO;AACT,CAAC;AACD,MAAM,cAAc,OAAO"}
@@ -60,8 +60,7 @@ function createSwitch(createProps) {
60
60
  Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
61
61
  Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
62
62
  var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
63
- var _createProps_componentThemes;
64
- var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
63
+ var { size: sizeProp, activeStyle, ...thumbProps } = props;
65
64
  var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
66
65
  var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
67
66
  var _ref;
@@ -71,7 +70,7 @@ function createSwitch(createProps) {
71
70
  var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
72
71
  var distance = frameWidth - thumbWidth;
73
72
  var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
74
- var thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
73
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
75
74
  ref: forwardedRef,
76
75
  size,
77
76
  alignSelf: initialChecked ? "flex-end" : "flex-start",
@@ -83,15 +82,9 @@ function createSwitch(createProps) {
83
82
  ...thumbProps,
84
83
  ...active && activeStyle
85
84
  });
86
- var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;
87
- return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
88
- name: themeName,
89
- children: thumb
90
- }) : thumb;
91
85
  });
92
86
  var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
93
- var _createProps_componentThemes;
94
- var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
87
+ var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
95
88
  var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
96
89
  prop: checkedProp,
97
90
  defaultProp: defaultChecked || false,
@@ -121,35 +114,31 @@ function createSwitch(createProps) {
121
114
  setFrameInnerWidth(next);
122
115
  }
123
116
  };
124
- var frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
125
- ref: switchRef,
126
- render: "button",
127
- ...import_core.isWeb && { type: "button" },
128
- size,
129
- ...props,
130
- ...switchProps,
131
- disabled,
132
- ...checked && activeStyle,
133
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
134
- alignSelf: "stretch",
135
- flex: 1,
136
- onLayout: handleLayout,
137
- children: props.children
138
- })
139
- });
140
- var _ref1, _ref2;
141
- var frameTheme = (_ref2 = (_ref1 = checked ? activeTheme : void 0) !== null && _ref1 !== void 0 ? _ref1 : theme) !== null && _ref2 !== void 0 ? _ref2 : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.frame;
117
+ var _ref1;
142
118
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
143
119
  size,
144
120
  active: checked,
145
121
  disabled,
146
122
  frameWidth,
147
- children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
148
- name: frameTheme,
149
- children: frame
150
- }) : frame
123
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
124
+ ref: switchRef,
125
+ render: "button",
126
+ theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,
127
+ ...import_core.isWeb && { type: "button" },
128
+ size,
129
+ ...props,
130
+ ...switchProps,
131
+ disabled,
132
+ ...checked && activeStyle,
133
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
134
+ alignSelf: "stretch",
135
+ flex: 1,
136
+ onLayout: handleLayout,
137
+ children: props.children
138
+ })
139
+ })
151
140
  }), bubbleInput] });
152
- }, { disableTheme: true });
141
+ });
153
142
  return (0, import_core.withStaticProperties)(SwitchComponent, {
154
143
  Frame,
155
144
  Thumb: SwitchThumbComponent
@@ -60,8 +60,7 @@ function createSwitch(createProps) {
60
60
  Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
61
61
  Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
62
62
  var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {
63
- var _createProps_componentThemes;
64
- var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
63
+ var { size: sizeProp, activeStyle, ...thumbProps } = props;
65
64
  var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
66
65
  var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
67
66
  var _ref;
@@ -71,7 +70,7 @@ function createSwitch(createProps) {
71
70
  var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
72
71
  var distance = frameWidth - thumbWidth;
73
72
  var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
74
- var thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
73
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {
75
74
  ref: forwardedRef,
76
75
  size,
77
76
  alignSelf: initialChecked ? "flex-end" : "flex-start",
@@ -83,15 +82,9 @@ function createSwitch(createProps) {
83
82
  ...thumbProps,
84
83
  ...active && activeStyle
85
84
  });
86
- var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;
87
- return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
88
- name: themeName,
89
- children: thumb
90
- }) : thumb;
91
85
  });
92
86
  var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {
93
- var _createProps_componentThemes;
94
- var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
87
+ var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;
95
88
  var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
96
89
  prop: checkedProp,
97
90
  defaultProp: defaultChecked || false,
@@ -121,35 +114,31 @@ function createSwitch(createProps) {
121
114
  setFrameInnerWidth(next);
122
115
  }
123
116
  };
124
- var frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
125
- ref: switchRef,
126
- render: "button",
127
- ...import_core.isWeb && { type: "button" },
128
- size,
129
- ...props,
130
- ...switchProps,
131
- disabled,
132
- ...checked && activeStyle,
133
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
134
- alignSelf: "stretch",
135
- flex: 1,
136
- onLayout: handleLayout,
137
- children: props.children
138
- })
139
- });
140
- var _ref1, _ref2;
141
- var frameTheme = (_ref2 = (_ref1 = checked ? activeTheme : void 0) !== null && _ref1 !== void 0 ? _ref1 : theme) !== null && _ref2 !== void 0 ? _ref2 : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.frame;
117
+ var _ref1;
142
118
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
143
119
  size,
144
120
  active: checked,
145
121
  disabled,
146
122
  frameWidth,
147
- children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
148
- name: frameTheme,
149
- children: frame
150
- }) : frame
123
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {
124
+ ref: switchRef,
125
+ render: "button",
126
+ theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,
127
+ ...import_core.isWeb && { type: "button" },
128
+ size,
129
+ ...props,
130
+ ...switchProps,
131
+ disabled,
132
+ ...checked && activeStyle,
133
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
134
+ alignSelf: "stretch",
135
+ flex: 1,
136
+ onLayout: handleLayout,
137
+ children: props.children
138
+ })
139
+ })
151
140
  }), bubbleInput] });
152
- }, { disableTheme: true });
141
+ });
153
142
  return (0, import_core.withStaticProperties)(SwitchComponent, {
154
143
  Frame,
155
144
  Thumb: SwitchThumbComponent
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.native.js","names":[],"sources":["jsx/Switch.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar Switch_exports = {};\n__export(Switch_exports, {\n Switch: () => Switch,\n SwitchFrame: () => SwitchFrame,\n SwitchThumb: () => SwitchThumb,\n SwitchThumbFrame: () => SwitchThumbFrame,\n createSwitch: () => createSwitch\n});\nmodule.exports = __toCommonJS(Switch_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_core = require(\"@tamagui/core\");\nvar import_switch_headless = require(\"@tamagui/switch-headless\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar React = __toESM(require(\"react\"), 1);\nvar import_StyledContext = require(\"./StyledContext\");\nvar import_useSwitchNative = require(\"./useSwitchNative\");\nvar SwitchThumbFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"SwitchThumb\",\n context: import_StyledContext.SwitchStyledContext\n});\nvar SwitchFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"Switch\",\n context: import_StyledContext.SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n var _createProps_Frame;\n var Frame = (_createProps_Frame = createProps.Frame) !== null && _createProps_Frame !== void 0 ? _createProps_Frame : SwitchFrame;\n var _createProps_Thumb;\n var Thumb = (_createProps_Thumb = createProps.Thumb) !== null && _createProps_Thumb !== void 0 ? _createProps_Thumb : SwitchThumbFrame;\n Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;\n Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;\n var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {\n var _createProps_componentThemes;\n var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;\n var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();\n var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n var _ref;\n var size = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref !== void 0 ? _ref : true;\n var initialChecked = React.useRef(active).current;\n var initialWidth = (0, import_core.getVariableValue)(props.width, \"size\");\n var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === \"number\" ? initialWidth : 0);\n var distance = frameWidth - thumbWidth;\n var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n var thumb = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(event) {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n });\n var themeName = theme !== null && theme !== void 0 ? theme : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.thumb;\n return themeName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {\n name: themeName,\n children: thumb\n }) : thumb;\n });\n var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {\n var _createProps_componentThemes;\n var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;\n var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);\n var [frameWidth, setFrameInnerWidth] = React.useState(0);\n var { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(\n props,\n [\n checked,\n setChecked\n ],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n var nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({\n id: props.id,\n disabled: props.disabled,\n native,\n nativeProps,\n checked,\n setChecked\n });\n if (nativeSwitch) {\n return nativeSwitch;\n }\n var disabled = props.disabled;\n var _styledContext_size, _ref;\n var size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : true;\n var handleLayout = function(event) {\n var next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n var frame = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {\n ref: switchRef,\n render: \"button\",\n ...import_core.isWeb && {\n type: \"button\"\n },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {\n alignSelf: \"stretch\",\n flex: 1,\n onLayout: handleLayout,\n children: props.children\n })\n });\n var _ref1, _ref2;\n var frameTheme = (_ref2 = (_ref1 = checked ? activeTheme : void 0) !== null && _ref1 !== void 0 ? _ref1 : theme) !== null && _ref2 !== void 0 ? _ref2 : (_createProps_componentThemes = createProps.componentThemes) === null || _createProps_componentThemes === void 0 ? void 0 : _createProps_componentThemes.frame;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {\n children: [\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: frameTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {\n name: frameTheme,\n children: frame\n }) : frame\n }),\n bubbleInput\n ]\n });\n }, {\n disableTheme: true\n });\n return (0, import_core.withStaticProperties)(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nvar Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nvar SwitchThumb = Switch.Thumb;\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO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\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar Switch_exports = {};\n__export(Switch_exports, {\n Switch: () => Switch,\n SwitchFrame: () => SwitchFrame,\n SwitchThumb: () => SwitchThumb,\n SwitchThumbFrame: () => SwitchThumbFrame,\n createSwitch: () => createSwitch\n});\nmodule.exports = __toCommonJS(Switch_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_core = require(\"@tamagui/core\");\nvar import_switch_headless = require(\"@tamagui/switch-headless\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar React = __toESM(require(\"react\"), 1);\nvar import_StyledContext = require(\"./StyledContext\");\nvar import_useSwitchNative = require(\"./useSwitchNative\");\nvar SwitchThumbFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"SwitchThumb\",\n context: import_StyledContext.SwitchStyledContext\n});\nvar SwitchFrame = (0, import_core.styled)(import_core.View, {\n displayName: \"Switch\",\n context: import_StyledContext.SwitchStyledContext,\n render: \"button\",\n tabIndex: 0\n});\nfunction createSwitch(createProps) {\n var _createProps_Frame;\n var Frame = (_createProps_Frame = createProps.Frame) !== null && _createProps_Frame !== void 0 ? _createProps_Frame : SwitchFrame;\n var _createProps_Thumb;\n var Thumb = (_createProps_Thumb = createProps.Thumb) !== null && _createProps_Thumb !== void 0 ? _createProps_Thumb : SwitchThumbFrame;\n Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;\n Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;\n var SwitchThumbComponent = (0, import_core.createStyledHOC)(Thumb, function SwitchThumb2(props, forwardedRef) {\n var { size: sizeProp, activeStyle, ...thumbProps } = props;\n var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();\n var { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;\n var _ref;\n var size = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref !== void 0 ? _ref : true;\n var initialChecked = React.useRef(active).current;\n var initialWidth = (0, import_core.getVariableValue)(props.width, \"size\");\n var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === \"number\" ? initialWidth : 0);\n var distance = frameWidth - thumbWidth;\n var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumb, {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function(event) {\n setThumbWidth(event.nativeEvent.layout.width);\n }),\n disabled,\n ...thumbProps,\n ...active && activeStyle\n });\n });\n var SwitchComponent = (0, import_core.createStyledHOC)(Frame, function Switch2(_props, forwardedRef) {\n var { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, ...props } = _props;\n var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);\n var [frameWidth, setFrameInnerWidth] = React.useState(0);\n var { switchProps, bubbleInput, switchRef } = (0, import_switch_headless.useSwitch)(\n props,\n [\n checked,\n setChecked\n ],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n var nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({\n id: props.id,\n disabled: props.disabled,\n native,\n nativeProps,\n checked,\n setChecked\n });\n if (nativeSwitch) {\n return nativeSwitch;\n }\n var disabled = props.disabled;\n var _styledContext_size, _ref;\n var size = (_ref = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref !== void 0 ? _ref : true;\n var handleLayout = function(event) {\n var next = event.nativeEvent.layout.width;\n if (next !== frameWidth) {\n setFrameInnerWidth(next);\n }\n };\n var _ref1;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {\n children: [\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Frame, {\n ref: switchRef,\n render: \"button\",\n // the track and the thumb swap onto one theme while checked, so\n // the fill and the knob move together. the key stays present with\n // a null value so toggling never re-parents the frame.\n theme: checked ? (_ref1 = activeTheme !== null && activeTheme !== void 0 ? activeTheme : createProps.activeTheme) !== null && _ref1 !== void 0 ? _ref1 : null : null,\n ...import_core.isWeb && {\n type: \"button\"\n },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {\n alignSelf: \"stretch\",\n flex: 1,\n onLayout: handleLayout,\n children: props.children\n })\n })\n }),\n bubbleInput\n ]\n });\n });\n return (0, import_core.withStaticProperties)(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nvar Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nvar SwitchThumb = Switch.Thumb;\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,iBAAiB,CAAC;AACtB,SAAS,gBAAgB;CACvB,cAAc;CACd,mBAAmB;CACnB,mBAAmB;CACnB,wBAAwB;CACxB,oBAAoB;AACtB,CAAC;AACD,OAAO,UAA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L,IAAI,eAAe,SAAS,OAAO;GACjC,IAAI,OAAO,MAAM,YAAY,OAAO;GACpC,IAAI,SAAS,YAAY;IACvB,mBAAmB,IAAI;GACzB;EACF;EACA,IAAI;EACJ,OAAuB,iBAAC,GAAG,mBAAmB,KAAI,CAAE,mBAAmB,UAAU,EAC/E,UAAU,CACQ,iBAAC,GAAG,mBAAmB,IAAG,CAAE,qBAAqB,oBAAoB,UAAU;GAC7F;GACA,QAAQ;GACR;GACA;GACA,UAA0B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,OAAO;IAC3D,KAAK;IACL,QAAQ;IAIR,OAAO,WAAW,QAAQ,gBAAgB,QAAQ,gBAAgB,KAAK,IAAI,cAAc,YAAY,iBAAiB,QAAQ,UAAU,KAAK,IAAI,QAAQ,OAAO;IAChK,GAAG,YAAY,SAAS,EACtB,MAAM,SACR;IACA;IACA,GAAG;IACH,GAAG;IACH;IACA,GAAG,WAAW;IACd,UAA0B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,YAAY,MAAM;KACtE,WAAW;KACX,MAAM;KACN,UAAU;KACV,UAAU,MAAM;IAClB,CAAC;GACH,CAAC;EACH,CAAC,GACD,WACF,EACF,CAAC;CACH,CAAC;CACD,QAAQ,GAAG,YAAY,qBAAoB,CAAE,iBAAiB;EAC5D;EACA,OAAO;CACT,CAAC;AACH;AACA,IAAI,SAAS,aAAa;CACxB,OAAO;CACP,OAAO;AACT,CAAC;AACD,IAAI,cAAc,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/switch",
3
- "version": "3.0.0-beta.1216.1",
3
+ "version": "3.0.0-beta.1310.1",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "files": [
@@ -35,14 +35,14 @@
35
35
  "clean:build": "tamagui-build clean:build"
36
36
  },
37
37
  "dependencies": {
38
- "@tamagui/core": "3.0.0-beta.1216.1",
39
- "@tamagui/focusable": "3.0.0-beta.1216.1",
40
- "@tamagui/react-native-types": "3.0.0-beta.1216.1",
41
- "@tamagui/switch-headless": "3.0.0-beta.1216.1",
42
- "@tamagui/use-controllable-state": "3.0.0-beta.1216.1"
38
+ "@tamagui/core": "3.0.0-beta.1310.1",
39
+ "@tamagui/focusable": "3.0.0-beta.1310.1",
40
+ "@tamagui/react-native-types": "3.0.0-beta.1310.1",
41
+ "@tamagui/switch-headless": "3.0.0-beta.1310.1",
42
+ "@tamagui/use-controllable-state": "3.0.0-beta.1310.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@tamagui/build": "3.0.0-beta.1216.1",
45
+ "@tamagui/build": "3.0.0-beta.1310.1",
46
46
  "react": "19.2.3",
47
47
  "react-native": "0.86.2"
48
48
  },
package/src/Switch.tsx CHANGED
@@ -5,7 +5,6 @@ import {
5
5
  getVariableValue,
6
6
  isWeb,
7
7
  styled,
8
- Theme,
9
8
  type ThemeProps,
10
9
  View,
11
10
  withStaticProperties,
@@ -38,10 +37,11 @@ export const SwitchFrame = styled(View, {
38
37
  export function createSwitch(createProps: {
39
38
  Frame?: SwitchFrameComponent
40
39
  Thumb?: SwitchThumbFrameComponent
41
- componentThemes?: {
42
- frame?: ThemeProps['name']
43
- thumb?: ThemeProps['name']
44
- }
40
+ /**
41
+ * theme the whole control swaps onto while checked, so the track fill and the
42
+ * thumb move together. the `activeTheme` prop overrides it per instance.
43
+ */
44
+ activeTheme?: ThemeProps['name']
45
45
  }) {
46
46
  const Frame = (createProps.Frame ?? SwitchFrame) as typeof SwitchFrame
47
47
  const Thumb = (createProps.Thumb ?? SwitchThumbFrame) as typeof SwitchThumbFrame
@@ -55,7 +55,7 @@ export function createSwitch(createProps: {
55
55
  props: Omit<GetProps<typeof Thumb>, keyof SwitchThumbProps> & SwitchThumbProps,
56
56
  forwardedRef
57
57
  ) {
58
- const { size: sizeProp, activeStyle, theme, ...thumbProps } = props
58
+ const { size: sizeProp, activeStyle, ...thumbProps } = props
59
59
  const styledContext = SwitchStyledContext.useStyledContext()
60
60
  const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext
61
61
  const size = sizeProp ?? sizeContext ?? true
@@ -67,7 +67,7 @@ export function createSwitch(createProps: {
67
67
  const distance = frameWidth - thumbWidth
68
68
  const x = initialChecked ? (active ? 0 : -distance) : active ? distance : 0
69
69
 
70
- const thumb = (
70
+ return (
71
71
  <Thumb
72
72
  ref={forwardedRef}
73
73
  size={size}
@@ -81,9 +81,6 @@ export function createSwitch(createProps: {
81
81
  {...(active && activeStyle)}
82
82
  />
83
83
  )
84
-
85
- const themeName = theme ?? createProps.componentThemes?.thumb
86
- return themeName ? <Theme name={themeName}>{thumb}</Theme> : thumb
87
84
  }
88
85
  )
89
86
 
@@ -98,7 +95,6 @@ export function createSwitch(createProps: {
98
95
  onCheckedChange,
99
96
  activeStyle,
100
97
  activeTheme,
101
- theme,
102
98
  ...props
103
99
  } = _props
104
100
  const [checked, setChecked] = useControllableState({
@@ -138,26 +134,6 @@ export function createSwitch(createProps: {
138
134
  }
139
135
  }
140
136
 
141
- const frame = (
142
- <Frame
143
- ref={switchRef}
144
- render="button"
145
- {...(isWeb && { type: 'button' })}
146
- size={size}
147
- {...props}
148
- {...(switchProps as any)}
149
- disabled={disabled}
150
- {...(checked && activeStyle)}
151
- >
152
- <View alignSelf="stretch" flex={1} onLayout={handleLayout}>
153
- {props.children}
154
- </View>
155
- </Frame>
156
- )
157
-
158
- const frameTheme =
159
- (checked ? activeTheme : undefined) ?? theme ?? createProps.componentThemes?.frame
160
-
161
137
  return (
162
138
  <>
163
139
  <SwitchStyledContext.Provider
@@ -166,15 +142,29 @@ export function createSwitch(createProps: {
166
142
  disabled={disabled}
167
143
  frameWidth={frameWidth}
168
144
  >
169
- {frameTheme ? <Theme name={frameTheme}>{frame}</Theme> : frame}
145
+ <Frame
146
+ ref={switchRef}
147
+ render="button"
148
+ // the track and the thumb swap onto one theme while checked, so
149
+ // the fill and the knob move together. the key stays present with
150
+ // a null value so toggling never re-parents the frame.
151
+ theme={checked ? (activeTheme ?? createProps.activeTheme ?? null) : null}
152
+ {...(isWeb && { type: 'button' })}
153
+ size={size}
154
+ {...props}
155
+ {...(switchProps as any)}
156
+ disabled={disabled}
157
+ {...(checked && activeStyle)}
158
+ >
159
+ <View alignSelf="stretch" flex={1} onLayout={handleLayout}>
160
+ {props.children}
161
+ </View>
162
+ </Frame>
170
163
  </SwitchStyledContext.Provider>
171
164
 
172
165
  {bubbleInput}
173
166
  </>
174
167
  )
175
- },
176
- {
177
- disableTheme: true,
178
168
  }
179
169
  )
180
170