@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.
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/cjs/useSwitch.native.js +162 -58
- package/dist/cjs/useSwitch.native.js.map +3 -3
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/useSwitch.native.js +161 -56
- package/dist/esm/useSwitch.native.js.map +3 -3
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/useSwitch.native.js +161 -56
- package/dist/jsx/useSwitch.native.js.map +3 -3
- package/package.json +8 -8
|
@@ -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"))
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
142
|
+
var event = new Event("click", {
|
|
143
|
+
bubbles
|
|
144
|
+
});
|
|
45
145
|
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
46
146
|
}
|
|
47
|
-
}, [
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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,
|
|
67
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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)
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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": "
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch-headless/src/useSwitch.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0BAAgC,kCAChC,mBAAsB,+BACtB,iBAAqC,6BACrC,eAAgC,2BAChC,sBAA4B,kCAC5B,QAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBvB,SAASA,SAASC,SAAoB;AACpC,SAAOA,UAAU,YAAY;AAC/B;AAWA,IAAMC,cAAc,SAACC,OAAAA;AACnB,MAAQC,UAAoDD,MAApDC,SAASH,UAA2CE,MAA3CF,SAAAA,iBAA2CE,MAAlCE,SAAAA,UAAAA,mBAAAA,SAAU,KAAA,gBAASC,aAAAA,2BAAeH,OAAAA;IAApDC;IAASH;IAASI;MACpBE,MAAMC,MAAMC,OAAyB,IAAA,GACrCC,kBAAcC,iCAAYV,OAAAA;AAGhCO,eAAMI,UAAU,WAAA;AACd,QAAMC,QAAQN,IAAIO,SACZC,aAAaC,OAAOC,iBAAiBC,WACrCC,aAAaC,OAAOC,yBACxBN,YACA,SAAA,GAEIO,aAAaH,WAAWI;AAC9B,QAAIb,gBAAgBT,WAAWqB,YAAY;AACzC,UAAME,QAAQ,IAAIC,MAAM,SAAS;QAAEpB;MAAQ,CAAA;AAC3CiB,iBAAWI,KAAKb,OAAOZ,OAAAA,GACvBY,MAAMc,cAAcH,KAAAA;IACtB;EACF,GAAG;IAACd;IAAaT;IAASI;GAAQ;EAIhC,sBAAA,cAACQ,SAAAA,qBAAAA,eAAAA;IACCe,MAAK;IACLC,eAAAA;IACAC,gBAAgB7B;KACZK,UAAAA,GAAAA;IACJyB,UAAU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MACTvC,SAAS,CAACqC,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
|
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
119
|
+
var event = new Event("click", {
|
|
120
|
+
bubbles
|
|
121
|
+
});
|
|
20
122
|
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
21
123
|
}
|
|
22
|
-
}, [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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,
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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)
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
bubbleInput: isWeb && isFormControl ? /* @__PURE__ */
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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,
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch-headless/src/useSwitch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"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
|
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
119
|
+
var event = new Event("click", {
|
|
120
|
+
bubbles
|
|
121
|
+
});
|
|
20
122
|
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
21
123
|
}
|
|
22
|
-
}, [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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,
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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)
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
bubbleInput: isWeb && isFormControl ? /* @__PURE__ */
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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,
|
|
5
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/switch-headless/src/useSwitch.tsx"],
|
|
4
|
+
"mappings": "AAAA,SAASA,uBAAuB;AAChC,SAASC,aAAa;AACtB,SAASC,4BAA4B;AACrC,SAASC,uBAAuB;AAChC,SAASC,mBAAmB;AAC5B,YAAYC,WAAW;;;;;;;;;;;;;;;;;;;;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AAboC,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.
|
|
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.
|
|
36
|
-
"@tamagui/constants": "1.89.
|
|
37
|
-
"@tamagui/helpers": "1.89.
|
|
38
|
-
"@tamagui/label": "1.89.
|
|
39
|
-
"@tamagui/use-previous": "1.89.
|
|
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.
|
|
46
|
+
"@tamagui/build": "1.89.27-1708112217600",
|
|
47
47
|
"react": "^18.2.0",
|
|
48
|
-
"react-native": "^0.
|
|
48
|
+
"react-native": "^0.73.4"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|