@tamagui/switch 2.7.7 → 3.0.0-beta.1093.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.
Files changed (97) hide show
  1. package/dist/cjs/StyledContext.cjs +18 -23
  2. package/dist/cjs/StyledContext.native.cjs +32 -0
  3. package/dist/cjs/StyledContext.native.js +18 -22
  4. package/dist/cjs/StyledContext.native.js.map +1 -1
  5. package/dist/cjs/Switch.cjs +139 -86
  6. package/dist/cjs/Switch.native.cjs +162 -0
  7. package/dist/cjs/Switch.native.js +146 -90
  8. package/dist/cjs/Switch.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +13 -25
  10. package/dist/cjs/index.native.cjs +30 -0
  11. package/dist/cjs/index.native.js +14 -25
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/types.cjs +9 -11
  14. package/dist/cjs/types.native.cjs +18 -0
  15. package/dist/cjs/types.native.js +9 -10
  16. package/dist/cjs/types.native.js.map +1 -1
  17. package/dist/cjs/useSwitchNative.cjs +15 -19
  18. package/dist/cjs/useSwitchNative.native.cjs +64 -0
  19. package/dist/cjs/useSwitchNative.native.js +43 -54
  20. package/dist/cjs/useSwitchNative.native.js.map +1 -1
  21. package/dist/esm/StyledContext.mjs +6 -5
  22. package/dist/esm/StyledContext.mjs.map +1 -1
  23. package/dist/esm/StyledContext.native.js +6 -5
  24. package/dist/esm/StyledContext.native.js.map +1 -1
  25. package/dist/esm/Switch.mjs +119 -71
  26. package/dist/esm/Switch.mjs.map +1 -1
  27. package/dist/esm/Switch.native.js +126 -76
  28. package/dist/esm/Switch.native.js.map +1 -1
  29. package/dist/esm/index.js +8 -12
  30. package/dist/esm/index.mjs +8 -12
  31. package/dist/esm/index.native.js +8 -12
  32. package/dist/esm/types.mjs +0 -2
  33. package/dist/esm/types.native.js +0 -2
  34. package/dist/esm/useSwitchNative.mjs +2 -1
  35. package/dist/esm/useSwitchNative.mjs.map +1 -1
  36. package/dist/esm/useSwitchNative.native.js +30 -31
  37. package/dist/esm/useSwitchNative.native.js.map +1 -1
  38. package/dist/jsx/StyledContext.mjs +6 -5
  39. package/dist/jsx/StyledContext.mjs.map +1 -1
  40. package/dist/jsx/StyledContext.native.cjs +32 -0
  41. package/dist/jsx/StyledContext.native.js +18 -22
  42. package/dist/jsx/StyledContext.native.js.map +1 -1
  43. package/dist/jsx/Switch.mjs +119 -71
  44. package/dist/jsx/Switch.mjs.map +1 -1
  45. package/dist/jsx/Switch.native.cjs +162 -0
  46. package/dist/jsx/Switch.native.js +146 -90
  47. package/dist/jsx/Switch.native.js.map +1 -1
  48. package/dist/jsx/index.js +8 -12
  49. package/dist/jsx/index.mjs +8 -12
  50. package/dist/jsx/index.native.cjs +30 -0
  51. package/dist/jsx/index.native.js +14 -25
  52. package/dist/jsx/index.native.js.map +1 -1
  53. package/dist/jsx/types.mjs +0 -2
  54. package/dist/jsx/types.native.cjs +18 -0
  55. package/dist/jsx/types.native.js +9 -10
  56. package/dist/jsx/types.native.js.map +1 -1
  57. package/dist/jsx/useSwitchNative.mjs +2 -1
  58. package/dist/jsx/useSwitchNative.mjs.map +1 -1
  59. package/dist/jsx/useSwitchNative.native.cjs +64 -0
  60. package/dist/jsx/useSwitchNative.native.js +43 -54
  61. package/dist/jsx/useSwitchNative.native.js.map +1 -1
  62. package/package.json +10 -15
  63. package/src/StyledContext.tsx +1 -3
  64. package/src/Switch.tsx +190 -89
  65. package/src/index.ts +0 -20
  66. package/src/types.ts +7 -6
  67. package/types/StyledContext.d.ts +2 -3
  68. package/types/StyledContext.d.ts.map +1 -1
  69. package/types/Switch.d.ts +209 -37
  70. package/types/Switch.d.ts.map +1 -1
  71. package/types/index.d.ts +0 -146
  72. package/types/index.d.ts.map +1 -1
  73. package/types/types.d.ts +4 -5
  74. package/types/types.d.ts.map +1 -1
  75. package/dist/cjs/createSwitch.cjs +0 -186
  76. package/dist/cjs/createSwitch.native.js +0 -194
  77. package/dist/cjs/createSwitch.native.js.map +0 -1
  78. package/dist/esm/createSwitch.mjs +0 -150
  79. package/dist/esm/createSwitch.mjs.map +0 -1
  80. package/dist/esm/createSwitch.native.js +0 -155
  81. package/dist/esm/createSwitch.native.js.map +0 -1
  82. package/dist/esm/index.js.map +0 -1
  83. package/dist/esm/index.mjs.map +0 -1
  84. package/dist/esm/index.native.js.map +0 -1
  85. package/dist/esm/types.mjs.map +0 -1
  86. package/dist/esm/types.native.js.map +0 -1
  87. package/dist/jsx/createSwitch.mjs +0 -150
  88. package/dist/jsx/createSwitch.mjs.map +0 -1
  89. package/dist/jsx/createSwitch.native.js +0 -194
  90. package/dist/jsx/createSwitch.native.js.map +0 -1
  91. package/dist/jsx/index.js.map +0 -1
  92. package/dist/jsx/index.mjs.map +0 -1
  93. package/dist/jsx/types.mjs.map +0 -1
  94. package/src/Switch.draggable-tmp +0 -340
  95. package/src/createSwitch.tsx +0 -201
  96. package/types/createSwitch.d.ts +0 -141
  97. package/types/createSwitch.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["getVariableValue","styled","getSize","YStack","SwitchThumb","name","variants","unstyled","false","size","backgroundColor","borderRadius","...size","val","getSwitchHeight","height","width","defaultVariants","process","env","TAMAGUI_HEADLESS","accept","activeStyle","Math","round","getSwitchWidth","SwitchFrame","render","tabIndex","focusVisibleStyle","outlineColor","outlineStyle","outlineWidth","param","props","minHeight"],"sources":["../../src/Switch.tsx"],"sourcesContent":[null],"mappings":"AACA,SAASA,gBAAA,EAAkBC,MAAA,QAAc;AACzC,SAASC,OAAA,QAAe;AACxB,SAASC,MAAA,QAAc;AAEhB,IAAAC,WAAM,GAAAH,MAAc,CAAAE,MAAA;EACzBE,IAAA;EACAC,QAAA;IACEC,QAAM;MAENC,KAAA;QACEC,IAAA,SAAU;QACRC,eAAO;QAAAC,YACC;MAAA;IACW;IACHF,IAChB;MACF,oBAAAG,CAAAC,GAAA;QAEA,IAAMJ,IAAA,GAAAK,eAAA,CAAAD,GAAA;QACJ;UACEE,MAAM,EAAAN,IAAA;UACNO,KAAA,EAAOP;QAAA;MACG;IACD;EACT;EACFQ,eACF;IACFV,QAAA,EAAAW,OAAA,CAAAC,GAAA,CAAAC,gBAAA;EAAA;AAEiB;EAC4BC,MAC7C;IACFC,WAAA;EACA;AAAA;AACU,IAAAR,eACO,YAAAA,CAAAD,GAAA;EAAA,OACfU,IAAA,CAAAC,KAAA,CAAAxB,gBAAA,CAAAE,OAAA,CAAAW,GAAA;AAAA;AAEJ,IAAAY,cAAA,YAAAA,CAAAZ,GAAA;EAEA,OAAMC,eAAkB,CAACD,GAAA,KACvB;AAEF;AAEO,IAAAa,WAAM,GAAAzB,MAAc,CAAAE,MAAA;EACzBE,IAAA;EACAsB,MAAA;EAAAC,QACQ;EAAAtB,QACN,EAAQ;IACRC,QAAA,EAAU;MAEVC,KAAA;QACEG,YAAU;QACRD,eAAO;QAAAmB,iBACS;UACdC,YAAA,iBAAiB;UAEjBC,YAAA,SAAmB;UAAAC,YACjB;QAAc;MACA;IACA;IAChBvB,IACF;MACF,oBAAAG,CAAAC,GAAA,EAAAoB,KAAA;QAEA,IAAM;UAAAC;QAAA,IAAAD,KAAA;QACJ,IAAAC,KAAA,WAAmB;QACjB,IAAAnB,MAAI,GAAMD,eAAa,CAAAD,GAAA;QACvB,IAAAG,KAAM,GAAAS,cAAS,CAAAZ,GAAA;QACf;UACAE,MAAA;UAAOoB,SACL,EAAApB,MAAA;UAAAC;QACW;MACX;IACF;EACF;EACFC,eACF;IAEAV,QAAA,EAAAW,OAAiB,CAAAC,GAAA,CAAAC,gBAAA;EAAA;AAC4B;EAE/CC,MAAA;IACAC,WAAA;EAAA;AACU;AACO,SAEjBI,WAAA,EACFtB,WAAA","ignoreList":[]}
