@tamagui/switch-headless 1.89.26 → 1.89.27-1708112217600

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": ";;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,wBAAd;",
3
+ "sources": ["../../src/Users/n8/tamagui/packages/switch-headless/src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;;AAAA;;wBAAc,wBAAd;",
5
5
  "names": []
6
6
  }
@@ -26,78 +26,182 @@ __export(useSwitch_exports, {
26
26
  useSwitch: () => useSwitch
27
27
  });
28
28
  module.exports = __toCommonJS(useSwitch_exports);
29
- var import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_helpers = require("@tamagui/helpers"), import_label = require("@tamagui/label"), import_use_previous = require("@tamagui/use-previous"), React = __toESM(require("react")), import_jsx_runtime = (
30
- // @ts-ignore
31
- require("react/jsx-runtime")
32
- );
29
+ var import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_helpers = require("@tamagui/helpers"), import_label = require("@tamagui/label"), import_use_previous = require("@tamagui/use-previous"), React = __toESM(require("react"));
30
+ function _array_like_to_array(arr, len) {
31
+ (len == null || len > arr.length) && (len = arr.length);
32
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
33
+ arr2[i] = arr[i];
34
+ return arr2;
35
+ }
36
+ function _array_with_holes(arr) {
37
+ if (Array.isArray(arr))
38
+ return arr;
39
+ }
40
+ function _define_property(obj, key, value) {
41
+ return key in obj ? Object.defineProperty(obj, key, {
42
+ value,
43
+ enumerable: !0,
44
+ configurable: !0,
45
+ writable: !0
46
+ }) : obj[key] = value, obj;
47
+ }
48
+ function _iterable_to_array_limit(arr, i) {
49
+ var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
50
+ if (_i != null) {
51
+ var _arr = [], _n = !0, _d = !1, _s, _e;
52
+ try {
53
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
54
+ ;
55
+ } catch (err) {
56
+ _d = !0, _e = err;
57
+ } finally {
58
+ try {
59
+ !_n && _i.return != null && _i.return();
60
+ } finally {
61
+ if (_d)
62
+ throw _e;
63
+ }
64
+ }
65
+ return _arr;
66
+ }
67
+ }
68
+ function _non_iterable_rest() {
69
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
70
+ }
71
+ function _object_spread(target) {
72
+ for (var i = 1; i < arguments.length; i++) {
73
+ var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
74
+ typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
75
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
76
+ }))), ownKeys2.forEach(function(key) {
77
+ _define_property(target, key, source[key]);
78
+ });
79
+ }
80
+ return target;
81
+ }
82
+ function ownKeys(object, enumerableOnly) {
83
+ var keys = Object.keys(object);
84
+ if (Object.getOwnPropertySymbols) {
85
+ var symbols = Object.getOwnPropertySymbols(object);
86
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
87
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
88
+ })), keys.push.apply(keys, symbols);
89
+ }
90
+ return keys;
91
+ }
92
+ function _object_spread_props(target, source) {
93
+ return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
94
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
95
+ }), target;
96
+ }
97
+ function _object_without_properties(source, excluded) {
98
+ if (source == null)
99
+ return {};
100
+ var target = _object_without_properties_loose(source, excluded), key, i;
101
+ if (Object.getOwnPropertySymbols) {
102
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
103
+ for (i = 0; i < sourceSymbolKeys.length; i++)
104
+ key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
105
+ }
106
+ return target;
107
+ }
108
+ function _object_without_properties_loose(source, excluded) {
109
+ if (source == null)
110
+ return {};
111
+ var target = {}, sourceKeys = Object.keys(source), key, i;
112
+ for (i = 0; i < sourceKeys.length; i++)
113
+ key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
114
+ return target;
115
+ }
116
+ function _sliced_to_array(arr, i) {
117
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
118
+ }
119
+ function _unsupported_iterable_to_array(o, minLen) {
120
+ if (o) {
121
+ if (typeof o == "string")
122
+ return _array_like_to_array(o, minLen);
123
+ var n = Object.prototype.toString.call(o).slice(8, -1);
124
+ if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
125
+ return Array.from(n);
126
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
127
+ return _array_like_to_array(o, minLen);
128
+ }
129
+ }
33
130
  function getState(checked) {
34
131
  return checked ? "checked" : "unchecked";
35
132
  }
