@tamagui/switch 2.0.0-rc.4 → 2.0.0-rc.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/cjs/StyledContext.cjs +14 -12
  2. package/dist/cjs/StyledContext.native.js +20 -18
  3. package/dist/cjs/StyledContext.native.js.map +1 -1
  4. package/dist/cjs/Switch.cjs +76 -74
  5. package/dist/cjs/Switch.native.js +81 -80
  6. package/dist/cjs/Switch.native.js.map +1 -1
  7. package/dist/cjs/createSwitch.cjs +156 -144
  8. package/dist/cjs/createSwitch.native.js +161 -153
  9. package/dist/cjs/createSwitch.native.js.map +1 -1
  10. package/dist/cjs/index.cjs +15 -13
  11. package/dist/cjs/index.native.js +20 -18
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/types.cjs +7 -5
  14. package/dist/cjs/types.native.js +7 -5
  15. package/dist/cjs/types.native.js.map +1 -1
  16. package/dist/cjs/useSwitchNative.cjs +12 -10
  17. package/dist/cjs/useSwitchNative.native.js +40 -33
  18. package/dist/cjs/useSwitchNative.native.js.map +1 -1
  19. package/dist/esm/StyledContext.mjs +2 -2
  20. package/dist/esm/StyledContext.native.js +2 -2
  21. package/dist/esm/Switch.mjs +61 -61
  22. package/dist/esm/Switch.mjs.map +1 -1
  23. package/dist/esm/Switch.native.js +65 -66
  24. package/dist/esm/Switch.native.js.map +1 -1
  25. package/dist/esm/createSwitch.mjs +124 -114
  26. package/dist/esm/createSwitch.mjs.map +1 -1
  27. package/dist/esm/createSwitch.native.js +129 -123
  28. package/dist/esm/createSwitch.native.js.map +1 -1
  29. package/dist/esm/index.js +8 -11
  30. package/dist/esm/index.js.map +1 -6
  31. package/dist/esm/useSwitchNative.native.js +11 -6
  32. package/dist/esm/useSwitchNative.native.js.map +1 -1
  33. package/dist/jsx/StyledContext.mjs +2 -2
  34. package/dist/jsx/StyledContext.native.js +20 -18
  35. package/dist/jsx/StyledContext.native.js.map +1 -1
  36. package/dist/jsx/Switch.mjs +61 -61
  37. package/dist/jsx/Switch.mjs.map +1 -1
  38. package/dist/jsx/Switch.native.js +81 -80
  39. package/dist/jsx/Switch.native.js.map +1 -1
  40. package/dist/jsx/createSwitch.mjs +124 -114
  41. package/dist/jsx/createSwitch.mjs.map +1 -1
  42. package/dist/jsx/createSwitch.native.js +161 -153
  43. package/dist/jsx/createSwitch.native.js.map +1 -1
  44. package/dist/jsx/index.js +8 -11
  45. package/dist/jsx/index.js.map +1 -6
  46. package/dist/jsx/index.native.js +20 -18
  47. package/dist/jsx/index.native.js.map +1 -1
  48. package/dist/jsx/types.native.js +7 -5
  49. package/dist/jsx/useSwitchNative.native.js +40 -33
  50. package/dist/jsx/useSwitchNative.native.js.map +1 -1
  51. package/package.json +17 -20
  52. package/types/createSwitch.d.ts +4 -4
  53. package/types/index.d.ts +4 -4
  54. package/dist/cjs/StyledContext.js +0 -28
  55. package/dist/cjs/StyledContext.js.map +0 -6
  56. package/dist/cjs/Switch.js +0 -93
  57. package/dist/cjs/Switch.js.map +0 -6
  58. package/dist/cjs/createSwitch.js +0 -146
  59. package/dist/cjs/createSwitch.js.map +0 -6
  60. package/dist/cjs/index.js +0 -31
  61. package/dist/cjs/index.js.map +0 -6
  62. package/dist/cjs/types.js +0 -14
  63. package/dist/cjs/types.js.map +0 -6
  64. package/dist/cjs/useSwitchNative.js +0 -23
  65. package/dist/cjs/useSwitchNative.js.map +0 -6
  66. package/dist/esm/StyledContext.js +0 -12
  67. package/dist/esm/StyledContext.js.map +0 -6
  68. package/dist/esm/Switch.js +0 -79
  69. package/dist/esm/Switch.js.map +0 -6
  70. package/dist/esm/createSwitch.js +0 -135
  71. package/dist/esm/createSwitch.js.map +0 -6
  72. package/dist/esm/types.js +0 -1
  73. package/dist/esm/types.js.map +0 -6
  74. package/dist/esm/useSwitchNative.js +0 -7
  75. package/dist/esm/useSwitchNative.js.map +0 -6
  76. package/dist/jsx/StyledContext.js +0 -12
  77. package/dist/jsx/StyledContext.js.map +0 -6
  78. package/dist/jsx/Switch.js +0 -79
  79. package/dist/jsx/Switch.js.map +0 -6
  80. package/dist/jsx/createSwitch.js +0 -135
  81. package/dist/jsx/createSwitch.js.map +0 -6
  82. package/dist/jsx/types.js +0 -1
  83. package/dist/jsx/types.js.map +0 -6
  84. package/dist/jsx/useSwitchNative.js +0 -7
  85. package/dist/jsx/useSwitchNative.js.map +0 -6
