@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
@@ -2,172 +2,184 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
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: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
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: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var createSwitch_exports = {};
33
35
  __export(createSwitch_exports, {
34
36
  createSwitch: () => createSwitch
35
37
  });
36
38
  module.exports = __toCommonJS(createSwitch_exports);
37
- var import_core = require("@tamagui/core"),
38
- import_switch_headless = require("@tamagui/switch-headless"),
39
- import_use_controllable_state = require("@tamagui/use-controllable-state"),
40
- React = __toESM(require("react"), 1),
41
- import_StyledContext = require("./StyledContext.cjs"),
42
- import_Switch = require("./Switch.cjs"),
43
- import_useSwitchNative = require("./useSwitchNative.cjs"),
44
- import_jsx_runtime = require("react/jsx-runtime");
39
+ var import_core = require("@tamagui/core");
40
+ var import_switch_headless = require("@tamagui/switch-headless");
41
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
42
+ var React = __toESM(require("react"), 1);
43
+ var import_StyledContext = require("./StyledContext.cjs");
44
+ var import_Switch = require("./Switch.cjs");
45
+ var import_useSwitchNative = require("./useSwitchNative.cjs");
46
+ var import_jsx_runtime = require("react/jsx-runtime");
45
47
  function createSwitch(createProps) {
46
48
  const {
47
49
  Frame = import_Switch.SwitchFrame,
48
50
  Thumb = import_Switch.SwitchThumb
49
51
  } = createProps;
50
- 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;
51
- const SwitchThumbComponent = Thumb.styleable(function (props, forwardedRef) {
52
- const {
53
- size: sizeProp,
54
- unstyled: unstyledProp,
55
- activeStyle,
56
- ...thumbProps
57
- } = props,
58
- styledContext = import_StyledContext.SwitchStyledContext.useStyledContext(),
59
- {
60
- unstyled: unstyledContext,
61
- size: sizeContext,
62
- active,
63
- disabled,
64
- frameWidth = 0
65
- } = styledContext,
66
- unstyled = process.env.TAMAGUI_HEADLESS === "1" ? !0 : unstyledProp ?? unstyledContext ?? !1,
67
- size = sizeProp ?? sizeContext ?? "$true",
68
- initialChecked = React.useRef(active).current,
69
- initialWidth = (0, import_core.getVariableValue)(props.width || size, "size"),
70
- [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth == "number" ? initialWidth : 0),
71
- distance = frameWidth - thumbWidth,
72
- x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
73
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Thumb, {
74
- ref: forwardedRef,
52
+ if (process.env.NODE_ENV === "development") {
53
+ 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) {
54
+ console.warn(`Warning: createSwitch() needs to control context to pass checked state from Frame to Thumb, any custom context passed will be overridden.`);
55
+ }
56
+ }
57
+ Frame.staticConfig.context = import_StyledContext.SwitchStyledContext;
58
+ Thumb.staticConfig.context = import_StyledContext.SwitchStyledContext;
59
+ const SwitchThumbComponent = Thumb.styleable(function SwitchThumb2(props, forwardedRef) {
60
+ const {
61
+ size: sizeProp,
62
+ unstyled: unstyledProp,
63
+ activeStyle,
64
+ ...thumbProps
65
+ } = props;
66
+ const styledContext = import_StyledContext.SwitchStyledContext.useStyledContext();
67
+ const {
68
+ unstyled: unstyledContext,
69
+ size: sizeContext,
70
+ active,
71
+ disabled,
72
+ frameWidth = 0
73
+ } = styledContext;
74
+ const unstyled = process.env.TAMAGUI_HEADLESS === "1" ? true : unstyledProp ?? unstyledContext ?? false;
75
+ const size = sizeProp ?? sizeContext ?? "$true";
76
+ const initialChecked = React.useRef(active).current;
77
+ const initialWidth = (0, import_core.getVariableValue)(props.width || size, "size");
78
+ const [thumbWidth, setThumbWidth] = React.useState(typeof initialWidth === "number" ? initialWidth : 0);
79
+ const distance = frameWidth - thumbWidth;
80
+ const x = initialChecked ? active ? 0 : -distance : active ? distance : 0;
81
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Thumb, {
82
+ ref: forwardedRef,
83
+ unstyled,
84
+ ...(unstyled === false && {
85
+ size
86
+ }),
87
+ alignSelf: initialChecked ? "flex-end" : "flex-start",
88
+ x,
89
+ onLayout: (0, import_core.composeEventHandlers)(props.onLayout, e => {
90
+ const next = e.nativeEvent.layout.width;
91
+ setThumbWidth(next);
92
+ }),
93
+ disabled,
94
+ ...thumbProps,
95
+ ...(active && activeStyle)
96
+ });
97
+ });
98
+ const SwitchComponent = Frame.styleable(function SwitchFrame(_props, forwardedRef) {
99
+ const {
100
+ native,
101
+ nativeProps,
102
+ checked: checkedProp,
103
+ defaultChecked,
104
+ onCheckedChange,
105
+ activeStyle,
106
+ unstyled: unstyledProp,
107
+ activeTheme: activeThemeProp,
108
+ ...props
109
+ } = _props;
110
+ const [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
111
+ prop: checkedProp,
112
+ defaultProp: defaultChecked || false,
113
+ onChange: onCheckedChange,
114
+ transition: true
115
+ });
116
+ const styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context);
117
+ const [frameWidth, setFrameInnerWidth] = React.useState(0);
118
+ const {
119
+ switchProps,
120
+ bubbleInput,
121
+ switchRef
122
+ } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
123
+ // @ts-ignore TODO tamagui react 19 type error
124
+ forwardedRef);
125
+ const nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
126
+ id: props.id,
127
+ disabled: props.disabled,
128
+ native,
129
+ nativeProps,
130
+ checked,
131
+ setChecked
132
+ });
133
+ if (nativeSwitch) {
134
+ return nativeSwitch;
135
+ }
136
+ const disabled = props.disabled;
137
+ const handleLayout = e => {
138
+ const next = e.nativeEvent.layout.width;
139
+ if (next !== frameWidth) {
140
+ setFrameInnerWidth(next);
141
+ }
142
+ };
143
+ const unstyled = styledContext.unstyled ?? unstyledProp ?? false;
144
+ return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
145
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
146
+ size: styledContext.size ?? props.size ?? "$true",
75
147
  unstyled,
