@tamagui/switch 2.7.7 → 3.0.0-beta.643.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 +19 -23
  2. package/dist/cjs/StyledContext.native.cjs +33 -0
  3. package/dist/cjs/StyledContext.native.js +19 -22
  4. package/dist/cjs/StyledContext.native.js.map +1 -1
  5. package/dist/cjs/Switch.cjs +140 -86
  6. package/dist/cjs/Switch.native.cjs +163 -0
  7. package/dist/cjs/Switch.native.js +147 -90
  8. package/dist/cjs/Switch.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +14 -25
  10. package/dist/cjs/index.native.cjs +31 -0
  11. package/dist/cjs/index.native.js +15 -25
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/types.cjs +10 -11
  14. package/dist/cjs/types.native.cjs +19 -0
  15. package/dist/cjs/types.native.js +10 -10
  16. package/dist/cjs/types.native.js.map +1 -1
  17. package/dist/cjs/useSwitchNative.cjs +16 -19
  18. package/dist/cjs/useSwitchNative.native.cjs +65 -0
  19. package/dist/cjs/useSwitchNative.native.js +44 -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 +33 -0
  41. package/dist/jsx/StyledContext.native.js +19 -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 +163 -0
  46. package/dist/jsx/Switch.native.js +147 -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 +31 -0
  51. package/dist/jsx/index.native.js +15 -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 +19 -0
  55. package/dist/jsx/types.native.js +10 -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 +65 -0
  60. package/dist/jsx/useSwitchNative.native.js +44 -54
  61. package/dist/jsx/useSwitchNative.native.js.map +1 -1
  62. package/package.json +7 -14
  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 +3 -5
  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 +3 -4
  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,194 +0,0 @@