36
- const BubbleInput = (props) => {
37
- const { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
38
- return React.useEffect(() => {
39
- const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
40
- inputProto,
41
- "checked"
42
- ).set;
133
+ var BubbleInput = function(props) {
134
+ var control = props.control, checked = props.checked, _props_bubbles = props.bubbles, bubbles = _props_bubbles === void 0 ? !0 : _props_bubbles, inputProps = _object_without_properties(props, [
135
+ "control",
136
+ "checked",
137
+ "bubbles"
138
+ ]), ref = React.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
139
+ return React.useEffect(function() {
140
+ var input = ref.current, inputProto = window.HTMLInputElement.prototype, descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"), setChecked = descriptor.set;
43
141
  if (prevChecked !== checked && setChecked) {
44
- const event = new Event("click", { bubbles });
142
+ var event = new Event("click", {
143
+ bubbles
144
+ });
45
145
  setChecked.call(input, checked), input.dispatchEvent(event);
46
146
  }
47
- }, [prevChecked, checked, bubbles]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
48
- "input",
49
- {
50
- type: "checkbox",
51
- "aria-hidden": !0,
52
- defaultChecked: checked,
53
- ...inputProps,
54
- tabIndex: -1,
55
- ref,
56
- style: {
57
- ...props.style,
58
- position: "absolute",
59
- pointerEvents: "none",
60
- opacity: 0,
61
- margin: 0
62
- }
63
- }
64
- );
147
+ }, [
148
+ prevChecked,
149
+ checked,
150
+ bubbles
151
+ ]), // @ts-ignore
152
+ /* @__PURE__ */ React.createElement("input", _object_spread_props(_object_spread({
153
+ type: "checkbox",
154
+ "aria-hidden": !0,
155
+ defaultChecked: checked
156
+ }, inputProps), {
157
+ tabIndex: -1,
158
+ ref,
159
+ style: _object_spread_props(_object_spread({}, props.style), {
160
+ position: "absolute",
161
+ pointerEvents: "none",
162
+ opacity: 0,
163
+ margin: 0
164
+ })
165
+ }));
65
166
  };
66
- function useSwitch(props, [checked, setChecked], ref) {
67
- const { disabled, name, value, required } = props, hasConsumerStoppedPropagationRef = React.useRef(!1), [button, setButton] = React.useState(null), composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton), isFormControl = import_constants.isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = (0, import_label.useLabelContext)(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
167
+ function useSwitch(props, param, ref) {
168
+ var _param = _sliced_to_array(param, 2), checked = _param[0], setChecked = _param[1], disabled = props.disabled, name = props.name, value = props.value, required = props.required, hasConsumerStoppedPropagationRef = React.useRef(!1), _React_useState = _sliced_to_array(React.useState(null), 2), button = _React_useState[0], setButton = _React_useState[1], composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton), isFormControl = import_constants.isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = (0, import_label.useLabelContext)(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
68
169
  return {
69
- switchProps: {
170
+ switchProps: _object_spread_props(_object_spread({
70
171
  role: "switch",
71
- "aria-checked": checked,
72
- ...import_constants.isWeb ? {
73
- tabIndex: disabled ? void 0 : 0,
74
- "data-state": getState(checked),
75
- "data-disabled": disabled ? "" : void 0,
76
- disabled
77
- } : {},
78
- ...props,
172
+ "aria-checked": checked
173
+ }, import_constants.isWeb ? {
174
+ tabIndex: disabled ? void 0 : 0,
175
+ "data-state": getState(checked),
176
+ "data-disabled": disabled ? "" : void 0,
177
+ disabled
178
+ } : {}, props), {
79
179
  "aria-labelledby": ariaLabelledBy,
80
- onPress: (0, import_helpers.composeEventHandlers)(props.onPress, (event) => {
81
- setChecked((prevChecked) => !prevChecked), import_constants.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
180
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress, function(event) {
181
+ setChecked(function(prevChecked) {
182
+ return !prevChecked;
183
+ }), import_constants.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
82
184
  })
83
- },
185
+ }),
84
186
  switchRef: composedRefs,
85
187
  /**
86
- * insert as a sibling of your switch (should not be inside the switch)
87
- */
88
- bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
89
- BubbleInput,
90
- {
91
- control: button,
92
- bubbles: !hasConsumerStoppedPropagationRef.current,
93
- name,
94
- value,
95
- checked,
96
- required,
97
- disabled,
98
- style: { transform: "translateX(-100%)" }
188
+ * insert as a sibling of your switch (should not be inside the switch)
189
+ */
190
+ bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ React.createElement(BubbleInput, {
191
+ control: button,
192
+ bubbles: !hasConsumerStoppedPropagationRef.current,
193
+ name,
194
+ value,
195
+ checked,
196
+ required,
197
+ disabled,
198
+ // We transform because the input is absolutely positioned but we have
199
+ // rendered it **after** the button. This pulls it back to sit on top
200
+ // of the button.
201
+ style: {
202
+ transform: "translateX(-100%)"
99
203
  }
100
- ) : null
204
+ }) : null
101
205
  };
102
206
  }
103
207
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/useSwitch.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC,kCAChC,mBAAsB,+BACtB,iBAAqC,6BACrC,eAAgC,2BAChC,sBAA4B,kCAC5B,QAAuB,2BAuDnB;AAAA;AAAA;AAAA;AApCJ,SAAS,SAAS,SAAsB;AACtC,SAAO,UAAU,YAAY;AAC/B;AAWA,MAAM,cAAc,CAAC,UAA4B;AAC/C,QAAM,EAAE,SAAS,SAAS,UAAU,IAAM,GAAG,WAAW,IAAI,OACtD,MAAM,MAAM,OAAyB,IAAI,GACzC,kBAAc,iCAAY,OAAO;AAGvC,eAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI,SACZ,aAAa,OAAO,iBAAiB,WAKrC,aAJa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF,EAC8B;AAC9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC5C,iBAAW,KAAK,OAAO,OAAO,GAC9B,MAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC,GAIhC;AAAA,IAAC;AAAA;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AACqC,iCAAiC5B;MAC3CyB;MACAC;MACAvC;MACAwC;MACAH;;;;MAIAN,OAAO;QAAEiC,WAAW;MAAoB;SAExC;EACR;AACF;",
5
+ "names": ["getState", "checked", "BubbleInput", "props", "control", "bubbles", "inputProps", "ref", "React", "useRef", "prevChecked", "usePrevious", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "useState", "button", "setButton", "composedRefs", "useComposedRefs", "isFormControl", "isWeb", "Boolean", "closest", "labelId", "useLabelContext", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "composeEventHandlers", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts"],
3
+ "sources": ["../../src/Users/n8/tamagui/packages/switch-headless/src/index.ts"],
4
4
  "mappings": "AAAA,cAAc;",
5
5
  "names": []
6
6
  }
@@ -4,76 +4,181 @@ import { composeEventHandlers } from "@tamagui/helpers";
4
4
  import { useLabelContext } from "@tamagui/label";
5
5
  import { usePrevious } from "@tamagui/use-previous";
6
6
  import * as React from "react";
7
- import { jsx } from "react/jsx-runtime";
7
+ function _array_like_to_array(arr, len) {
8
+ (len == null || len > arr.length) && (len = arr.length);
9
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
10
+ arr2[i] = arr[i];
11
+ return arr2;
12
+ }
13
+ function _array_with_holes(arr) {
14
+ if (Array.isArray(arr))
15
+ return arr;
16
+ }
17
+ function _define_property(obj, key, value) {
18
+ return key in obj ? Object.defineProperty(obj, key, {
19
+ value,
20
+ enumerable: !0,
21
+ configurable: !0,
22
+ writable: !0
23
+ }) : obj[key] = value, obj;
24
+ }
25
+ function _iterable_to_array_limit(arr, i) {
26
+ var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
27
+ if (_i != null) {
28
+ var _arr = [], _n = !0, _d = !1, _s, _e;
29
+ try {
30
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
31
+ ;
32
+ } catch (err) {
33
+ _d = !0, _e = err;
34
+ } finally {
35
+ try {
36
+ !_n && _i.return != null && _i.return();
37
+ } finally {
38
+ if (_d)
39
+ throw _e;
40
+ }
41
+ }
42
+ return _arr;
43
+ }
44
+ }
45
+ function _non_iterable_rest() {
46
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
47
+ }
48
+ function _object_spread(target) {
49
+ for (var i = 1; i < arguments.length; i++) {
50
+ var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
51
+ typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
52
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
53
+ }))), ownKeys2.forEach(function(key) {
54
+ _define_property(target, key, source[key]);
55
+ });
56
+ }
57
+ return target;
58
+ }
59
+ function ownKeys(object, enumerableOnly) {
60
+ var keys = Object.keys(object);
61
+ if (Object.getOwnPropertySymbols) {
62
+ var symbols = Object.getOwnPropertySymbols(object);
63
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
+ })), keys.push.apply(keys, symbols);
66
+ }
67
+ return keys;
68
+ }
69
+ function _object_spread_props(target, source) {
70
+ return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
71
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
72
+ }), target;
73
+ }
74
+ function _object_without_properties(source, excluded) {
75
+ if (source == null)
76
+ return {};
77
+ var target = _object_without_properties_loose(source, excluded), key, i;
78
+ if (Object.getOwnPropertySymbols) {
79
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
80
+ for (i = 0; i < sourceSymbolKeys.length; i++)
81
+ key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
82
+ }
83
+ return target;
84
+ }
85
+ function _object_without_properties_loose(source, excluded) {
86
+ if (source == null)
87
+ return {};
88
+ var target = {}, sourceKeys = Object.keys(source), key, i;
89
+ for (i = 0; i < sourceKeys.length; i++)
90
+ key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
91
+ return target;
92
+ }
93
+ function _sliced_to_array(arr, i) {
94
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
95
+ }
96
+ function _unsupported_iterable_to_array(o, minLen) {
97
+ if (o) {
98
+ if (typeof o == "string")
99
+ return _array_like_to_array(o, minLen);
100
+ var n = Object.prototype.toString.call(o).slice(8, -1);
101
+ if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
102
+ return Array.from(n);
103
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
104
+ return _array_like_to_array(o, minLen);
105
+ }
106
+ }
8
107
  function getState(checked) {
9
108
  return checked ? "checked" : "unchecked";
10
109
  }