1
+ {"version":3,"file":"Switch.native.js","names":["_Fragment"],"sources":["esm/Switch.native.js"],"sourcesContent":["import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nimport { composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, Theme, View, withStaticProperties } 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\";\nvar SwitchThumbFrame = styled(View, {\n displayName: \"SwitchThumb\",\n context: SwitchStyledContext\n});\nvar SwitchFrame = styled(View, {\n displayName: \"Switch\",\n context: 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 = SwitchStyledContext;\n Thumb.staticConfig.context = SwitchStyledContext;\n var SwitchThumbComponent = createStyledHOC(Thumb, function SwitchThumb2(props, forwardedRef) {\n var _createProps_componentThemes;\n var { size: sizeProp, activeStyle, theme, ...thumbProps } = props;\n var 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 = 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__ */ _jsx(Thumb, {\n ref: forwardedRef,\n size,\n alignSelf: initialChecked ? \"flex-end\" : \"flex-start\",\n x,\n onLayout: 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__ */ _jsx(Theme, {\n name: themeName,\n children: thumb\n }) : thumb;\n });\n var SwitchComponent = 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] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true\n });\n var styledContext = React.useContext(SwitchStyledContext.context);\n var [frameWidth, setFrameInnerWidth] = React.useState(0);\n var { switchProps, bubbleInput, switchRef } = useSwitch(\n props,\n [\n checked,\n setChecked\n ],\n // @ts-ignore TODO tamagui react 19 type error\n forwardedRef\n );\n var 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 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__ */ _jsx(Frame, {\n ref: switchRef,\n render: \"button\",\n ...isWeb && {\n type: \"button\"\n },\n size,\n ...props,\n ...switchProps,\n disabled,\n ...checked && activeStyle,\n children: /* @__PURE__ */ _jsx(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__ */ _jsxs(_Fragment, {\n children: [\n /* @__PURE__ */ _jsx(SwitchStyledContext.Provider, {\n size,\n active: checked,\n disabled,\n frameWidth,\n children: frameTheme ? /* @__PURE__ */ _jsx(Theme, {\n name: frameTheme,\n children: frame\n }) : frame\n }),\n bubbleInput\n ]\n });\n }, {\n disableTheme: true\n });\n return withStaticProperties(SwitchComponent, {\n Frame,\n Thumb: SwitchThumbComponent\n });\n}\nvar Switch = createSwitch({\n Frame: SwitchFrame,\n Thumb: SwitchThumbFrame\n});\nvar SwitchThumb = Switch.Thumb;\nexport {\n Switch,\n SwitchFrame,\n SwitchThumb,\n SwitchThumbFrame,\n createSwitch\n};\n//# sourceMappingURL=Switch.js.map\n"],"mappings":";;;;;;;;;AAOA,IAAI,mBAAmB,OAAO,MAAM;CAClC,aAAa;CACb,SAAS;AACX,CAAC;AACD,IAAI,cAAc,OAAO,MAAM;CAC7B,aAAa;CACb,SAAS;CACT,QAAQ;CACR,UAAU;AACZ,CAAC;AACD,SAAS,aAAa,aAAa;CACjC,IAAI;CACJ,IAAI,SAAS,qBAAqB,YAAY,WAAW,QAAQ,uBAAuB,KAAK,IAAI,qBAAqB;CACtH,IAAI;CACJ,IAAI,SAAS,qBAAqB,YAAY,WAAW,QAAQ,uBAAuB,KAAK,IAAI,qBAAqB;CACtH,MAAM,aAAa,UAAU;CAC7B,MAAM,aAAa,UAAU;CAC7B,IAAI,uBAAuB,gBAAgB,OAAO,SAAS,aAAa,OAAO,cAAc;EAC3F,IAAI;EACJ,IAAI,EAAE,MAAM,UAAU,aAAa,OAAO,GAAG,eAAe;EAC5D,IAAI,gBAAgB,oBAAoB,iBAAiB;EACzD,IAAI,EAAE,MAAM,aAAa,QAAQ,UAAU,aAAa,MAAM;EAC9D,IAAI;EACJ,IAAI,QAAQ,OAAO,aAAa,QAAQ,aAAa,KAAK,IAAI,WAAW,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Switch.mjs";
2
- import { SwitchFrame, SwitchThumb } from "./Switch.mjs";
3
- export * from "./createSwitch.mjs";
4
- export * from "./StyledContext.mjs";
5
- export * from "./Switch.mjs";
6
- export * from "./types.mjs";
7
1
  import { useSwitchNative } from "./useSwitchNative.mjs";
8
- const Switch = createSwitch({
9
- Frame: SwitchFrame,
10
- Thumb: SwitchThumb
11
- });
12
- export { Switch, useSwitchNative };
13
- //# sourceMappingURL=index.js.map
2
+
3
+ export * from "./StyledContext.mjs"
4
+
5
+ export * from "./Switch.mjs"
6
+
7
+ export * from "./types.mjs"
8
+
9
+ export { useSwitchNative };
@@ -1,13 +1,9 @@
1
- import { createSwitch } from "./createSwitch.mjs";
2
- import { SwitchFrame, SwitchThumb } from "./Switch.mjs";
3
- export * from "./createSwitch.mjs";
4
- export * from "./StyledContext.mjs";
5
- export * from "./Switch.mjs";
6
- export * from "./types.mjs";
7
1
  import { useSwitchNative } from "./useSwitchNative.mjs";
8
- const Switch = createSwitch({
9
- Frame: SwitchFrame,
10
- Thumb: SwitchThumb
11
- });
12
- export { Switch, useSwitchNative };
13
- //# sourceMappingURL=index.mjs.map
2
+
3
+ export * from "./StyledContext.mjs"
4
+
5
+ export * from "./Switch.mjs"
6
+
7
+ export * from "./types.mjs"
8
+
9
+ export { useSwitchNative };
@@ -1,13 +1,9 @@
1
- import { createSwitch } from "./createSwitch.native.js";
2
- import { SwitchFrame, SwitchThumb } from "./Switch.native.js";
3
- export * from "./createSwitch.native.js";
4
- export * from "./StyledContext.native.js";
5
- export * from "./Switch.native.js";
6
- export * from "./types.native.js";
7
1
  import { useSwitchNative } from "./useSwitchNative.native.js";
8
- var Switch = createSwitch({
9
- Frame: SwitchFrame,
10
- Thumb: SwitchThumb
11
- });
12
- export { Switch, useSwitchNative };
13
- //# sourceMappingURL=index.native.js.map
2
+
3
+ export * from "./StyledContext.native.js"
4
+
5
+ export * from "./Switch.native.js"
6
+
7
+ export * from "./types.native.js"
8
+
9
+ export { useSwitchNative };
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.mjs.map
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.native.js.map
@@ -1,5 +1,6 @@
1
1
  function useSwitchNative(_props) {
2
- return null;
2
+ return null;
3
3
  }
4
+
4
5
  export { useSwitchNative };
5
6
  //# sourceMappingURL=useSwitchNative.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["useSwitchNative","_props"],"sources":["../../src/useSwitchNative.tsx"],"sourcesContent":[null],"mappings":"AAKO,SAASA,gBAAgBC,MAAA,EAAsD;EACpF,OAAO;AACT","ignoreList":[]}
1
+ {"version":3,"file":"useSwitchNative.js","names":[],"sources":["esm/useSwitchNative.js"],"sourcesContent":["function useSwitchNative(_props) {\n return null;\n}\nexport {\n useSwitchNative\n};\n//# sourceMappingURL=useSwitchNative.js.map\n"],"mappings":";AAAA,SAAS,gBAAgB,QAAQ;CAC/B,OAAO;AACT"}
@@ -1,38 +1,37 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import { shouldRenderNativePlatform } from "@tamagui/core";
3
3
  import { registerFocusable } from "@tamagui/focusable";
4
4
  import * as React from "react";
5
- import { Switch as NativeSwitch } from "react-native";
5
+ import { Switch } from "react-native";
6
+
6
7
  function useSwitchNative(props) {
7
- var {
8
- id,
9
- disabled,
10
- native,
11
- nativeProps,
12
- checked,
13
- setChecked
14
- } = props;
15
- React.useEffect(function () {
16
- if (!id) return;
17
- if (disabled) return;
18
- return registerFocusable(id, {
19
- focusAndSelect: function () {
20
- setChecked(function (value) {
21
- return !value;
22
- });
23
- },
24
- focus: function () {}
25
- });
26
- }, [id, disabled, setChecked]);
27
- var renderNative = shouldRenderNativePlatform(native);
28
- if (renderNative === "android" || renderNative === "ios") {
29
- return /* @__PURE__ */_jsx(NativeSwitch, {
30
- value: checked,
31
- onValueChange: setChecked,
32
- ...nativeProps
33
- });
34
- }
35
- return null;
8
+ var { id, disabled, native, nativeProps, checked, setChecked } = props;
9
+ React.useEffect(function() {
10
+ if (!id) return;
11
+ if (disabled) return;
12
+ return registerFocusable(id, {
13
+ focusAndSelect: function() {
14
+ setChecked(function(value) {
15
+ return !value;
16
+ });
17
+ },
18
+ focus: function() {}
19
+ });
20
+ }, [
21
+ id,
22
+ disabled,
23
+ setChecked
24
+ ]);
25
+ var renderNative = shouldRenderNativePlatform(native);
26
+ if (renderNative === "android" || renderNative === "ios") {
27
+ return /* @__PURE__ */ jsx(Switch, {
28
+ value: checked,
29
+ onValueChange: setChecked,
30
+ ...nativeProps
31
+ });
32
+ }
33
+ return null;
36
34
  }
35
+
37
36
  export { useSwitchNative };
38
37
  //# sourceMappingURL=useSwitchNative.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["jsx","_jsx","shouldRenderNativePlatform","registerFocusable","React","Switch","NativeSwitch","useSwitchNative","props","id","disabled","native","nativeProps","checked","setChecked","useEffect","focusAndSelect","value","focus","renderNative","onValueChange"],"sources":["../../src/useSwitchNative.native.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAOC,IAAA,QAAY;AAC5B,SAASC,0BAAA,QAAkC;AAC3C,SAASC,iBAAA,QAAyB;AAClC,YAAYC,KAAA,MAAW;AACvB,SAASC,MAAA,IAAUC,YAAA,QAAoB;AAG5B,SAASC,gBAAgBC,KAAA,EAAO;EACvC,IAAI;IAAEC,EAAA;IAAIC,QAAA;IAAUC,MAAA;IAAQC,WAAA;IAAaC,OAAA;IAASC;EAAW,IAAIN,KAAA;EACjEJ,KAAA,CAAMW,SAAA,CAAU,YAAW;IACvB,IAAI,CAACN,EAAA,EAAI;IACT,IAAIC,QAAA,EAAU;IACd,OAAOP,iBAAA,CAAkBM,EAAA,EAAI;MACzBO,cAAA,EAAgB,SAAAA,CAAA,EAAW;QACvBF,UAAA,CAAW,UAASG,KAAA,EAAO;UACvB,OAAO,CAACA,KAAA;QACZ,CAAC;MACL;MACAC,KAAA,EAAO,SAAAA,CAAA,EAAW,CAAC;IACvB,CAAC;EACL,GAAG,CACCT,EAAA,EACAC,QAAA,EACAI,UAAA,CACH;EACD,IAAIK,YAAA,GAAejB,0BAAA,CAA2BS,MAAM;EACpD,IAAIQ,YAAA,KAAiB,aAAaA,YAAA,KAAiB,OAAO;IACtD,OAAqB,eAAAlB,IAAA,CAAKK,YAAA,EAAc;MACpCW,KAAA,EAAOJ,OAAA;MACPO,aAAA,EAAeN,UAAA;MACf,GAAGF;IACP,CAAC;EACL;EACA,OAAO;AACX","ignoreList":[]}
1
+ {"version":3,"file":"useSwitchNative.native.js","names":["NativeSwitch"],"sources":["esm/useSwitchNative.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { shouldRenderNativePlatform } from \"@tamagui/core\";\nimport { registerFocusable } from \"@tamagui/focusable\";\nimport * as React from \"react\";\nimport { Switch as NativeSwitch } from \"react-native\";\nfunction useSwitchNative(props) {\n var { id, disabled, native, nativeProps, checked, setChecked } = props;\n React.useEffect(function() {\n if (!id) return;\n if (disabled) return;\n return registerFocusable(id, {\n focusAndSelect: function() {\n setChecked(function(value) {\n return !value;\n });\n },\n focus: function() {\n }\n });\n }, [\n id,\n disabled,\n setChecked\n ]);\n var renderNative = shouldRenderNativePlatform(native);\n if (renderNative === \"android\" || renderNative === \"ios\") {\n return /* @__PURE__ */ _jsx(NativeSwitch, {\n value: checked,\n onValueChange: setChecked,\n ...nativeProps\n });\n }\n return null;\n}\nexport {\n useSwitchNative\n};\n//# sourceMappingURL=useSwitchNative.native.js.map\n"],"mappings":";;;;;;;AAKA,SAAS,gBAAgB,OAAO;CAC9B,IAAI,EAAE,IAAI,UAAU,QAAQ,aAAa,SAAS,eAAe;CACjE,MAAM,UAAU,WAAW;EACzB,IAAI,CAAC,IAAI;EACT,IAAI,UAAU;EACd,OAAO,kBAAkB,IAAI;GAC3B,gBAAgB,WAAW;IACzB,WAAW,SAAS,OAAO;KACzB,OAAO,CAAC;IACV,CAAC;GACH;GACA,OAAO,WAAW,CAClB;EACF,CAAC;CACH,GAAG;EACD;EACA;EACA;CACF,CAAC;CACD,IAAI,eAAe,2BAA2B,MAAM;CACpD,IAAI,iBAAiB,aAAa,iBAAiB,OAAO;EACxD,OAAuB,oBAAKA,QAAc;GACxC,OAAO;GACP,eAAe;GACf,GAAG;EACL,CAAC;CACH;CACA,OAAO;AACT"}
@@ -1,10 +1,11 @@
1
1
  import { createStyledContext } from "@tamagui/core";
2
+
2
3
  const SwitchStyledContext = createStyledContext({
3
- active: false,
4
- disabled: false,
5
- frameWidth: void 0,
6
- size: void 0,
7
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
4
+ active: false,
5
+ disabled: false,
6
+ frameWidth: void 0,
7
+ size: void 0
8
8
  });
9
+
9
10
  export { SwitchStyledContext };
10
11
  //# sourceMappingURL=StyledContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["createStyledContext","SwitchStyledContext","active","disabled","frameWidth","size","unstyled","process","env","TAMAGUI_HEADLESS"],"sources":["../../src/StyledContext.tsx"],"sourcesContent":[null],"mappings":"AACA,SAASA,mBAAA,QAA2B;AAE7B,MAAMC,mBAAA,GAAsBD,mBAAA,CAMhC;EACDE,MAAA,EAAQ;EACRC,QAAA,EAAU;EACVC,UAAA,EAAY;EACZC,IAAA,EAAM;EACNC,QAAA,EAAUC,OAAA,CAAQC,GAAA,CAAIC,gBAAA,KAAqB;AAC7C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"StyledContext.js","names":[],"sources":["jsx/StyledContext.js"],"sourcesContent":["import { createStyledContext } from \"@tamagui/core\";\nconst SwitchStyledContext = createStyledContext({\n active: false,\n disabled: false,\n frameWidth: void 0,\n size: void 0\n});\nexport {\n SwitchStyledContext\n};\n//# sourceMappingURL=StyledContext.js.map\n"],"mappings":";;;AACA,MAAM,sBAAsB,oBAAoB;CAC9C,QAAQ;CACR,UAAU;CACV,YAAY,KAAK;CACjB,MAAM,KAAK;AACb,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
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, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var StyledContext_exports = {};
24
+ __export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
25
+ module.exports = __toCommonJS(StyledContext_exports);
26
+ var import_core = require("@tamagui/core");
27
+ var SwitchStyledContext = (0, import_core.createStyledContext)({
28
+ active: false,
29
+ disabled: false,
30
+ frameWidth: void 0,
31
+ size: void 0
32
+ });
@@ -5,34 +5,30 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
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, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
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, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
- value: true
24
- }), mod);
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
23
  var StyledContext_exports = {};