@@ -11,127 +11,137 @@ function createSwitch(createProps) {
11
11
  Frame = DefaultSwitchFrame,
12
12
  Thumb = SwitchThumb
13
13
  } = createProps;
14
- process.env.NODE_ENV === "development" && (Frame !== DefaultSwitchFrame && Frame.staticConfig.context && Frame.staticConfig.context !== SwitchStyledContext || Thumb !== SwitchThumb && Thumb.staticConfig.context && Thumb.staticConfig.context !== SwitchStyledContext) && console.warn("Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden."), Frame.staticConfig.context = SwitchStyledContext, Thumb.staticConfig.context = SwitchStyledContext;
15
- const SwitchThumbComponent = Thumb.styleable(function (props, forwardedRef) {
16
- const {
17
- size: sizeProp,
18
- unstyled: unstyledProp,
19
- activeStyle,
20
- ...thumbProps
21
- } = props,
22
- styledContext = SwitchStyledContext.useStyledContext(),
23
- {
24
- unstyled: unstyledContext,
25
- size: sizeContext,
26
- active,
27
- disabled,
28
- frameWidth = 0
29
- } = styledContext,
30
- unstyled = process.env.TAMAGUI_HEADLESS === "1" ? !0 : unstyledProp ?? unstyledContext ?? !1,
31
- size = sizeProp ?? sizeContext ?? "$true",
32
- initialChecked = React.useRef(active).current,
33
- initialWidth = getVariableValue(props.width || size, "size"),
34
- [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth == "number" ? initialWidth : 0),
35
- distance = frameWidth - thumbWidth,
36
- x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
37
- return /* @__PURE__ */jsx(Thumb, {
38
- ref: forwardedRef,
14
+ if (process.env.NODE_ENV === "development") {
15
+ if (Frame !== DefaultSwitchFrame && Frame.staticConfig.context && Frame.staticConfig.context !== SwitchStyledContext || Thumb !== SwitchThumb && Thumb.staticConfig.context && Thumb.staticConfig.context !== SwitchStyledContext) {
16
+ console.warn(`Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden.`);
17
+ }
18
+ }
19
+ Frame.staticConfig.context = SwitchStyledContext;
20
+ Thumb.staticConfig.context = SwitchStyledContext;
21
+ const SwitchThumbComponent = Thumb.styleable(function SwitchThumb2(props, forwardedRef) {
22
+ const {
23
+ size: sizeProp,
24
+ unstyled: unstyledProp,
25
+ activeStyle,
26
+ ...thumbProps
27
+ } = props;
28
+ const styledContext = SwitchStyledContext.useStyledContext();
29
+ const {
30
+ unstyled: unstyledContext,
31
+ size: sizeContext,
32
+ active,
33
+ disabled,
34
+ frameWidth = 0
35
+ } = styledContext;
36
+ const unstyled = process.env.TAMAGUI_HEADLESS === "1" ? true : unstyledProp ?? unstyledContext ?? false;
37
+ const size = sizeProp ?? sizeContext ?? "$true";
38
+ const initialChecked = React.useRef(active).current;
39
+ const initialWidth = getVariableValue(props.width || size, "size");
40
+ const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
41
+ const distance = frameWidth - thumbWidth;
42
+ const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
43
+ return /* @__PURE__ */jsx(Thumb, {
44
+ ref: forwardedRef,
45
+ unstyled,
46
+ ...(unstyled === false && {
47
+ size
48
+ }),
49
+ alignSelf: initialChecked ? "flex-end" : "flex-start",
50
+ x,
51
+ onLayout: composeEventHandlers(props.onLayout, e => {
52
+ const next = e.nativeEvent.layout.width;
53
+ setThumbWidth(next);
54
+ }),
55
+ disabled,
56
+ ...thumbProps,
57
+ ...(active && activeStyle)
58
+ });
59
+ });
60
+ const SwitchComponent = Frame.styleable(function SwitchFrame(_props, forwardedRef) {
61
+ const {
62
+ native,
63
+ nativeProps,
64
+ checked: checkedProp,
65
+ defaultChecked,
66
+ onCheckedChange,
67
+ activeStyle,
68
+ unstyled: unstyledProp,
69
+ activeTheme: activeThemeProp,
70
+ ...props
71
+ } = _props;
72
+ const [checked, setChecked] = useControllableState({
73
+ prop: checkedProp,
74
+ defaultProp: defaultChecked || false,
75
+ onChange: onCheckedChange,
76
+ transition: true
77
+ });
78
+ const styledContext = React.useContext(SwitchStyledContext.context);
79
+ const [frameWidth, setFrameInnerWidth] = React.useState(0);
80
+ const {
81
+ switchProps,
82
+ bubbleInput,
83
+ switchRef
84
+ } = useSwitch(props, [checked, setChecked],
85
+ // @ts-ignore TODO tamagui react 19 type error
86
+ forwardedRef);
87
+ const nativeSwitch = useSwitchNative({
88
+ id: props.id,
89
+ disabled: props.disabled,
90
+ native,
91
+ nativeProps,
92
+ checked,
93
+ setChecked
94
+ });
95
+ if (nativeSwitch) {
96
+ return nativeSwitch;
97
+ }
98
+ const disabled = props.disabled;
99
+ const handleLayout = e => {
100
+ const next = e.nativeEvent.layout.width;
101
+ if (next !== frameWidth) {
102
+ setFrameInnerWidth(next);
103
+ }
104
+ };
105
+ const unstyled = styledContext.unstyled ?? unstyledProp ?? false;
106
+ return /* @__PURE__ */jsxs(Fragment, {
107
+ children: [/* @__PURE__ */jsx(SwitchStyledContext.Provider, {
108
+ size: styledContext.size ?? props.size ?? "$true",
39
109
  unstyled,
40
- ...(unstyled === !1 && {
41
- size
42
- }),
43
- alignSelf: initialChecked ? "flex-end" : "flex-start",
44
- x,
45
- onLayout: composeEventHandlers(props.onLayout, e => {
46
- const next = e.nativeEvent.layout.width;
47
- setThumbWidth(next);
48
- }),
110
+ active: checked,
49
111
  disabled,
50
- ...thumbProps,
51
- ...(active && activeStyle)
52
- });
53
- }),
54
- SwitchComponent = Frame.styleable(function (_props, forwardedRef) {
55
- const {
56
- native,
57
- nativeProps,
58
- checked: checkedProp,
59
- defaultChecked,
60
- onCheckedChange,
61
- activeStyle,
62
- unstyled: unstyledProp,
63
- activeTheme: activeThemeProp,
64
- ...props
65
- } = _props,
66
- [checked, setChecked] = useControllableState({
67
- prop: checkedProp,
68
- defaultProp: defaultChecked || !1,
69
- onChange: onCheckedChange,
70
- transition: !0
71
- }),
72
- styledContext = React.useContext(SwitchStyledContext.context),
73
- [frameWidth, setFrameInnerWidth] = React.useState(0),
74
- {
75
- switchProps,
76
- bubbleInput,
77
- switchRef
78
- } = useSwitch(props, [checked, setChecked],
79
- // @ts-ignore TODO tamagui react 19 type error
80
- forwardedRef),
81
- nativeSwitch = useSwitchNative({
82
- id: props.id,
83
- disabled: props.disabled,
84
- native,
85
- nativeProps,
86
- checked,
87
- setChecked
88
- });
89
- if (nativeSwitch) return nativeSwitch;
90
- const disabled = props.disabled,
91
- handleLayout = e => {
92
- const next = e.nativeEvent.layout.width;
93
- next !== frameWidth && setFrameInnerWidth(next);
94
- },
95
- unstyled = styledContext.unstyled ?? unstyledProp ?? !1;
96
- return /* @__PURE__ */jsxs(Fragment, {
97
- children: [/* @__PURE__ */jsx(SwitchStyledContext.Provider, {
98
- size: styledContext.size ?? props.size ?? "$true",
112
+ frameWidth,
113
+ children: /* @__PURE__ */jsx(Frame, {
114
+ ref: switchRef,
115
+ render: "button",
116
+ theme: activeThemeProp ?? null,
117
+ ...(isWeb && {
118
+ type: "button"
119
+ }),
120
+ ...(!unstyled && {
121
+ size: styledContext.size ?? props.size ?? "$true"
122
+ }),
99
123
  unstyled,
100
- active: checked,
124
+ ...props,
125
+ ...switchProps,
101
126
  disabled,
102
- frameWidth,
103
- children: /* @__PURE__ */jsx(Frame, {
104
- ref: switchRef,
105
- render: "button",
106
- theme: activeThemeProp ?? null,
107
- ...(isWeb && {
108
- type: "button"
109
- }),
110
- ...(!unstyled && {
111
- size: styledContext.size ?? props.size ?? "$true"
127
+ ...(checked && {
128
+ ...(!unstyled && !activeStyle && {
129
+ backgroundColor: "$backgroundActive"
112
130
  }),
113
- unstyled,
114
- ...props,
115
- ...switchProps,
116
- disabled,
117
- ...(checked && {
118
- ...(!unstyled && !activeStyle && {
119
- backgroundColor: "$backgroundActive"
120
- }),
121
- ...activeStyle
122
- }),
123
- children: /* @__PURE__ */jsx(View, {
124
- alignSelf: "stretch",
125
- flex: 1,
126
- onLayout: handleLayout,
127
- children: props.children
128
- })
131
+ ...activeStyle
132
+ }),
133
+ children: /* @__PURE__ */jsx(View, {
134
+ alignSelf: "stretch",
135
+ flex: 1,
136
+ onLayout: handleLayout,
137
+ children: props.children
129
138
  })
130
- }), bubbleInput]
131
- });
132
- }, {
133
- disableTheme: !0
139
+ })
140
+ }), bubbleInput]
134
141
  });
142
+ }, {
143
+ disableTheme: true
144
+ });
135
145
  return withStaticProperties(SwitchComponent, {
136
146
  Thumb: SwitchThumbComponent
137
147
  });
@@ -1 +1 @@
1
- {"version":3,"names":["composeEventHandlers","getVariableValue","isWeb","View","withStaticProperties","useSwitch","useControllableState","React","SwitchStyledContext","SwitchFrame","DefaultSwitchFrame","SwitchThumb","useSwitchNative","Fragment","jsx","jsxs","createSwitch","createProps","Frame","Thumb","process","env","NODE_ENV","staticConfig","context","console","warn","SwitchThumbComponent","styleable","props","forwardedRef","size","sizeProp","unstyled","unstyledProp","activeStyle","thumbProps","styledContext","useStyledContext","unstyledContext","sizeContext","active","disabled","frameWidth","TAMAGUI_HEADLESS","initialChecked","useRef","current","initialWidth","width","thumbWidth","setThumbWidth","useState","distance","x","ref","alignSelf","onLayout","e","next","nativeEvent","layout","SwitchComponent","_props","native","nativeProps","checked","checkedProp","defaultChecked","onCheckedChange","activeTheme","activeThemeProp","setChecked","prop","defaultProp","onChange","transition","useContext","setFrameInnerWidth","switchProps","bubbleInput","switchRef","nativeSwitch","id","handleLayout","children","Provider","render","theme","type","backgroundColor","flex","disableTheme"],"sources":["../../src/createSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SACEA,oBAAA,EACAC,gBAAA,EACAC,KAAA,EACAC,IAAA,EACAC,oBAAA,QACK;AACP,SAASC,SAAA,QAAiB;AAC1B,SAASC,oBAAA,QAA4B;AACrC,YAAYC,KA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;YACzB,IAAIrE,KAAA,IAAS;cAAEuF,IAAA,EAAM;YAAS;YAC9B,IAAI,CAACxD,QAAA,IAAY;cAChBF,IAAA,EAAMM,aAAA,CAAcN,IAAA,IAAQF,KAAA,CAAME,IAAA,IAAQ;YAC5C;YACAE,QAAA;YACC,GAAGJ,KAAA;YACH,GAAIkD,WAAA;YACLrC,QAAA;YACC,IAAIwB,OAAA,IAAW;cACd,IAAI,CAACjC,QAAA,IACH,CAACE,WAAA,IAAe;gBACduD,eAAA,EAAiB;cACnB;cACF,GAAGvD;YACL;YAEAkD,QAAA,iBAAAvE,GAAA,CAACX,IAAA;cAAKqD,SAAA,EAAU;cAAUmC,IAAA,EAAM;cAAGlC,QAAA,EAAU2B,YAAA;cAC1CC,QAAA,EAAAxD,KAAA,CAAMwD;YAAA,CACT;UAAA,CACF;QAAA,CACF,GAECL,WAAA;MAAA,CACH;IAEJ,GACA;MACEY,YAAA,EAAc;IAChB,CACF;EAEA,OAAOxF,oBAAA,CAAqB0D,eAAA,EAAiB;IAC3C3C,KAAA,EAAOQ;EACT,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["composeEventHandlers","getVariableValue","isWeb","View","withStaticProperties","useSwitch","useControllableState","React","SwitchStyledContext","SwitchFrame","DefaultSwitchFrame","SwitchThumb","useSwitchNative","Fragment","jsx","jsxs","createSwitch","createProps","Frame","Thumb","process","env","NODE_ENV","staticConfig","context","console","warn","SwitchThumbComponent","styleable","SwitchThumb2","props","forwardedRef","size","sizeProp","unstyled","unstyledProp","activeStyle","thumbProps","styledContext","useStyledContext","unstyledContext","sizeContext","active","disabled","frameWidth","TAMAGUI_HEADLESS","initialChecked","useRef","current","initialWidth","width","thumbWidth","setThumbWidth","useState","distance","x","ref","alignSelf","onLayout","e","next","nativeEvent","layout","SwitchComponent","_props","native","nativeProps","checked","checkedProp","defaultChecked","onCheckedChange","activeTheme","activeThemeProp","setChecked","prop","defaultProp","onChange","transition","useContext","setFrameInnerWidth","switchProps","bubbleInput","switchRef","nativeSwitch","id","handleLayout","children","Provider","render","theme","type","backgroundColor","flex","disableTheme"],"sources":["../../src/createSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SACEA,oBAAA,EACAC,gBAAA,EACAC,KAAA,EACAC,IAAA,EACAC,oBAAA,QACK;AACP,SAASC,SAAA,QAAiB;AAC1B,SAASC,oBAAA,QAA4B;AACrC,YAAYC,KAAA,MAAW;AAEvB,SAASC,mBAAA,QAA2B;AACpC,SAASC,WAAA,IAAeC,kBAAA,EAAoBC,WAAA,QAAmB;AAQ/D,SAASC,eAAA,QAAuB;AAwDxB,SA6EAC,QAAA,EA7EAC,GAAA,EA6EAC,IAAA,QA7EA;AApDD,SAASC,aAGdC,WAAA,EAAuC;EACvC,MAAM;IAAEC,KAAA,GAAQR,kBAAA;IAAoBS,KAAA,GAAQR;EAAY,IAAIM,WAAA;EAK5D,IAAIG,OAAA,CAAQC,GAAA,CAAIC,QAAA,KAAa,eAAe;IAC1C,IACGJ,KAAA,KAAUR,kBAAA,IACTQ,KAAA,CAAMK,YAAA,CAAaC,OAAA,IACnBN,KAAA,CAAMK,YAAA,CAAaC,OAAA,KAAYhB,mBAAA,IAChCW,KAAA,KAAUR,WAAA,IACTQ,KAAA,CAAMI,YAAA,CAAaC,OAAA,IACnBL,KAAA,CAAMI,YAAA,CAAaC,OAAA,KAAYhB,mBAAA,EACjC;MACAiB,OAAA,CAAQC,IAAA,CACN,2IACF;IACF;EACF;EAEAR,KAAA,CAAMK,YAAA,CAAaC,OAAA,GAAUhB,mBAAA;EAC7BW,KAAA,CAAMI,YAAA,CAAaC,OAAA,GAAUhB,mBAAA;EAE7B,MAAMmB,oBAAA,GAAuBR,KAAA,CAAMS,SAAA,CACjC,SAASC,aAAYC,KAAA,EAAOC,YAAA,EAAc;IACxC,MAAM;MAAEC,IAAA,EAAMC,QAAA;MAAUC,QAAA,EAAUC,YAAA;MAAcC,WAAA;MAAa,GAAGC;IAAW,IAAIP,KAAA;IAC/E,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MAAM1B,QAAA,GAAWI,aAAA,CAAcJ,QAAA,IAAYC,YAAA,IAAgB;IAE3D,OACE,eAAApB,IAAA,CAAAF,QAAA;MACEyE,QAAA,kBAAAxE,GAAA,CAACN,mBAAA,CAAoB+E,QAAA,EAApB;QACCvD,IAAA,EAAMM,aAAA,CAAcN,IAAA,IAAQF,KAAA,CAAME,IAAA,IAAQ;QAC1CE,QAAA;QACAQ,MAAA,EAAQyB,OAAA;QACRxB,QAAA;QACAC,UAAA;QAEA0C,QAAA,iBAAAxE,GAAA,CAACI,KAAA;UACCsC,GAAA,EAAK0B,SAAA;UACLM,MAAA,EAAO;UAEPC,KAAA,EAAOjB,eAAA,IAAmB;UACzB,IAAItE,KAAA,IAAS;YAAEwF,IAAA,EAAM;UAAS;UAC9B,IAAI,CAACxD,QAAA,IAAY;YAChBF,IAAA,EAAMM,aAAA,CAAcN,IAAA,IAAQF,KAAA,CAAME,IAAA,IAAQ;UAC5C;UACAE,QAAA;UACC,GAAGJ,KAAA;UACH,GAAIkD,WAAA;UACLrC,QAAA;UACC,IAAIwB,OAAA,IAAW;YACd,IAAI,CAACjC,QAAA,IACH,CAACE,WAAA,IAAe;cACduD,eAAA,EAAiB;YACnB;YACF,GAAGvD;UACL;UAEAkD,QAAA,iBAAAxE,GAAA,CAACX,IAAA;YAAKsD,SAAA,EAAU;YAAUmC,IAAA,EAAM;YAAGlC,QAAA,EAAU2B,YAAA;YAC1CC,QAAA,EAAAxD,KAAA,CAAMwD;UAAA,CACT;QAAA,CACF;MAAA,CACF,GAECL,WAAA;IAAA,CACH;EAEJ,GACA;IACEY,YAAA,EAAc;EAChB,CACF;EAEA,OAAOzF,oBAAA,CAAqB2D,eAAA,EAAiB;IAC3C5C,KAAA,EAAOQ;EACT,CAAC;AACH","ignoreList":[]}
@@ -4,181 +4,189 @@ var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf,
8
- __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: !0
13
- });
14
- },
15
- __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
18
  get: () => from[key],
18
19
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
20
  });
20
- return to;
21
- };
21
+ }
22
+ return to;
23
+ };
22
24
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: !0
30
- }) : target, mod)),
31
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: !0
33
- }), mod);
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
+ value: true
35
+ }), mod);
34
36
  var createSwitch_exports = {};