11
- const BubbleInput = (props) => {
12
- const { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = usePrevious(checked);
13
- return React.useEffect(() => {
14
- const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
15
- inputProto,
16
- "checked"
17
- ).set;
110
+ var BubbleInput = function(props) {
111
+ var control = props.control, checked = props.checked, _props_bubbles = props.bubbles, bubbles = _props_bubbles === void 0 ? !0 : _props_bubbles, inputProps = _object_without_properties(props, [
112
+ "control",
113
+ "checked",
114
+ "bubbles"
115
+ ]), ref = React.useRef(null), prevChecked = usePrevious(checked);
116
+ return React.useEffect(function() {
117
+ var input = ref.current, inputProto = window.HTMLInputElement.prototype, descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"), setChecked = descriptor.set;
18
118
  if (prevChecked !== checked && setChecked) {
19
- const event = new Event("click", { bubbles });
119
+ var event = new Event("click", {
120
+ bubbles
121
+ });
20
122
  setChecked.call(input, checked), input.dispatchEvent(event);
21
123
  }
22
- }, [prevChecked, checked, bubbles]), // @ts-ignore
23
- /* @__PURE__ */ jsx(
24
- "input",
25
- {
26
- type: "checkbox",
27
- "aria-hidden": !0,
28
- defaultChecked: checked,
29
- ...inputProps,
30
- tabIndex: -1,
31
- ref,
32
- style: {
33
- ...props.style,
34
- position: "absolute",
35
- pointerEvents: "none",
36
- opacity: 0,
37
- margin: 0
38
- }
39
- }
40
- );
124
+ }, [
125
+ prevChecked,
126
+ checked,
127
+ bubbles
128
+ ]), // @ts-ignore
129
+ /* @__PURE__ */ React.createElement("input", _object_spread_props(_object_spread({
130
+ type: "checkbox",
131
+ "aria-hidden": !0,
132
+ defaultChecked: checked
133
+ }, inputProps), {
134
+ tabIndex: -1,
135
+ ref,
136
+ style: _object_spread_props(_object_spread({}, props.style), {
137
+ position: "absolute",
138
+ pointerEvents: "none",
139
+ opacity: 0,
140
+ margin: 0
141
+ })
142
+ }));
41
143
  };
42
- function useSwitch(props, [checked, setChecked], ref) {
43
- const { disabled, name, value, required } = props, hasConsumerStoppedPropagationRef = React.useRef(!1), [button, setButton] = React.useState(null), composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
144
+ function useSwitch(props, param, ref) {
145
+ var _param = _sliced_to_array(param, 2), checked = _param[0], setChecked = _param[1], disabled = props.disabled, name = props.name, value = props.value, required = props.required, hasConsumerStoppedPropagationRef = React.useRef(!1), _React_useState = _sliced_to_array(React.useState(null), 2), button = _React_useState[0], setButton = _React_useState[1], composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
44
146
  return {
45
- switchProps: {
147
+ switchProps: _object_spread_props(_object_spread({
46
148
  role: "switch",
47
- "aria-checked": checked,
48
- ...isWeb ? {
49
- tabIndex: disabled ? void 0 : 0,
50
- "data-state": getState(checked),
51
- "data-disabled": disabled ? "" : void 0,
52
- disabled
53
- } : {},
54
- ...props,
149
+ "aria-checked": checked
150
+ }, isWeb ? {
151
+ tabIndex: disabled ? void 0 : 0,
152
+ "data-state": getState(checked),
153
+ "data-disabled": disabled ? "" : void 0,
154
+ disabled
155
+ } : {}, props), {
55
156
  "aria-labelledby": ariaLabelledBy,
56
- onPress: composeEventHandlers(props.onPress, (event) => {
57
- setChecked((prevChecked) => !prevChecked), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
157
+ onPress: composeEventHandlers(props.onPress, function(event) {
158
+ setChecked(function(prevChecked) {
159
+ return !prevChecked;
160
+ }), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
58
161
  })
59
- },
162
+ }),
60
163
  switchRef: composedRefs,
61
164
  /**
62
- * insert as a sibling of your switch (should not be inside the switch)
63
- */
64
- bubbleInput: isWeb && isFormControl ? /* @__PURE__ */ jsx(
65
- BubbleInput,
66
- {
67
- control: button,
68
- bubbles: !hasConsumerStoppedPropagationRef.current,
69
- name,
70
- value,
71
- checked,
72
- required,
73
- disabled,
74
- style: { transform: "translateX(-100%)" }
165
+ * insert as a sibling of your switch (should not be inside the switch)
166
+ */
167
+ bubbleInput: isWeb && isFormControl ? /* @__PURE__ */ React.createElement(BubbleInput, {
168
+ control: button,
169
+ bubbles: !hasConsumerStoppedPropagationRef.current,
170
+ name,
171
+ value,
172
+ checked,
173
+ required,
174
+ disabled,
175
+ // We transform because the input is absolutely positioned but we have
176
+ // rendered it **after** the button. This pulls it back to sit on top
177
+ // of the button.
178
+ style: {
179
+ transform: "translateX(-100%)"
75
180
  }
76
- ) : null
181
+ }) : null
77
182
  };
78
183
  }
79
184
  export {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/useSwitch.tsx"],
4
- "mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAuDnB;AApCJ,SAAS,SAAS,SAAsB;AACtC,SAAO,UAAU,YAAY;AAC/B;AAWA,MAAM,cAAc,CAAC,UAA4B;AAC/C,QAAM,EAAE,SAAS,SAAS,UAAU,IAAM,GAAG,WAAW,IAAI,OACtD,MAAM,MAAM,OAAyB,IAAI,GACzC,cAAc,YAAY,OAAO;AAGvC,eAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI,SACZ,aAAa,OAAO,iBAAiB,WAKrC,aAJa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF,EAC8B;AAC9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC5C,iBAAW,KAAK,OAAO,OAAO,GAC9B,MAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC;AAAA,EAIhC;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,eAAW;AAAA,MACX,gBAAgB;AAAA,MACf,GAAG;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA,OAAO;AA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eb", "composeEventHandlers", "useLabelContext", "usePrevious", "React", "getState", "checked", "BubbleInput", "props", "control", "bubbles", "inputProps", "ref", "useRef", "prevChecked", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "useState", "button", "setButton", "composedRefs", "isFormControl", "Boolean", "closest", "labelId", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts"],
3
+ "sources": ["../../src/Users/n8/tamagui/packages/switch-headless/src/index.ts"],
4
4
  "mappings": "AAAA,cAAc;",
5
5
  "names": []
6
6
  }
@@ -4,76 +4,181 @@ import { composeEventHandlers } from "@tamagui/helpers";
4
4
  import { useLabelContext } from "@tamagui/label";
5
5
  import { usePrevious } from "@tamagui/use-previous";
6
6
  import * as React from "react";
7
- import { jsx } from "react/jsx-runtime";
7
+ function _array_like_to_array(arr, len) {
8
+ (len == null || len > arr.length) && (len = arr.length);
9
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
10
+ arr2[i] = arr[i];
11
+ return arr2;
12
+ }
13
+ function _array_with_holes(arr) {
14
+ if (Array.isArray(arr))
15
+ return arr;
16
+ }
17
+ function _define_property(obj, key, value) {
18
+ return key in obj ? Object.defineProperty(obj, key, {
19
+ value,
20
+ enumerable: !0,
21
+ configurable: !0,
22
+ writable: !0
23
+ }) : obj[key] = value, obj;
24
+ }
25
+ function _iterable_to_array_limit(arr, i) {
26
+ var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
27
+ if (_i != null) {
28
+ var _arr = [], _n = !0, _d = !1, _s, _e;
29
+ try {
30
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
31
+ ;
32
+ } catch (err) {
33
+ _d = !0, _e = err;
34
+ } finally {
35
+ try {
36
+ !_n && _i.return != null && _i.return();
37
+ } finally {
38
+ if (_d)
39
+ throw _e;
40
+ }
41
+ }
42
+ return _arr;
43
+ }
44
+ }
45
+ function _non_iterable_rest() {
46
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
47
+ }
48
+ function _object_spread(target) {
49
+ for (var i = 1; i < arguments.length; i++) {
50
+ var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
51
+ typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
52
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
53
+ }))), ownKeys2.forEach(function(key) {
54
+ _define_property(target, key, source[key]);
55
+ });
56
+ }
57
+ return target;
58
+ }
59
+ function ownKeys(object, enumerableOnly) {
60
+ var keys = Object.keys(object);
61
+ if (Object.getOwnPropertySymbols) {
62
+ var symbols = Object.getOwnPropertySymbols(object);
63
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
+ })), keys.push.apply(keys, symbols);
66
+ }
67
+ return keys;
68
+ }
69
+ function _object_spread_props(target, source) {
70
+ return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
71
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
72
+ }), target;
73
+ }
74
+ function _object_without_properties(source, excluded) {
75
+ if (source == null)
76
+ return {};
77
+ var target = _object_without_properties_loose(source, excluded), key, i;
78
+ if (Object.getOwnPropertySymbols) {
79
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
80
+ for (i = 0; i < sourceSymbolKeys.length; i++)
81
+ key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
82
+ }
83
+ return target;
84
+ }
85
+ function _object_without_properties_loose(source, excluded) {
86
+ if (source == null)
87
+ return {};
88
+ var target = {}, sourceKeys = Object.keys(source), key, i;
89
+ for (i = 0; i < sourceKeys.length; i++)
90
+ key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
91
+ return target;
92
+ }
93
+ function _sliced_to_array(arr, i) {
94
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
95
+ }
96
+ function _unsupported_iterable_to_array(o, minLen) {
97
+ if (o) {
98
+ if (typeof o == "string")
99
+ return _array_like_to_array(o, minLen);
100
+ var n = Object.prototype.toString.call(o).slice(8, -1);
101
+ if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
102
+ return Array.from(n);
103
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
104
+ return _array_like_to_array(o, minLen);
105
+ }
106
+ }
8
107
  function getState(checked) {
9
108
  return checked ? "checked" : "unchecked";
10
109
  }