76
- ...(unstyled === !1 && {
77
- size
78
- }),
79
- alignSelf: initialChecked ? "flex-end" : "flex-start",
80
- x,
81
- onLayout: (0, import_core.composeEventHandlers)(props.onLayout, e => {
82
- const next = e.nativeEvent.layout.width;
83
- setThumbWidth(next);
84
- }),
148
+ active: checked,
85
149
  disabled,
86
- ...thumbProps,
87
- ...(active && activeStyle)
88
- });
89
- }),
90
- SwitchComponent = Frame.styleable(function (_props, forwardedRef) {
91
- const {
92
- native,
93
- nativeProps,
94
- checked: checkedProp,
95
- defaultChecked,
96
- onCheckedChange,
97
- activeStyle,
98
- unstyled: unstyledProp,
99
- activeTheme: activeThemeProp,
100
- ...props
101
- } = _props,
102
- [checked, setChecked] = (0, import_use_controllable_state.useControllableState)({
103
- prop: checkedProp,
104
- defaultProp: defaultChecked || !1,
105
- onChange: onCheckedChange,
106
- transition: !0
107
- }),
108
- styledContext = React.useContext(import_StyledContext.SwitchStyledContext.context),
109
- [frameWidth, setFrameInnerWidth] = React.useState(0),
110
- {
111
- switchProps,
112
- bubbleInput,
113
- switchRef
114
- } = (0, import_switch_headless.useSwitch)(props, [checked, setChecked],
115
- // @ts-ignore TODO tamagui react 19 type error
116
- forwardedRef),
117
- nativeSwitch = (0, import_useSwitchNative.useSwitchNative)({
118
- id: props.id,
119
- disabled: props.disabled,
120
- native,
121
- nativeProps,
122
- checked,
123
- setChecked
124
- });
125
- if (nativeSwitch) return nativeSwitch;
126
- const disabled = props.disabled,
127
- handleLayout = e => {
128
- const next = e.nativeEvent.layout.width;
129
- next !== frameWidth && setFrameInnerWidth(next);
130
- },
131
- unstyled = styledContext.unstyled ?? unstyledProp ?? !1;
132
- return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
133
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_StyledContext.SwitchStyledContext.Provider, {
134
- size: styledContext.size ?? props.size ?? "$true",
150
+ frameWidth,
151
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
152
+ ref: switchRef,
153
+ render: "button",
154
+ theme: activeThemeProp ?? null,
155
+ ...(import_core.isWeb && {
156
+ type: "button"
157
+ }),
158
+ ...(!unstyled && {
159
+ size: styledContext.size ?? props.size ?? "$true"
160
+ }),
135
161
  unstyled,
136
- active: checked,
162
+ ...props,
163
+ ...switchProps,
137
164
  disabled,
138
- frameWidth,
139
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
140
- ref: switchRef,
141
- render: "button",
142
- theme: activeThemeProp ?? null,
143
- ...(import_core.isWeb && {
144
- type: "button"
145
- }),
146
- ...(!unstyled && {
147
- size: styledContext.size ?? props.size ?? "$true"
165
+ ...(checked && {
166
+ ...(!unstyled && !activeStyle && {
167
+ backgroundColor: "$backgroundActive"
148
168
  }),
149
- unstyled,
150
- ...props,
151
- ...switchProps,
152
- disabled,
153
- ...(checked && {
154
- ...(!unstyled && !activeStyle && {
155
- backgroundColor: "$backgroundActive"
156
- }),
157
- ...activeStyle
158
- }),
159
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
160
- alignSelf: "stretch",
161
- flex: 1,
162
- onLayout: handleLayout,
163
- children: props.children
164
- })
169
+ ...activeStyle
170
+ }),
171
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
172
+ alignSelf: "stretch",
173
+ flex: 1,
174
+ onLayout: handleLayout,
175
+ children: props.children
165
176
  })
166
- }), bubbleInput]
167
- });
168
- }, {
169
- disableTheme: !0
177
+ })
178
+ }), bubbleInput]
170
179
  });
180
+ }, {
181
+ disableTheme: true
182
+ });
171
183
  return (0, import_core.withStaticProperties)(SwitchComponent, {
172
184
  Thumb: SwitchThumbComponent
173
185
  });