26
- __export(StyledContext_exports, {
27
- SwitchStyledContext: () => SwitchStyledContext
28
- });
24
+ __export(StyledContext_exports, { SwitchStyledContext: () => SwitchStyledContext });
29
25
  module.exports = __toCommonJS(StyledContext_exports);
30
26
  var import_core = require("@tamagui/core");
31
27
  var SwitchStyledContext = (0, import_core.createStyledContext)({
32
- active: false,
33
- disabled: false,
34
- frameWidth: void 0,
35
- size: void 0,
36
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
28
+ active: false,
29
+ disabled: false,
30
+ frameWidth: void 0,
31
+ size: void 0
37
32
  });
33
+
38
34
  //# sourceMappingURL=StyledContext.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable"],"sources":["../../src/StyledContext.tsx"],"sourcesContent":[null],"mappings":"AACA,YAAS;;AAEF,IAAAA,SAAM,GAAAC,MAAA,CAAAC,cAAsB;AAMhC,IACDC,gBAAQ,GAAAF,MAAA,CAAAG,wBAAA;AAAA,IACRC,iBAAU,GAAAJ,MAAA,CAAAK,mBAAA;AAAA,IACVC,YAAY,GAAAN,MAAA,CAAAO,SAAA,CAAAC,cAAA;AAAA,IACZC,QAAM,GAAAA,CAAAC,MAAA,EAAAC,GAAA;EACN,SAAAC,IAAU,IAAAD,GAAQ,EACnBZ,SAAA,CAAAW,MAAA,EAAAE,IAAA;IAAAC,GAAA,EAAAF,GAAA,CAAAC,IAAA;IAAAE,UAAA;EAAA","ignoreList":[]}