35
37
  __export(createSwitch_exports, {
36
38
  createSwitch: () => createSwitch
37
39
  });
38
40
  module.exports = __toCommonJS(createSwitch_exports);
39
- var import_jsx_runtime = require("react/jsx-runtime"),
40
- import_core = require("@tamagui/core"),
41
- import_switch_headless = require("@tamagui/switch-headless"),
42
- import_use_controllable_state = require("@tamagui/use-controllable-state"),
43
- React = __toESM(require("react"), 1),
44
- import_StyledContext = require("./StyledContext.native.js"),
45
- import_Switch = require("./Switch.native.js"),
46
- import_useSwitchNative = require("./useSwitchNative.native.js");
41
+ var import_jsx_runtime = require("react/jsx-runtime");
42
+ var import_core = require("@tamagui/core");
43
+ var import_switch_headless = require("@tamagui/switch-headless");
44
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
45
+ var React = __toESM(require("react"), 1);
46
+ var import_StyledContext = require("./StyledContext.native.js");
47
+ var import_Switch = require("./Switch.native.js");
48
+ var import_useSwitchNative = require("./useSwitchNative.native.js");
47
49
  function createSwitch(createProps) {
48
50
  var {
49
51
  Frame = import_Switch.SwitchFrame,
50
52
  Thumb = import_Switch.SwitchThumb
51
53
  } = createProps;
52
- process.env.NODE_ENV === "development" && (Frame !== import_Switch.SwitchFrame && Frame.staticConfig.context && Frame.staticConfig.context !== import_StyledContext.SwitchStyledContext || Thumb !== import_Switch.SwitchThumb && Thumb.staticConfig.context && Thumb.staticConfig.context !== import_StyledContext.SwitchStyledContext) && console.warn("Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden."), Frame.staticConfig.context = import_StyledContext.SwitchStyledContext, Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
53
- var SwitchThumbComponent = Thumb.styleable(function (props, forwardedRef) {
54
- var {
55
- size: sizeProp,
56
- unstyled: unstyledProp,
57
- activeStyle,
58
- ...thumbProps
59
- } = props,
60
- styledContext = import_StyledContext.SwitchStyledContext.useStyledContext(),
61
- {
62
- unstyled: unstyledContext,
63
- size: sizeContext,
64
- active,
65
- disabled,
66
- frameWidth = 0
67
- } = styledContext,
68
- _ref,
69
- unstyled = process.env.TAMAGUI_HEADLESS === "1" ? !0 : (_ref = unstyledProp ?? unstyledContext) !== null && _ref !== void 0 ? _ref : !1,
70
- _ref1,
71
- size = (_ref1 = sizeProp ?? sizeContext) !== null && _ref1 !== void 0 ? _ref1 : "$true",
72
- initialChecked = React.useRef(active).current,
73
- initialWidth = (0, import_core.getVariableValue)(props.width || size, "size"),
74
- [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth == "number" ? initialWidth : 0),
75
- distance = frameWidth - thumbWidth,
76
- x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
77
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Thumb, {
78
- ref: forwardedRef,
54
+ if (process.env.NODE_ENV === "development") {
55
+ if (Frame !== import_Switch.SwitchFrame && Frame.staticConfig.context && Frame.staticConfig.context !== import_StyledContext.SwitchStyledContext || Thumb !== import_Switch.SwitchThumb && Thumb.staticConfig.context && Thumb.staticConfig.context !== import_StyledContext.SwitchStyledContext) {
56
+ console.warn(`Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden.`);
57
+ }
58
+ }
59
+ Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
60
+ Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
61
+ var SwitchThumbComponent = Thumb.styleable(function SwitchThumb2(props, forwardedRef) {
62
+ var {
63
+ size: sizeProp,
64
+ unstyled: unstyledProp,
65
+ activeStyle,
66
+ ...thumbProps
67
+ } = props;
68
+ var styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
69
+ var {
70
+ unstyled: unstyledContext,
71
+ size: sizeContext,
72
+ active,
73
+ disabled,
74
+ frameWidth = 0
75
+ } = styledContext;
76
+ var _ref;
77
+ var unstyled = process.env.TAMAGUI_HEADLESS === "1" ? true : (_ref = unstyledProp !== null && unstyledProp !== void 0 ? unstyledProp : unstyledContext) !== null && _ref !== void 0 ? _ref : false;
78
+ var _ref1;
79
+ var size = (_ref1 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref1 !== void 0 ? _ref1 : "$true";
80
+ var initialChecked = React.useRef(active).current;
81
+ var initialWidth = (0, import_core.getVariableValue)(props.width || size, "size");
82
+ var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
83
+ var distance = frameWidth - thumbWidth;
84
+ var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
85
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Thumb, {
86
+ ref: forwardedRef,
87
+ unstyled,
88
+ ...(unstyled === false && {
89
+ size
90
+ }),
91
+ alignSelf: initialChecked ? "flex-end" : "flex-start",
92
+ x,
93
+ onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function (e) {
94
+ var next = e.nativeEvent.layout.width;
95
+ setThumbWidth(next);
96
+ }),
97
+ disabled,
98
+ ...thumbProps,
99
+ ...(active && activeStyle)
100
+ });
101
+ });
102
+ var SwitchComponent = Frame.styleable(function SwitchFrame(_props, forwardedRef) {
103
+ var {
104
+ native,
105
+ nativeProps,
106
+ checked: checkedProp,
107
+ defaultChecked,
108
+ onCheckedChange,
109
+ activeStyle,
110
+ unstyled: unstyledProp,
111
+ activeTheme: activeThemeProp,
112
+ ...props
113
+ } = _props;
114
+ var [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
115
+ prop: checkedProp,
116
+ defaultProp: defaultChecked || false,
117
+ onChange: onCheckedChange,
118
+ transition: true
119
+ });
120
+ var styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
121
+ var [frameWidth, setFrameInnerWidth] = React.useState(0);
122
+ var {
123
+ switchProps,
124
+ bubbleInput,
125
+ switchRef
126
+ } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
127
+ // @ts-ignore TODO tamagui react 19 type error
128
+ forwardedRef);
129
+ var nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
130
+ id: props.id,
131
+ disabled: props.disabled,
132
+ native,
133
+ nativeProps,
134
+ checked,
135
+ setChecked
136
+ });
137
+ if (nativeSwitch) {
138
+ return nativeSwitch;
139
+ }
140
+ var disabled = props.disabled;
141
+ var handleLayout = function (e) {
142
+ var next = e.nativeEvent.layout.width;
143
+ if (next !== frameWidth) {
144
+ setFrameInnerWidth(next);
145
+ }
146
+ };
147
+ var _styledContext_unstyled, _ref;
148
+ var unstyled = (_ref = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : unstyledProp) !== null && _ref !== void 0 ? _ref : false;
149
+ var _styledContext_size, _ref1, _styledContext_size1, _ref2;
150
+ return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
151
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
152
+ size: (_ref1 = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref1 !== void 0 ? _ref1 : "$true",
79
153
  unstyled,
80
- ...(unstyled === !1 && {
81
- size
82
- }),
83
- alignSelf: initialChecked ? "flex-end" : "flex-start",
84
- x,
85
- onLayout: (0, import_core.composeEventHandlers)(props.onLayout, function (e) {
86
- var next = e.nativeEvent.layout.width;
87
- setThumbWidth(next);
88
- }),
154
+ active: checked,
89
155
  disabled,
90
- ...thumbProps,
91
- ...(active && activeStyle)
92
- });
93
- }),
94
- SwitchComponent = Frame.styleable(function (_props, forwardedRef) {
95
- var {
96
- native,
97
- nativeProps,
98
- checked: checkedProp,
99
- defaultChecked,
100
- onCheckedChange,
101
- activeStyle,
102
- unstyled: unstyledProp,
103
- activeTheme: activeThemeProp,
104
- ...props
105
- } = _props,
106
- [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
107
- prop: checkedProp,
108
- defaultProp: defaultChecked || !1,
109
- onChange: onCheckedChange,
110
- transition: !0
111
- }),
112
- styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context),
113
- [frameWidth, setFrameInnerWidth] = React.useState(0),
114
- {
115
- switchProps,
116
- bubbleInput,
117
- switchRef
118
- } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
119
- // @ts-ignore TODO tamagui react 19 type error
120
- forwardedRef),
121
- nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
122
- id: props.id,
123
- disabled: props.disabled,
124
- native,
125
- nativeProps,
126
- checked,
127
- setChecked
128
- });
129
- if (nativeSwitch) return nativeSwitch;
130
- var disabled = props.disabled,
131
- handleLayout = function (e) {
132
- var next = e.nativeEvent.layout.width;
133
- next !== frameWidth && setFrameInnerWidth(next);
134
- },
135
- _styledContext_unstyled,
136
- _ref,
137
- unstyled = (_ref = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : unstyledProp) !== null && _ref !== void 0 ? _ref : !1,
138
- _styledContext_size,
139
- _ref1,
140
- _styledContext_size1,
141
- _ref2;
142
- return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
143
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
144
- size: (_ref1 = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref1 !== void 0 ? _ref1 : "$true",
156
+ frameWidth,
157
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
158
+ ref: switchRef,
159
+ render: "button",
160
+ // activeThemeProp should be a theme name string like "active", not a style object
161
+ theme: activeThemeProp !== null && activeThemeProp !== void 0 ? activeThemeProp : null,
162
+ ...(import_core.isWeb && {
163
+ type: "button"
164
+ }),
165
+ ...(!unstyled && {
166
+ size: (_ref2 = (_styledContext_size1 = styledContext.size) !== null && _styledContext_size1 !== void 0 ? _styledContext_size1 : props.size) !== null && _ref2 !== void 0 ? _ref2 : "$true"
167
+ }),
145
168
  unstyled,
146
- active: checked,
169
+ ...props,
170
+ ...switchProps,
147
171
  disabled,
148
- frameWidth,
149
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
150
- ref: switchRef,
151
- render: "button",
152
- // activeThemeProp should be a theme name string like "active", not a style object
153
- theme: activeThemeProp ?? null,
154
- ...(import_core.isWeb && {
155
- type: "button"
156
- }),
157
- ...(!unstyled && {
158
- size: (_ref2 = (_styledContext_size1 = styledContext.size) !== null && _styledContext_size1 !== void 0 ? _styledContext_size1 : props.size) !== null && _ref2 !== void 0 ? _ref2 : "$true"
172
+ ...(checked && {
173
+ ...(!unstyled && !activeStyle && {
174
+ backgroundColor: "$backgroundActive"
159
175
  }),
160
- unstyled,
161
- ...props,
162
- ...switchProps,
163
- disabled,
164
- ...(checked && {
165
- ...(!unstyled && !activeStyle && {
166
- backgroundColor: "$backgroundActive"
167
- }),
168
- ...activeStyle
169
- }),
170
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
171
- alignSelf: "stretch",
172
- flex: 1,
173
- onLayout: handleLayout,
174
- children: props.children
175
- })
176
+ ...activeStyle
177
+ }),
178
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
179
+ alignSelf: "stretch",
180
+ flex: 1,
181
+ onLayout: handleLayout,
182
+ children: props.children
176
183
  })
177
- }), bubbleInput]
178
- });
179
- }, {
180
- disableTheme: !0
184
+ })
185
+ }), bubbleInput]
181
186
  });
187
+ }, {
188
+ disableTheme: true
189
+ });
182
190
  return (0, import_core.withStaticProperties)(SwitchComponent, {
183
191
  Thumb: SwitchThumbComponent
184
192
  });