11
- const BubbleInput = (props) => {
12
- const { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = usePrevious(checked);
13
- return React.useEffect(() => {
14
- const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
15
- inputProto,
16
- "checked"
17
- ).set;
110
+ var BubbleInput = function(props) {
111
+ var control = props.control, checked = props.checked, _props_bubbles = props.bubbles, bubbles = _props_bubbles === void 0 ? !0 : _props_bubbles, inputProps = _object_without_properties(props, [
112
+ "control",
113
+ "checked",
114
+ "bubbles"
115
+ ]), ref = React.useRef(null), prevChecked = usePrevious(checked);
116
+ return React.useEffect(function() {
117
+ var input = ref.current, inputProto = window.HTMLInputElement.prototype, descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"), setChecked = descriptor.set;
18
118
  if (prevChecked !== checked && setChecked) {
19
- const event = new Event("click", { bubbles });
119
+ var event = new Event("click", {
120
+ bubbles
121
+ });
20
122
  setChecked.call(input, checked), input.dispatchEvent(event);
21
123
  }
22
- }, [prevChecked, checked, bubbles]), // @ts-ignore
23
- /* @__PURE__ */ jsx(
24
- "input",
25
- {
26
- type: "checkbox",
27
- "aria-hidden": !0,
28
- defaultChecked: checked,
29
- ...inputProps,
30
- tabIndex: -1,
31
- ref,
32
- style: {
33
- ...props.style,
34
- position: "absolute",
35
- pointerEvents: "none",
36
- opacity: 0,
37
- margin: 0
38
- }
39
- }
40
- );
124
+ }, [
125
+ prevChecked,
126
+ checked,
127
+ bubbles
128
+ ]), // @ts-ignore
129
+ /* @__PURE__ */ React.createElement("input", _object_spread_props(_object_spread({
130
+ type: "checkbox",
131
+ "aria-hidden": !0,
132
+ defaultChecked: checked
133
+ }, inputProps), {
134
+ tabIndex: -1,
135
+ ref,
136
+ style: _object_spread_props(_object_spread({}, props.style), {
137
+ position: "absolute",
138
+ pointerEvents: "none",
139
+ opacity: 0,
140
+ margin: 0
141
+ })
142
+ }));
41
143
  };
42
- function useSwitch(props, [checked, setChecked], ref) {
43
- const { disabled, name, value, required } = props, hasConsumerStoppedPropagationRef = React.useRef(!1), [button, setButton] = React.useState(null), composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
144
+ function useSwitch(props, param, ref) {
145
+ var _param = _sliced_to_array(param, 2), checked = _param[0], setChecked = _param[1], disabled = props.disabled, name = props.name, value = props.value, required = props.required, hasConsumerStoppedPropagationRef = React.useRef(!1), _React_useState = _sliced_to_array(React.useState(null), 2), button = _React_useState[0], setButton = _React_useState[1], composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
44
146
  return {
45
- switchProps: {
147
+ switchProps: _object_spread_props(_object_spread({
46
148
  role: "switch",
47
- "aria-checked": checked,
48
- ...isWeb ? {
49
- tabIndex: disabled ? void 0 : 0,
50
- "data-state": getState(checked),
51
- "data-disabled": disabled ? "" : void 0,
52
- disabled
53
- } : {},
54
- ...props,
149
+ "aria-checked": checked
150
+ }, isWeb ? {
151
+ tabIndex: disabled ? void 0 : 0,
152
+ "data-state": getState(checked),
153
+ "data-disabled": disabled ? "" : void 0,
154
+ disabled
155
+ } : {}, props), {
55
156
  "aria-labelledby": ariaLabelledBy,
56
- onPress: composeEventHandlers(props.onPress, (event) => {
57
- setChecked((prevChecked) => !prevChecked), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
157
+ onPress: composeEventHandlers(props.onPress, function(event) {
158
+ setChecked(function(prevChecked) {
159
+ return !prevChecked;
160
+ }), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
58
161
  })
59
- },
162
+ }),
60
163
  switchRef: composedRefs,
61
164
  /**
62
- * insert as a sibling of your switch (should not be inside the switch)
63
- */
64
- bubbleInput: isWeb && isFormControl ? /* @__PURE__ */ jsx(
65
- BubbleInput,
66
- {
67
- control: button,
68
- bubbles: !hasConsumerStoppedPropagationRef.current,
69
- name,
70
- value,
71
- checked,
72
- required,
73
- disabled,
74
- style: { transform: "translateX(-100%)" }
165
+ * insert as a sibling of your switch (should not be inside the switch)
166
+ */
167
+ bubbleInput: isWeb && isFormControl ? /* @__PURE__ */ React.createElement(BubbleInput, {
168
+ control: button,
169
+ bubbles: !hasConsumerStoppedPropagationRef.current,
170
+ name,
171
+ value,
172
+ checked,
173
+ required,
174
+ disabled,
175
+ // We transform because the input is absolutely positioned but we have
176
+ // rendered it **after** the button. This pulls it back to sit on top
177
+ // of the button.
178
+ style: {
179
+ transform: "translateX(-100%)"
75
180
  }
76
- ) : null
181
+ }) : null
77
182
  };
78
183
  }
79
184
  export {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/useSwitch.tsx"],
4
- "mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAuDnB;AApCJ,SAAS,SAAS,SAAsB;AACtC,SAAO,UAAU,YAAY;AAC/B;AAWA,MAAM,cAAc,CAAC,UAA4B;AAC/C,QAAM,EAAE,SAAS,SAAS,UAAU,IAAM,GAAG,WAAW,IAAI,OACtD,MAAM,MAAM,OAAyB,IAAI,GACzC,cAAc,YAAY,OAAO;AAGvC,eAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI,SACZ,aAAa,OAAO,iBAAiB,WAKrC,aAJa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF,EAC8B;AAC9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC5C,iBAAW,KAAK,OAAO,OAAO,GAC9B,MAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC;AAAA,EAIhC;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,eAAW;AAAA,MACX,gBAAgB;AAAA,MACf,GAAG;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA,OAAO;AAAA,QACL,GAAG,MAAM;AAAA,QACT,UAAU;AAAA,QACV,eAAe;AAAA,QACf,SAAS;AAAA,QACT,QAAQ;AAAA,MACV;AAAA;AAAA,EACF;AAEJ;AAEO,SAA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OAA0BlC,MAA1BkC,MAAMC,QAAoBnC,MAApBmC,OAAOC,WAAapC,MAAboC,UACzBC,mCAAmCzC,MAAMS,OAAO,EAAA,GAC1BT,kBAAAA,iBAAAA,MAAM0C,SAAmC,IAAA,GAAA,CAAA,GAA9DC,SAAqB3C,gBAAAA,CAAAA,GAAb4C,YAAa5C,gBAAAA,CAAAA,GACtB6C,eAAelD,gBAAsBa,KAAKoC,SAAAA,GAG1CE,gBAAgBlD,QAAS+C,SAASI,EAAQJ,OAAOK,QAAQ,MAAA,IAAW,KAAQ,IAE5EC,UAAUnD,gBAAgB6C,MAAAA,GAC1BO,iBAAiB9C,MAAM,iBAAA,KAAsBA,MAAM+C,aAAaF;AACtE,SAAO;IACLG,aAAa,qBAAA,eAAA;MACXC,MAAM;MACN,gBAAgBnD;OACZN,QACA;MACEkC,UAAUO,WAAWiB,SAAY;MACjC,cAAcrD,SAASC,OAAAA;MACvB,iBAAiBmC,WAAW,KAAKiB;MACjCjB;IACF,IACA,CAAC,GACFjC,KAAAA,GAAAA;MACH,mBAAmB8C;MACnBK,SAAS1D,qBAAqBO,MAAMmD,SAAS,SAAChC,OAAAA;AAC5CF,mBAAW,SAACX,aAAAA;iBAAgB,CAACA;YACzBd,SAASkD,kBACXL,iCAAiC5B,UAAUU,MAAMiC,qBAAoB,GAIhEf,iCAAiC5B,WAASU,MAAMkC,gBAAe;MAExE,CAAA;;IAEFC,WAAWb;;;;IAIXc,aACE/D,SAASkD,gBACP,sBAAA,cAAC3C,aAAAA;MACCE,SAASsC;MACTrC,SAAS,CAACmC,iCAAiC5B;MAC3CyB;MACAC;MACArC;MACAsC;MACAH;;;;MAIAN,OAAO;QAAE6B,WAAW;MAAoB;SAExC;EACR;AACF;",
5
+ "names": ["useComposedRefs", "isWeb", "composeEventHandlers", "useLabelContext", "usePrevious", "React", "getState", "checked", "BubbleInput", "props", "control", "bubbles", "inputProps", "ref", "useRef", "prevChecked", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "useState", "button", "setButton", "composedRefs", "isFormControl", "Boolean", "closest", "labelId", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/switch-headless",
3
- "version": "1.89.26",
3
+ "version": "1.89.27-1708112217600",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -32,20 +32,20 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@tamagui/compose-refs": "1.89.26",
36
- "@tamagui/constants": "1.89.26",
37
- "@tamagui/helpers": "1.89.26",
38
- "@tamagui/label": "1.89.26",
39
- "@tamagui/use-previous": "1.89.26"
35
+ "@tamagui/compose-refs": "1.89.27-1708112217600",
36
+ "@tamagui/constants": "1.89.27-1708112217600",
37
+ "@tamagui/helpers": "1.89.27-1708112217600",
38
+ "@tamagui/label": "1.89.27-1708112217600",
39
+ "@tamagui/use-previous": "1.89.27-1708112217600"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": "*",
43
43
  "react-native": "*"
44
44
  },
45
45
  "devDependencies": {
46
- "@tamagui/build": "1.89.26",
46
+ "@tamagui/build": "1.89.27-1708112217600",
47
47
  "react": "^18.2.0",
48
- "react-native": "^0.72.6"
48
+ "react-native": "^0.73.4"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"