1
+ {"version":3,"file":"StyledContext.native.js","names":[],"sources":["jsx/StyledContext.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\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 __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar StyledContext_exports = {};\n__export(StyledContext_exports, {\n SwitchStyledContext: () => SwitchStyledContext\n});\nmodule.exports = __toCommonJS(StyledContext_exports);\nvar import_core = require(\"@tamagui/core\");\nvar SwitchStyledContext = (0, import_core.createStyledContext)({\n active: false,\n disabled: false,\n frameWidth: void 0,\n size: void 0\n});\n//# sourceMappingURL=StyledContext.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,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,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,wBAAwB,CAAC;AAC7B,SAAS,uBAAuB,EAC9B,2BAA2B,oBAC7B,CAAC;AACD,OAAO,UAAU,aAAa,qBAAqB;AACnD,IAAI,cAAc,QAAQ,eAAe;AACzC,IAAI,uBAAuB,GAAG,YAAY,oBAAmB,CAAE;CAC7D,QAAQ;CACR,UAAU;CACV,YAAY,KAAK;CACjB,MAAM,KAAK;AACb,CAAC"}
@@ -1,74 +1,122 @@
1
- import { getVariableValue, styled } from "@tamagui/core";
2
- import { getSize } from "@tamagui/get-token";
3
- import { YStack } from "@tamagui/stacks";
4
- const SwitchThumb = styled(YStack, {
5
- name: "SwitchThumb",
6
- variants: {
7
- unstyled: {
8
- false: {
9
- size: "$true",
10
- backgroundColor: "$background",
11
- borderRadius: 1e3
12
- }
13
- },
14
- size: {
15
- "...size": val => {
16
- const size = getSwitchHeight(val);
17
- return {
18
- height: size,
19
- width: size
20
- };
21
- }
22
- }
23
- },
24
- defaultVariants: {
25
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
26
- }
27
- }, {
28
- accept: {
29
- activeStyle: "style"
30
- }
1
+ import { Theme, View, composeEventHandlers, createStyledHOC, getVariableValue, isWeb, styled, withStaticProperties } from "@tamagui/core";
2
+ import { useSwitch } from "@tamagui/switch-headless";
3
+ import { useControllableState } from "@tamagui/use-controllable-state";
4
+ import * as React from "react";
5
+ import { SwitchStyledContext } from "./StyledContext.mjs";
6
+ import { useSwitchNative } from "./useSwitchNative.mjs";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+
9
+ const SwitchThumbFrame = styled(View, {
10
+ displayName: "SwitchThumb",
11
+ context: SwitchStyledContext
31
12
  });
32
- const getSwitchHeight = val => Math.round(getVariableValue(getSize(val)) * 0.65);
33
- const getSwitchWidth = val => getSwitchHeight(val) * 2;
34
- const SwitchFrame = styled(YStack, {
35
- name: "Switch",
36
- render: "button",
37
- tabIndex: 0,
38
- variants: {
39
- unstyled: {
40
- false: {
41
- borderRadius: 1e3,
42
- backgroundColor: "$background",
43
- focusVisibleStyle: {
44
- outlineColor: "$outlineColor",
45
- outlineStyle: "solid",
46
- outlineWidth: 2
47
- }
48
- }
49
- },
50
- size: {
51
- "...size": (val, {
52
- props
53
- }) => {
54
- if (props["unstyled"]) return;
55
- const height = getSwitchHeight(val);
56
- const width = getSwitchWidth(val);
57
- return {
58
- height,
59
- minHeight: height,
60
- width
61
- };
62
- }
63
- }
64
- },
65
- defaultVariants: {
66
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
67
- }
68
- }, {
69
- accept: {
70
- activeStyle: "style"
71
- }
13
+ const SwitchFrame = styled(View, {
14
+ displayName: "Switch",
15
+ context: SwitchStyledContext,
16
+ render: "button",
17
+ tabIndex: 0
72
18
  });
73
- export { SwitchFrame, SwitchThumb };
19
+ function createSwitch(createProps) {
20
+ const Frame = createProps.Frame ?? SwitchFrame;
21
+ const Thumb = createProps.Thumb ?? SwitchThumbFrame;
22
+ Frame.staticConfig.context = SwitchStyledContext;
23
+ Thumb.staticConfig.context = SwitchStyledContext;
24
+ const SwitchThumbComponent = createStyledHOC(Thumb, function SwitchThumb2(props, forwardedRef) {
25
+ const { size: sizeProp, activeStyle, theme, ...thumbProps } = props;
26
+ const styledContext = SwitchStyledContext.useStyledContext();
27
+ const { size: sizeContext, active, disabled, frameWidth = 0 } = styledContext;
28
+ const size = sizeProp ?? sizeContext ?? true;
29
+ const initialChecked = React.useRef(active).current;
30
+ const initialWidth = getVariableValue(props.width, "size");
31
+ const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
32
+ const distance = frameWidth - thumbWidth;
33
+ const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
34
+ const thumb = /* @__PURE__ */ jsx(Thumb, {
35
+ ref: forwardedRef,
36
+ size,
37
+ alignSelf: initialChecked ? "flex-end" : "flex-start",
38
+ x,
39
+ onLayout: composeEventHandlers(props.onLayout, (event) => {
40
+ setThumbWidth(event.nativeEvent.layout.width);
41
+ }),
42
+ disabled,
43
+ ...thumbProps,
44
+ ...active && activeStyle
45
+ });
46
+ const themeName = theme ?? createProps.componentThemes?.thumb;
47
+ return themeName ? /* @__PURE__ */ jsx(Theme, {
48
+ name: themeName,
49
+ children: thumb
50
+ }) : thumb;
51
+ });
52
+ const SwitchComponent = createStyledHOC(Frame, function Switch2(_props, forwardedRef) {
53
+ const { native, nativeProps, checked: checkedProp, defaultChecked, onCheckedChange, activeStyle, activeTheme, theme, ...props } = _props;
54
+ const [checked, setChecked] = useControllableState({
55
+ prop: checkedProp,
56
+ defaultProp: defaultChecked || false,
57
+ onChange: onCheckedChange,
58
+ transition: true
59
+ });
60
+ const styledContext = React.useContext(SwitchStyledContext.context);
61
+ const [frameWidth, setFrameInnerWidth] = React.useState(0);
62
+ const { switchProps, bubbleInput, switchRef } = useSwitch(props, [checked, setChecked], forwardedRef);
63
+ const nativeSwitch = useSwitchNative({
64
+ id: props.id,
65
+ disabled: props.disabled,
66
+ native,
67
+ nativeProps,
68
+ checked,
69
+ setChecked
70
+ });
71
+ if (nativeSwitch) {
72
+ return nativeSwitch;
73
+ }
74
+ const disabled = props.disabled;
75
+ const size = styledContext.size ?? props.size ?? true;
76
+ const handleLayout = (event) => {
77
+ const next = event.nativeEvent.layout.width;
78
+ if (next !== frameWidth) {
79
+ setFrameInnerWidth(next);
80
+ }
81
+ };
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
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SwitchStyledContext.Provider, {
100
+ size,
101
+ active: checked,
102
+ disabled,
103
+ frameWidth,
104
+ children: frameTheme ? /* @__PURE__ */ jsx(Theme, {
105
+ name: frameTheme,
106
+ children: frame
107
+ }) : frame
108
+ }), bubbleInput] });
109
+ }, { disableTheme: true });
110
+ return withStaticProperties(SwitchComponent, {
111
+ Frame,
112
+ Thumb: SwitchThumbComponent
113
+ });
114
+ }
115
+ const Switch = createSwitch({
116
+ Frame: SwitchFrame,
117
+ Thumb: SwitchThumbFrame
118
+ });
119
+ const SwitchThumb = Switch.Thumb;
120
+
121
+ export { Switch, SwitchFrame, SwitchThumb, SwitchThumbFrame, createSwitch };
74
122
  //# sourceMappingURL=Switch.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["getVariableValue","styled","getSize","YStack","SwitchThumb","name","variants","unstyled","false","size","backgroundColor","borderRadius","val","getSwitchHeight","height","width","defaultVariants","process","env","TAMAGUI_HEADLESS","accept","activeStyle","Math","round","getSwitchWidth","SwitchFrame","render","tabIndex","focusVisibleStyle","outlineColor","outlineStyle","outlineWidth","...size","props","minHeight"],"sources":["../../src/Switch.tsx"],"sourcesContent":[null],"mappings":"AACA,SAASA,gBAAA,EAAkBC,MAAA,QAAc;AACzC,SAASC,OAAA,QAAe;AACxB,SAASC,MAAA,QAAc;AAEhB,MAAMC,WAAA,GAAcH,MAAA,CACzBE,MAAA,EACA;EACEE,IAAA,EAAM;EAENC,QAAA,EAAU;IACRC,QAAA,EAAU;MACRC,KAAA,EAAO;QACLC,I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AC7C;AACF,GACA;EACEC,MAAA,EAAQ;IACNC,WAAA,EAAa;EACf;AACF,CACF","ignoreList":[]}
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;GAC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