1
- "use strict";
2
-
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
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, {
18
- get: () => from[key],
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
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);
36
- var createSwitch_exports = {};
37
- __export(createSwitch_exports, {
38
- createSwitch: () => createSwitch
39
- });
40
- module.exports = __toCommonJS(createSwitch_exports);
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");
49
- function createSwitch(createProps) {
50
- var {
51
- Frame = import_Switch.SwitchFrame,
52
- Thumb = import_Switch.SwitchThumb
53
- } = createProps;
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",
153
- unstyled,
154
- active: checked,
155
- disabled,
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
- }),
168
- unstyled,
169
- ...props,
170
- ...switchProps,
171
- disabled,
172
- ...(checked && {
173
- ...(!unstyled && !activeStyle && {
174
- backgroundColor: "$backgroundActive"
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
183
- })
184
- })
185
- }), bubbleInput]
186
- });
187
- }, {
188
- disableTheme: true
189
- });
190
- return (0, import_core.withStaticProperties)(SwitchComponent, {
191
- Thumb: SwitchThumbComponent
192
- });
193
- }
194
- //# sourceMappingURL=createSwitch.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","createSwitch_exports","__export","createSwitch","module","exports","import_jsx_runtime","require","import_core","import_switch_headless","import_use_controllable_state","React","__toESM","import_StyledContext","import_Switch","import_useSwitchNative","createProps","Frame","SwitchFrame","Thumb","SwitchThumb","process","env","NODE_ENV","staticConfig","context","SwitchStyledContext","console","warn","SwitchThumbComponent","styleable","SwitchThumb2","props","forwardedRef","size","sizeProp","unstyled","unstyledProp","activeStyle","thumbProps","styledContext","useStyledContext","unstyledContext","sizeContext","active","disabled","frameWidth","_ref","TAMAGUI_HEADLESS","_ref1","initialChecked","useRef","current","initialWidth","getVariableValue","width","thumbWidth","setThumbWidth","useState","distance","x","jsx","ref","alignSelf","onLayout","composeEventHandlers","e","next","nativeEvent","layout","SwitchComponent","_props","native","nativeProps","checked","checkedProp","defaultChecked","onCheckedChange","activeTheme","activeThemeProp","setChecked","useControllableState","prop","defaultProp","onChange","transition","useContext","setFrameInnerWidth","switchProps","bubbleInput","switchRef","useSwitch","nativeSwitch","useSwitchNative","id","handleLayout","_styledContext_unstyled","_styledContext_size","_styledContext_size1","_ref2","jsxs","Fragment","children","Provider","render","theme","isWeb","type","backgroundColor","View","flex","disableTheme","withStaticProperties"],"sources":["../../src/createSwitch.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;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;UACE/D,QAAA;UAAC,GAAAJ,KAAA;UAAA,GAAAwD,WAAA;UACC3C,QAAM;UACN,IAAA6B,OAAA;YACA,KAAAtC,QAAQ,KAAAE,WAAA;cACRsE,eAAA;YACA;YAEA,GAAAtE;UAAA;UAACgE,QAAA,qBAAAhG,kBAAA,CAAAuD,GAAA,EAAArD,WAAA,CAAAqG,IAAA;YAAA9C,SACM;YAAA+C,IACL;YAAO9C,QAEP,EAAO+B,YAAA;YAAmBO,QACrB,EAAAtE,KAAA,CAAAsE;UAA0B;QACb;MAC0B,IAC5Cb,WACA;IACI;EACC;IACLsB,YACC;EAAe;EAEI,WAAAvG,WACd,CAAAwG,oBAAiB,EAAA1C,eAAA;IAAAnD,KAAA,EAAAU;EACnB;AACC","ignoreList":[]}
@@ -1,150 +0,0 @@
1
- import { composeEventHandlers, getVariableValue, isWeb, View, 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 { SwitchFrame as DefaultSwitchFrame, SwitchThumb } from "./Switch.mjs";
7
- import { useSwitchNative } from "./useSwitchNative.mjs";
8
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
- function createSwitch(createProps) {
10
- const {
11
- Frame = DefaultSwitchFrame,
12
- Thumb = SwitchThumb
13
- } = createProps;
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",
109
- unstyled,
110
- active: checked,
111
- disabled,
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
- }),
123
- unstyled,
124
- ...props,
125
- ...switchProps,
126
- disabled,
127
- ...(checked && {
128
- ...(!unstyled && !activeStyle && {
129
- backgroundColor: "$backgroundActive"
130
- }),
131
- ...activeStyle
132
- }),
133
- children: /* @__PURE__ */jsx(View, {
134
- alignSelf: "stretch",
135
- flex: 1,
136
- onLayout: handleLayout,
137
- children: props.children
138
- })
139
- })
140
- }), bubbleInput]
141
- });
142
- }, {
143
- disableTheme: true
144
- });
145
- return withStaticProperties(SwitchComponent, {
146
- Thumb: SwitchThumbComponent
147
- });
148
- }
149
- export { createSwitch };
150
- //# sourceMappingURL=createSwitch.mjs.map
@@ -1 +0,0 @@
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,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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CACT;QAAA,CACF;MAAA,CACF,GAECL,WAAA;IAAA,CACH;EAEJ,GACA;IACEY,YAAA,EAAc;EAChB,CACF;EAEA,OAAOxF,oBAAA,CAAqB0D,eAAA,EAAiB;IAC3C3C,KAAA,EAAOQ;EACT,CAAC;AACH","ignoreList":[]}
@@ -1,155 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { composeEventHandlers, getVariableValue, isWeb, View, withStaticProperties } from "@tamagui/core";
3
- import { useSwitch } from "@tamagui/switch-headless";
4
- import { useControllableState } from "@tamagui/use-controllable-state";
5
- import * as React from "react";
6
- import { SwitchStyledContext } from "./StyledContext.native.js";
7
- import { SwitchFrame as DefaultSwitchFrame, SwitchThumb } from "./Switch.native.js";
8
- import { useSwitchNative } from "./useSwitchNative.native.js";
9
- function createSwitch(createProps) {
10
- var {
11
- Frame = DefaultSwitchFrame,
12
- Thumb = SwitchThumb
13
- } = createProps;
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
- var SwitchThumbComponent = Thumb.styleable(function SwitchThumb2(props, forwardedRef) {
22
- var {
23
- size: sizeProp,
24
- unstyled: unstyledProp,
25
- activeStyle,
26
- ...thumbProps
27
- } = props;
28
- var styledContext = SwitchStyledContext.useStyledContext();
29
- var {
30
- unstyled: unstyledContext,
31
- size: sizeContext,
32
- active,
33
- disabled,
34
- frameWidth = 0
35
- } = styledContext;
36
- var _ref;
37
- var unstyled = process.env.TAMAGUI_HEADLESS === "1" ? true : (_ref = unstyledProp !== null && unstyledProp !== void 0 ? unstyledProp : unstyledContext) !== null && _ref !== void 0 ? _ref : false;
38
- var _ref1;
39
- var size = (_ref1 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : sizeContext) !== null && _ref1 !== void 0 ? _ref1 : "$true";
40
- var initialChecked = React.useRef(active).current;
41
- var initialWidth = getVariableValue(props.width || size, "size");
42
- var [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
43
- var distance = frameWidth - thumbWidth;
44
- var x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
45
- return /* @__PURE__ */_jsx(Thumb, {
46
- ref: forwardedRef,
47
- unstyled,
48
- ...(unstyled === false && {
49
- size
50
- }),
51
- alignSelf: initialChecked ? "flex-end" : "flex-start",
52
- x,
53
- onLayout: composeEventHandlers(props.onLayout, function (e) {
54
- var next = e.nativeEvent.layout.width;
55
- setThumbWidth(next);
56
- }),
57
- disabled,
58
- ...thumbProps,
59
- ...(active && activeStyle)
60
- });
61
- });
62
- var SwitchComponent = Frame.styleable(function SwitchFrame(_props, forwardedRef) {
63
- var {
64
- native,
65
- nativeProps,
66
- checked: checkedProp,
67
- defaultChecked,
68
- onCheckedChange,
69
- activeStyle,
70
- unstyled: unstyledProp,
71
- activeTheme: activeThemeProp,
72
- ...props
73
- } = _props;
74
- var [checked, setChecked] = useControllableState({
75
- prop: checkedProp,
76
- defaultProp: defaultChecked || false,
77
- onChange: onCheckedChange,
78
- transition: true
79
- });
80
- var styledContext = React.useContext(SwitchStyledContext.context);
81
- var [frameWidth, setFrameInnerWidth] = React.useState(0);
82
- var {
83
- switchProps,
84
- bubbleInput,
85
- switchRef
86
- } = useSwitch(props, [checked, setChecked],
87
- // @ts-ignore TODO tamagui react 19 type error
88
- forwardedRef);
89
- var nativeSwitch = useSwitchNative({
90
- id: props.id,
91
- disabled: props.disabled,
92
- native,
93
- nativeProps,
94
- checked,
95
- setChecked
96
- });
97
- if (nativeSwitch) {
98
- return nativeSwitch;
99
- }
100
- var disabled = props.disabled;
101
- var handleLayout = function (e) {
102
- var next = e.nativeEvent.layout.width;
103
- if (next !== frameWidth) {
104
- setFrameInnerWidth(next);
105
- }
106
- };
107
- var _styledContext_unstyled, _ref;
108
- var unstyled = (_ref = (_styledContext_unstyled = styledContext.unstyled) !== null && _styledContext_unstyled !== void 0 ? _styledContext_unstyled : unstyledProp) !== null && _ref !== void 0 ? _ref : false;
109
- var _styledContext_size, _ref1, _styledContext_size1, _ref2;
110
- return /* @__PURE__ */_jsxs(_Fragment, {
111
- children: [/* @__PURE__ */_jsx(SwitchStyledContext.Provider, {
112
- size: (_ref1 = (_styledContext_size = styledContext.size) !== null && _styledContext_size !== void 0 ? _styledContext_size : props.size) !== null && _ref1 !== void 0 ? _ref1 : "$true",
113
- unstyled,
114
- active: checked,
115
- disabled,
116
- frameWidth,
117
- children: /* @__PURE__ */_jsx(Frame, {
118
- ref: switchRef,
119
- render: "button",
120
- // activeThemeProp should be a theme name string like "active", not a style object
121
- theme: activeThemeProp !== null && activeThemeProp !== void 0 ? activeThemeProp : null,
122
- ...(isWeb && {
123
- type: "button"
124
- }),
125
- ...(!unstyled && {
126
- size: (_ref2 = (_styledContext_size1 = styledContext.size) !== null && _styledContext_size1 !== void 0 ? _styledContext_size1 : props.size) !== null && _ref2 !== void 0 ? _ref2 : "$true"
127
- }),
128
- unstyled,
129
- ...props,
130
- ...switchProps,
131
- disabled,
132
- ...(checked && {
133
- ...(!unstyled && !activeStyle && {
134
- backgroundColor: "$backgroundActive"
135
- }),
136
- ...activeStyle
137
- }),
138
- children: /* @__PURE__ */_jsx(View, {
139
- alignSelf: "stretch",
140
- flex: 1,
141
- onLayout: handleLayout,
142
- children: props.children
143
- })
144
- })
145
- }), bubbleInput]
146
- });
147
- }, {
148
- disableTheme: true
149
- });
150
- return withStaticProperties(SwitchComponent, {
151
- Thumb: SwitchThumbComponent
152
- });
153
- }
154
- export { createSwitch };
155
- //# sourceMappingURL=createSwitch.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","composeEventHandlers","getVariableValue","isWeb","View","withStaticProperties","useSwitch","useControllableState","React","SwitchStyledContext","SwitchFrame","DefaultSwitchFrame","SwitchThumb","useSwitchNative","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","_ref","TAMAGUI_HEADLESS","_ref1","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","_styledContext_unstyled","_styledContext_size","_styledContext_size1","_ref2","children","Provider","render","theme","type","backgroundColor","flex","disableTheme"],"sources":["../../src/createSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAAAA,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,EAAAC,QAAA,IAAAC,SAAA;AAAA,SACEC,oBAAA,EAAAC,gBAAA,EAAAC,KAAA,EAAAC,IAAA,EAAAC,oBAAA;AAAA,SACAC,SAAA;AAAA,SACAC,oBAAA;AAAA,OACA,KAAAC,KAAA;AAAA,SACAC,mBAAA;AAAA,SACKC,WAAA,IAAAC,kBAAA,EAAAC,WAAA;AACP,SAASC,eAAA,QAAiB;AAC1B,SAASC,aAAAC,WAAA;EACT;IAAAC,KAAY,GAAAL,kBAAW;IAAAM,KAAA,GAAAL;EAAA,IAAAG,WAAA;EAEvB,IAAAG,OAAS,CAAAC,GAAA,CAAAC,QAAA,kBAA2B;IACpC,IAAAJ,KAAS,KAAAL,kBAAe,IAAAK,KAA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AAAA,eAAA;UACD,IAAArE,KAAA;YAEG2F,IAAA;UACF;UACF,KAAA9D,QAAA;YAEMF,IAAA,GAAA2D,KAAW,GAAM,CAAAD,oBAAA,GAAApD,aAAA,CAAAN,IAAA,cAAA0D,oBAAA,cAAAA,oBAAA,GAAA5D,KAAA,CAAAE,IAAA,cAAA2D,KAAA,cAAAA,KAAA;UAEjB;UACJzD,QAAM;UACF,GAAAJ,KAAA;UACF,GAAAoD,WAAA;UACFvC,QAAA;UACF,IAAA0B,OAAA;YAEM,KAAAnC,QAAW,KAAAE,WAAc;cAG7B6D,eAAA;YACE;YAAC,GAAA7D;UAAA;UACCwD,QAAM,iBAAc9F,IAAQ,CAAAQ,IAAM;YAClCqD,SAAA;YACAuC,IAAA,EAAQ;YACRtC,QAAA,EAAA2B,YAAA;YACAK,QAAA,EAAA9D,KAAA,CAAA8D;UAEA;QAAA;MAAC,IAAAT,WACC;IACO;EAEmB;IACKgB,YAC9B;EAAiB;EAC0B,OAAA5F,oBAC5C,CAAA0D,eAAA;IAAA9C,KAAA,EAAAQ;EACA;AACI;AACC,SACLX,YAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["createSwitch","SwitchFrame","SwitchThumb","useSwitchNative","Switch","Frame","Thumb"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,YAAA,QAAoB;AAC7B,SAASC,WAAA,EAAaC,WAAA,QAAmB;AAEzC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAASC,eAAA,QAAuB;AAazB,MAAMC,MAAA,GAASJ,YAAA,CAAa;EACjCK,KAAA,EAAOJ,WAAA;EACPK,KAAA,EAAOJ;AACT,CAAC","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["createSwitch","SwitchFrame","SwitchThumb","useSwitchNative","Switch","Frame","Thumb"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,YAAA,QAAoB;AAC7B,SAASC,WAAA,EAAaC,WAAA,QAAmB;AAEzC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAASC,eAAA,QAAuB;AAazB,MAAMC,MAAA,GAASJ,YAAA,CAAa;EACjCK,KAAA,EAAOJ,WAAA;EACPK,KAAA,EAAOJ;AACT,CAAC","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["createSwitch","SwitchFrame","SwitchThumb","useSwitchNative","Switch","Frame","Thumb"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,YAAA,QAAoB;AAC7B,SAASC,WAAA,EAAaC,WAAA,QAAmB;AAEzC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAASC,eAAA,QAAuB;AAazB,IAAAC,MAAM,GAAAJ,YAAS;EACpBK,KAAA,EAAOJ,WAAA;EACPK,KAAA,EAAOJ;AACT,CAAC","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}