@tamagui/switch-headless 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.
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useSwitch.cjs +63 -60
- package/dist/cjs/useSwitch.native.js +32 -31
- package/dist/cjs/useSwitch.native.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/useSwitch.mjs +32 -32
- package/dist/esm/useSwitch.mjs.map +1 -1
- package/dist/esm/useSwitch.native.js +5 -6
- package/dist/esm/useSwitch.native.js.map +1 -1
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -6
- package/dist/jsx/index.native.js +7 -5
- package/dist/jsx/useSwitch.mjs +32 -32
- package/dist/jsx/useSwitch.mjs.map +1 -1
- package/dist/jsx/useSwitch.native.js +32 -31
- package/dist/jsx/useSwitch.native.js.map +1 -1
- package/package.json +11 -14
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useSwitch.js +0 -103
- package/dist/cjs/useSwitch.js.map +0 -6
- package/dist/esm/useSwitch.js +0 -83
- package/dist/esm/useSwitch.js.map +0 -6
- package/dist/jsx/useSwitch.js +0 -83
- package/dist/jsx/useSwitch.js.map +0 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,15 +3,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
7
8
|
get: () => from[key],
|
|
8
9
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
10
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
15
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
-
value:
|
|
16
|
+
value: true
|
|
15
17
|
}), mod);
|
|
16
18
|
var index_exports = {};
|
|
17
19
|
module.exports = __toCommonJS(index_exports);
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -5,15 +5,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
9
10
|
get: () => from[key],
|
|
10
11
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
17
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
-
value:
|
|
18
|
+
value: true
|
|
17
19
|
}), mod);
|
|
18
20
|
var index_exports = {};
|
|
19
21
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA","ignoreList":[]}
|
package/dist/cjs/useSwitch.cjs
CHANGED
|
@@ -2,72 +2,74 @@ 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
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 useSwitch_exports = {};
|
|
33
35
|
__export(useSwitch_exports, {
|
|
34
36
|
useSwitch: () => useSwitch
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(useSwitch_exports);
|
|
37
|
-
var import_compose_refs = require("@tamagui/compose-refs")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
require("react/jsx-runtime");
|
|
39
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
40
|
+
var import_constants = require("@tamagui/constants");
|
|
41
|
+
var import_helpers = require("@tamagui/helpers");
|
|
42
|
+
var import_label = require("@tamagui/label");
|
|
43
|
+
var import_use_previous = require("@tamagui/use-previous");
|
|
44
|
+
var React = __toESM(require("react"), 1);
|
|
45
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
46
|
function getState(checked) {
|
|
47
47
|
return checked ? "checked" : "unchecked";
|
|
48
48
|
}
|
|
49
49
|
const BubbleInput = props => {
|
|
50
50
|
const {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const input = ref.current
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
control,
|
|
52
|
+
checked,
|
|
53
|
+
bubbles = true,
|
|
54
|
+
...inputProps
|
|
55
|
+
} = props;
|
|
56
|
+
const ref = React.useRef(null);
|
|
57
|
+
const prevChecked = (0, import_use_previous.usePrevious)(checked);
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
const input = ref.current;
|
|
60
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
61
|
+
const setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
|
|
62
62
|
if (prevChecked !== checked && setChecked) {
|
|
63
63
|
const event = new Event("click", {
|
|
64
64
|
bubbles
|
|
65
65
|
});
|
|
66
|
-
setChecked.call(input, checked)
|
|
66
|
+
setChecked.call(input, checked);
|
|
67
|
+
input.dispatchEvent(event);
|
|
67
68
|
}
|
|
68
|
-
}, [prevChecked, checked, bubbles])
|
|
69
|
+
}, [prevChecked, checked, bubbles]);
|
|
70
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
|
|
69
71
|
type: "checkbox",
|
|
70
|
-
"aria-hidden":
|
|
72
|
+
"aria-hidden": true,
|
|
71
73
|
defaultChecked: checked,
|
|
72
74
|
...inputProps,
|
|
73
75
|
tabIndex: -1,
|
|
@@ -84,17 +86,17 @@ const BubbleInput = props => {
|
|
|
84
86
|
function useSwitch(props, [checked, setChecked], ref) {
|
|
85
87
|
{
|
|
86
88
|
const {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
disabled,
|
|
90
|
+
name,
|
|
91
|
+
value,
|
|
92
|
+
required
|
|
93
|
+
} = props;
|
|
94
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
95
|
+
const [button, setButton] = React.useState(null);
|
|
96
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);
|
|
97
|
+
const isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
98
|
+
const labelId = (0, import_label.useLabelContext)(button);
|
|
99
|
+
const ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
98
100
|
return {
|
|
99
101
|
switchProps: {
|
|
100
102
|
role: "switch",
|
|
@@ -107,13 +109,14 @@ function useSwitch(props, [checked, setChecked], ref) {
|
|
|
107
109
|
} : {}),
|
|
108
110
|
"aria-labelledby": ariaLabelledBy,
|
|
109
111
|
onPress: (0, import_helpers.composeEventHandlers)(props.onPress, event => {
|
|
110
|
-
setChecked(prevChecked => !prevChecked)
|
|
112
|
+
setChecked(prevChecked => !prevChecked);
|
|
113
|
+
if (import_constants.isWeb && isFormControl) {
|
|
114
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
115
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
116
|
+
}
|
|
111
117
|
})
|
|
112
118
|
},
|
|
113
119
|
switchRef: composedRefs,
|
|
114
|
-
/**
|
|
115
|
-
* insert as a sibling of your switch (should not be inside the switch)
|
|
116
|
-
*/
|
|
117
120
|
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(BubbleInput, {
|
|
118
121
|
control: button,
|
|
119
122
|
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
@@ -4,48 +4,50 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var useSwitch_exports = {};
|
|
35
37
|
__export(useSwitch_exports, {
|
|
36
38
|
useSwitch: () => useSwitch
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(useSwitch_exports);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
require("react/jsx-runtime");
|
|
42
|
+
require("@tamagui/compose-refs");
|
|
43
|
+
require("@tamagui/constants");
|
|
44
|
+
require("@tamagui/helpers");
|
|
45
|
+
require("@tamagui/label");
|
|
46
|
+
require("@tamagui/use-previous");
|
|
47
|
+
__toESM(require("react"), 1);
|
|
46
48
|
function useSwitch(props, param, ref) {
|
|
47
49
|
var [checked, setChecked] = param;
|
|
48
|
-
|
|
50
|
+
return {
|
|
49
51
|
switchProps: {
|
|
50
52
|
onPress() {
|
|
51
53
|
setChecked(function (prevChecked) {
|
|
@@ -56,6 +58,5 @@ function useSwitch(props, param, ref) {
|
|
|
56
58
|
switchRef: ref,
|
|
57
59
|
bubbleInput: null
|
|
58
60
|
};
|
|
59
|
-
var disabled, name, value, required, hasConsumerStoppedPropagationRef, button, setButton, composedRefs, isFormControl, labelId, ariaLabelledBy;
|
|
60
61
|
}
|
|
61
62
|
//# sourceMappingURL=useSwitch.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["isNodeMode","mod","__esModule","__defProp","target","value","enumerable","__toCommonJS","__copyProps","useSwitch_exports","__export","useSwitch","module","exports","require","__toESM","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,UAAA,KAAAC,GAAA,KAAAA,GAAA,CAAAC,UAAA,GAAAC,SAAA,CAAAC,MAAA;EAAAC,KAAA,EAAAJ,GAAA;EAAAK,UAAA;AAAA,KAAAF,MAAA,EAAAH,GAAA;AACA,IAAAM,YAAA,GAAAN,GAAsB,IAAAO,WAAA,CAAAL,SAAA;EAAAE,KAAA;AAAA,IAAAJ,GAAA;AACtB,IAAAQ,iBAAqC;AACrCC,QAAA,CAAAD,iBAAgC;EAAAE,SAAA,EAAAA,CAAA,KAAAA;AAAA;AAChCC,MAAA,CAAAC,OAAA,GAAAN,YAA4B,CAAAE,iBAAA;AAC5BK,OAAA,oBAAuB;AAuDnBA,OAAA;AAAAA,OAAA;AAAAA,OAAA;AAAAA,OAAA;AApCJA,OAAA,wBAAwC;AACtCC,OAAA,CAAAD,OAAO,QAAU;AACnB,SAAAH,UAAAK,KAAA,EAAAC,KAAA,EAAAC,GAAA;EAWA,KAAMC,OAAA,EAAAC,UAAe,IAAAH,KAA4B;EAC/C,OAAM;IACNI,WAAM,EAAM;MAAAC,OAAMA,CAAA,EAAyB;QAC3CF,UAAM,WAAAG,WAAc;UAGpB,OAAM,CAAAA,WAAU;QACd;MACA;IAAA;IACAC,SAAM,EAAAN,GAAA;IAAoBO,WACxB;EAAA;AACA","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./useSwitch";
|
|
1
|
+
export * from "./useSwitch.mjs";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
package/dist/esm/useSwitch.mjs
CHANGED
|
@@ -10,29 +10,28 @@ function getState(checked) {
|
|
|
10
10
|
}
|
|
11
11
|
const BubbleInput = props => {
|
|
12
12
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const input = ref.current
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
control,
|
|
14
|
+
checked,
|
|
15
|
+
bubbles = true,
|
|
16
|
+
...inputProps
|
|
17
|
+
} = props;
|
|
18
|
+
const ref = React.useRef(null);
|
|
19
|
+
const prevChecked = usePrevious(checked);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
const input = ref.current;
|
|
22
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
23
|
+
const setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
|
|
24
24
|
if (prevChecked !== checked && setChecked) {
|
|
25
25
|
const event = new Event("click", {
|
|
26
26
|
bubbles
|
|
27
27
|
});
|
|
28
|
-
setChecked.call(input, checked)
|
|
28
|
+
setChecked.call(input, checked);
|
|
29
|
+
input.dispatchEvent(event);
|
|
29
30
|
}
|
|
30
|
-
}, [prevChecked, checked, bubbles])
|
|
31
|
-
|
|
32
|
-
/* @__PURE__ */
|
|
33
|
-
jsx("input", {
|
|
31
|
+
}, [prevChecked, checked, bubbles]);
|
|
32
|
+
return /* @__PURE__ */jsx("input", {
|
|
34
33
|
type: "checkbox",
|
|
35
|
-
"aria-hidden":
|
|
34
|
+
"aria-hidden": true,
|
|
36
35
|
defaultChecked: checked,
|
|
37
36
|
...inputProps,
|
|
38
37
|
tabIndex: -1,
|
|
@@ -49,17 +48,17 @@ const BubbleInput = props => {
|
|
|
49
48
|
function useSwitch(props, [checked, setChecked], ref) {
|
|
50
49
|
{
|
|
51
50
|
const {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
disabled,
|
|
52
|
+
name,
|
|
53
|
+
value,
|
|
54
|
+
required
|
|
55
|
+
} = props;
|
|
56
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
57
|
+
const [button, setButton] = React.useState(null);
|
|
58
|
+
const composedRefs = useComposedRefs(ref, setButton);
|
|
59
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
60
|
+
const labelId = useLabelContext(button);
|
|
61
|
+
const ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
63
62
|
return {
|
|
64
63
|
switchProps: {
|
|
65
64
|
role: "switch",
|
|
@@ -72,13 +71,14 @@ function useSwitch(props, [checked, setChecked], ref) {
|
|
|
72
71
|
} : {}),
|
|
73
72
|
"aria-labelledby": ariaLabelledBy,
|
|
74
73
|
onPress: composeEventHandlers(props.onPress, event => {
|
|
75
|
-
setChecked(prevChecked => !prevChecked)
|
|
74
|
+
setChecked(prevChecked => !prevChecked);
|
|
75
|
+
if (isWeb && isFormControl) {
|
|
76
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
77
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
78
|
+
}
|
|
76
79
|
})
|
|
77
80
|
},
|
|
78
81
|
switchRef: composedRefs,
|
|
79
|
-
/**
|
|
80
|
-
* insert as a sibling of your switch (should not be inside the switch)
|
|
81
|
-
*/
|
|
82
82
|
bubbleInput: isWeb && isFormControl ? /* @__PURE__ */jsx(BubbleInput, {
|
|
83
83
|
control: button,
|
|
84
84
|
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useComposedRefs","isWeb","composeEventHandlers","useLabelContext","usePrevious","React","jsx","getState","checked","BubbleInput","props","control","bubbles","inputProps","ref","useRef","prevChecked","useEffect","input","current","inputProto","window","HTMLInputElement","prototype","setChecked","Object","getOwnPropertyDescriptor","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","closest","labelId","ariaLabelledBy","labeledBy","switchProps","role","onPress","isPropagationStopped","stopPropagation","switchRef","bubbleInput","transform"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,eAAA,QAAuB;AAChC,SAASC,KAAA,QAAa;AACtB,SAASC,oBAAA,QAA4B;AACrC,SAASC,eAAA,QAAuB;AAChC,SAASC,WAAA,QAAmB;AAC5B,YAAYC,KAAA,MAAW;AAuDnB,SAAAC,GAAA;AApCJ,SAASC,SAASC,OAAA,EAAsB;EACtC,
|
|
1
|
+
{"version":3,"names":["useComposedRefs","isWeb","composeEventHandlers","useLabelContext","usePrevious","React","jsx","getState","checked","BubbleInput","props","control","bubbles","inputProps","ref","useRef","prevChecked","useEffect","input","current","inputProto","window","HTMLInputElement","prototype","setChecked","Object","getOwnPropertyDescriptor","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","Boolean","closest","labelId","ariaLabelledBy","labeledBy","switchProps","role","onPress","isPropagationStopped","stopPropagation","switchRef","bubbleInput","transform"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,eAAA,QAAuB;AAChC,SAASC,KAAA,QAAa;AACtB,SAASC,oBAAA,QAA4B;AACrC,SAASC,eAAA,QAAuB;AAChC,SAASC,WAAA,QAAmB;AAC5B,YAAYC,KAAA,MAAW;AAuDnB,SAAAC,GAAA;AApCJ,SAASC,SAASC,OAAA,EAAsB;EACtC,OAAAA,OAAO,YAAU,cAAY;AAC/B;AAWA,MAAMC,WAAA,GAAeC,KAAA,IAA4B;EAC/C;IAAMC,OAAE;IAAAH,OAAS;IAAAI,OAAS,OAAU;IAAA,GAAMC;EAAG,CAAW,GAAAH,KAAI;EAC5D,MAAAI,GAAM,GAAAT,KAAM,CAAAU,MAAM,KAAyB,CAAI;EAC/C,MAAAC,WAAM,GAAAZ,WAAc,CAAAI,OAAY,CAAO;EAGvCH,KAAA,CAAAY,SAAM,OAAU;IACd,MAAAC,KAAM,GAAAJ,GAAQ,CAAAK,OAAI;IAClB,MAAAC,UAAM,GAAAC,MAAa,CAAAC,gBAAO,CAAAC,SAAiB;IAC3C,MAAAC,UAAM,GAAAC,MAAa,CAAAC,wBAAO,CAAAN,UAAA,aAAAO,GAAA;IAAA,IACxBX,WAAA,KAAAR,OAAA,I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AAqB,CAAAQ,KAAM,CAAAgD,OAAmC,EAAA9B,KAAI;UACzEJ,UAAM,CAAAR,WAAe,KAAAA,WAAsB,CAAK;UAEhD,IAAAf,KAAM,IAAAiD,aAAgB;YAMtBL,gCAAgC,CAAA1B,OAAM,GAAAS,KAAA,CAAA+B,oBAAA;YACtC,IAAM,CAAAd,gCAAuB,CAAA1B,OAAiB,EAAAS,KAAK,CAAAgC,eAAmB;UACtE;QAAO;MACQ;MACLC,SACN,EAAAZ,YAAgB;MAAAa,WACZ,EAAA7D,KACA,IAAAiD,aAAA,kBAAA5C,GAAA,CAAAG,WAAA;QAAAE,OACE,EAAAmC,MAAA;QAAiClC,OACjC,GAAAiC,gCAA8B,CAAA1B,OAAA;QAAAuB,IAAA;QACGC,KAAA;QACjCnC,OACF;QACCoC,QACL;QAAmBH,QACnB;QACEN,KAAA;UAAA4B,SAAY;QAAiB;MAC7B;IACE;EAIA;AAAqE;AACvE,SACDvB,SAAA","ignoreList":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import "@tamagui/compose-refs";
|
|
3
|
-
import "@tamagui/constants";
|
|
4
|
-
import "@tamagui/helpers";
|
|
5
|
-
import "@tamagui/label";
|
|
2
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
|
+
import { isWeb } from "@tamagui/constants";
|
|
4
|
+
import { composeEventHandlers } from "@tamagui/helpers";
|
|
5
|
+
import { useLabelContext } from "@tamagui/label";
|
|
6
6
|
import { usePrevious } from "@tamagui/use-previous";
|
|
7
7
|
import * as React from "react";
|
|
8
8
|
function useSwitch(props, param, ref) {
|
|
9
9
|
var [checked, setChecked] = param;
|
|
10
|
-
|
|
10
|
+
return {
|
|
11
11
|
switchProps: {
|
|
12
12
|
onPress() {
|
|
13
13
|
setChecked(function (prevChecked) {
|
|
@@ -18,7 +18,6 @@ function useSwitch(props, param, ref) {
|
|
|
18
18
|
switchRef: ref,
|
|
19
19
|
bubbleInput: null
|
|
20
20
|
};
|
|
21
|
-
var disabled, name, value, required, hasConsumerStoppedPropagationRef, button, setButton, composedRefs, isFormControl, labelId, ariaLabelledBy;
|
|
22
21
|
}
|
|
23
22
|
export { useSwitch };
|
|
24
23
|
//# sourceMappingURL=useSwitch.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsx","_jsx","usePrevious","React","useSwitch","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput"
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","useComposedRefs","isWeb","composeEventHandlers","useLabelContext","usePrevious","React","useSwitch","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,2BAAuB;AAChC,SAASC,eAAa;AACtB,SAASC,KAAA,4BAA4B;AACrC,SAASC,oBAAA,QAAuB;AAChC,SAASC,eAAA,QAAmB;AAC5B,SAAAC,WAAY,QAAW;AAuDnB,YAAAC,KAAA;AApCJ,SAASC,SAASA,CAAAC,KAAA,EAAAC,KAAsB,EAAAC,GAAA;EACtC,KAAAC,OAAO,EAAAC,UAAU,IAAAH,KAAY;EAC/B;IAWAI,WAAM;MAAAC,OAAeA,CAAA;QACnBF,UAAQ,WAASG,WAAS;UAC1B,OAAM,CAAAA,WAAY;QAClB;MAGA;IAAA;IACEC,SAAM,EAAAN,GAAA;IACNO,WAAM;EACN;AAA0B;AACxB,SACAV,SAAA","ignoreList":[]}
|
package/dist/jsx/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./useSwitch";
|
|
1
|
+
export * from "./useSwitch.mjs";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/jsx/index.js.map
CHANGED
package/dist/jsx/index.native.js
CHANGED
|
@@ -5,15 +5,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
9
10
|
get: () => from[key],
|
|
10
11
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
17
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
-
value:
|
|
18
|
+
value: true
|
|
17
19
|
}), mod);
|
|
18
20
|
var index_exports = {};
|
|
19
21
|
module.exports = __toCommonJS(index_exports);
|
package/dist/jsx/useSwitch.mjs
CHANGED
|
@@ -10,29 +10,28 @@ function getState(checked) {
|
|
|
10
10
|
}
|
|
11
11
|
const BubbleInput = props => {
|
|
12
12
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const input = ref.current
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
control,
|
|
14
|
+
checked,
|
|
15
|
+
bubbles = true,
|
|
16
|
+
...inputProps
|
|
17
|
+
} = props;
|
|
18
|
+
const ref = React.useRef(null);
|
|
19
|
+
const prevChecked = usePrevious(checked);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
const input = ref.current;
|
|
22
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
23
|
+
const setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
|
|
24
24
|
if (prevChecked !== checked && setChecked) {
|
|
25
25
|
const event = new Event("click", {
|
|
26
26
|
bubbles
|
|
27
27
|
});
|
|
28
|
-
setChecked.call(input, checked)
|
|
28
|
+
setChecked.call(input, checked);
|
|
29
|
+
input.dispatchEvent(event);
|
|
29
30
|
}
|
|
30
|
-
}, [prevChecked, checked, bubbles])
|
|
31
|
-
|
|
32
|
-
/* @__PURE__ */
|
|
33
|
-
jsx("input", {
|
|
31
|
+
}, [prevChecked, checked, bubbles]);
|
|
32
|
+
return /* @__PURE__ */jsx("input", {
|
|
34
33
|
type: "checkbox",
|
|
35
|
-
"aria-hidden":
|
|
34
|
+
"aria-hidden": true,
|
|
36
35
|
defaultChecked: checked,
|
|
37
36
|
...inputProps,
|
|
38
37
|
tabIndex: -1,
|
|
@@ -49,17 +48,17 @@ const BubbleInput = props => {
|
|
|
49
48
|
function useSwitch(props, [checked, setChecked], ref) {
|
|
50
49
|
{
|
|
51
50
|
const {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
disabled,
|
|
52
|
+
name,
|
|
53
|
+
value,
|
|
54
|
+
required
|
|
55
|
+
} = props;
|
|
56
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
57
|
+
const [button, setButton] = React.useState(null);
|
|
58
|
+
const composedRefs = useComposedRefs(ref, setButton);
|
|
59
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
60
|
+
const labelId = useLabelContext(button);
|
|
61
|
+
const ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
63
62
|
return {
|
|
64
63
|
switchProps: {
|
|
65
64
|
role: "switch",
|
|
@@ -72,13 +71,14 @@ function useSwitch(props, [checked, setChecked], ref) {
|
|
|
72
71
|
} : {}),
|
|
73
72
|
"aria-labelledby": ariaLabelledBy,
|
|
74
73
|
onPress: composeEventHandlers(props.onPress, event => {
|
|
75
|
-
setChecked(prevChecked => !prevChecked)
|
|
74
|
+
setChecked(prevChecked => !prevChecked);
|
|
75
|
+
if (isWeb && isFormControl) {
|
|
76
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
77
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
78
|
+
}
|
|
76
79
|
})
|
|
77
80
|
},
|
|
78
81
|
switchRef: composedRefs,
|
|
79
|
-
/**
|
|
80
|
-
* insert as a sibling of your switch (should not be inside the switch)
|
|
81
|
-
*/
|
|
82
82
|
bubbleInput: isWeb && isFormControl ? /* @__PURE__ */jsx(BubbleInput, {
|
|
83
83
|
control: button,
|
|
84
84
|
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useComposedRefs","isWeb","composeEventHandlers","useLabelContext","usePrevious","React","jsx","getState","checked","BubbleInput","props","control","bubbles","inputProps","ref","useRef","prevChecked","useEffect","input","current","inputProto","window","HTMLInputElement","prototype","setChecked","Object","getOwnPropertyDescriptor","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","closest","labelId","ariaLabelledBy","labeledBy","switchProps","role","onPress","isPropagationStopped","stopPropagation","switchRef","bubbleInput","transform"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,eAAA,QAAuB;AAChC,SAASC,KAAA,QAAa;AACtB,SAASC,oBAAA,QAA4B;AACrC,SAASC,eAAA,QAAuB;AAChC,SAASC,WAAA,QAAmB;AAC5B,YAAYC,KAAA,MAAW;AAuDnB,SAAAC,GAAA;AApCJ,SAASC,SAASC,OAAA,EAAsB;EACtC,
|
|
1
|
+
{"version":3,"names":["useComposedRefs","isWeb","composeEventHandlers","useLabelContext","usePrevious","React","jsx","getState","checked","BubbleInput","props","control","bubbles","inputProps","ref","useRef","prevChecked","useEffect","input","current","inputProto","window","HTMLInputElement","prototype","setChecked","Object","getOwnPropertyDescriptor","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","Boolean","closest","labelId","ariaLabelledBy","labeledBy","switchProps","role","onPress","isPropagationStopped","stopPropagation","switchRef","bubbleInput","transform"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,eAAA,QAAuB;AAChC,SAASC,KAAA,QAAa;AACtB,SAASC,oBAAA,QAA4B;AACrC,SAASC,eAAA,QAAuB;AAChC,SAASC,WAAA,QAAmB;AAC5B,YAAYC,KAAA,MAAW;AAuDnB,SAAAC,GAAA;AApCJ,SAASC,SAASC,OAAA,EAAsB;EACtC,OAAAA,OAAO,YAAU,cAAY;AAC/B;AAWA,MAAMC,WAAA,GAAeC,KAAA,IAA4B;EAC/C;IAAMC,OAAE;IAAAH,OAAS;IAAAI,OAAS,OAAU;IAAA,GAAMC;EAAG,CAAW,GAAAH,KAAI;EAC5D,MAAAI,GAAM,GAAAT,KAAM,CAAAU,MAAM,KAAyB,CAAI;EAC/C,MAAAC,WAAM,GAAAZ,WAAc,CAAAI,OAAY,CAAO;EAGvCH,KAAA,CAAAY,SAAM,OAAU;IACd,MAAAC,KAAM,GAAAJ,GAAQ,CAAAK,OAAI;IAClB,MAAAC,UAAM,GAAAC,MAAa,CAAAC,gBAAO,CAAAC,SAAiB;IAC3C,MAAAC,UAAM,GAAAC,MAAa,CAAAC,wBAAO,CAAAN,UAAA,aAAAO,GAAA;IAAA,IACxBX,WAAA,KAAAR,OAAA,IAAAgB,UAAA;MAAA,MACAI,KAAA,OAAAC,KAAA;QAAAjB;MAAA;MAAAY,UACF,CAAAM,IAAA,CAAAZ,KAAA,EA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EhD,IAAAf,KAAM,IAAAiD,aAAgB;YAMtBL,gCAAgC,CAAA1B,OAAM,GAAAS,KAAA,CAAA+B,oBAAA;YACtC,IAAM,CAAAd,gCAAuB,CAAA1B,OAAiB,EAAAS,KAAK,CAAAgC,eAAmB;UACtE;QAAO;MACQ;MACLC,SACN,EAAAZ,YAAgB;MAAAa,WACZ,EAAA7D,KACA,IAAAiD,aAAA,kBAAA5C,GAAA,CAAAG,WAAA;QAAAE,OACE,EAAAmC,MAAA;QAAiClC,OACjC,GAAAiC,gCAA8B,CAAA1B,OAAA;QAAAuB,IAAA;QACGC,KAAA;QACjCnC,OACF;QACCoC,QACL;QAAmBH,QACnB;QACEN,KAAA;UAAA4B,SAAY;QAAiB;MAC7B;IACE;EAIA;AAAqE;AACvE,SACDvB,SAAA","ignoreList":[]}
|
|
@@ -4,48 +4,50 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var useSwitch_exports = {};
|
|
35
37
|
__export(useSwitch_exports, {
|
|
36
38
|
useSwitch: () => useSwitch
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(useSwitch_exports);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
require("react/jsx-runtime");
|
|
42
|
+
require("@tamagui/compose-refs");
|
|
43
|
+
require("@tamagui/constants");
|
|
44
|
+
require("@tamagui/helpers");
|
|
45
|
+
require("@tamagui/label");
|
|
46
|
+
require("@tamagui/use-previous");
|
|
47
|
+
__toESM(require("react"), 1);
|
|
46
48
|
function useSwitch(props, param, ref) {
|
|
47
49
|
var [checked, setChecked] = param;
|
|
48
|
-
|
|
50
|
+
return {
|
|
49
51
|
switchProps: {
|
|
50
52
|
onPress() {
|
|
51
53
|
setChecked(function (prevChecked) {
|
|
@@ -56,6 +58,5 @@ function useSwitch(props, param, ref) {
|
|
|
56
58
|
switchRef: ref,
|
|
57
59
|
bubbleInput: null
|
|
58
60
|
};
|
|
59
|
-
var disabled, name, value, required, hasConsumerStoppedPropagationRef, button, setButton, composedRefs, isFormControl, labelId, ariaLabelledBy;
|
|
60
61
|
}
|
|
61
62
|
//# sourceMappingURL=useSwitch.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","useSwitch_exports","useSwitch","module","exports","
|
|
1
|
+
{"version":3,"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","useSwitch_exports","useSwitch","module","exports","require","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,YAAS;;AACT,IAAAA,QAAS,GAAAC,MAAA,CAAaC,MAAA;AACtB,IAAAC,SAAS,GAAAF,MAAA,CAAAG,cAA4B;AACrC,IAAAC,gBAAS,GAAAJ,MAAA,CAAAK,wBAAuB;AAChC,IAAAC,iBAAS,GAAAN,MAAmB,CAAAO,mBAAA;AAC5B,IAAAC,YAAY,GAAAR,MAAW,CAAAS,cAAA;AAuDnB,IAAAC,YAAA,GAAAV,MAAA,CAAAW,SAAA,CAAAC,cAAA;AApCJ,IAAAC,QAAS,GAAAA,CAAA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;AAAAA,OAAA,CACV;AAAAA,OAAA,CACA,oBAAO;AAAAA,OAAA,mBACI;AAAAA,OAAA,iBACC;AAAAA,OAAA,wBACK;AAAAV,OAAA,CAAAU,OACf,QAAS;AAAA,SAAAH,SACDA,CAAAI,KAAA,EAAAC,KAAA,EAAAC,GAAA;EAAA,KAAAC,OACV,EAAAC,UAAA,IAAAH,KAAA;EAAA;IAAAI,WACF;MAAAC,QAAA;QAAAF,UAAA,WAAAG,WAAA;UAEJ,QAAAA,WAAA;QAEO;MAKL;IAAA;IACEC,SAAO,EAAAN,GAAA;IAAAO,WACL;EAAa;AAET","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/switch-headless",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.40",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -18,15 +18,12 @@
|
|
|
18
18
|
"./package.json": "./package.json",
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./types/index.d.ts",
|
|
21
|
-
"react-native":
|
|
22
|
-
|
|
23
|
-
"import": "./dist/esm/index.native.js",
|
|
24
|
-
"require": "./dist/cjs/index.native.js"
|
|
25
|
-
},
|
|
21
|
+
"react-native": "./dist/esm/index.native.js",
|
|
22
|
+
"browser": "./dist/esm/index.mjs",
|
|
26
23
|
"module": "./dist/esm/index.mjs",
|
|
27
24
|
"import": "./dist/esm/index.mjs",
|
|
28
25
|
"require": "./dist/cjs/index.cjs",
|
|
29
|
-
"default": "./dist/
|
|
26
|
+
"default": "./dist/esm/index.mjs"
|
|
30
27
|
}
|
|
31
28
|
},
|
|
32
29
|
"publishConfig": {
|
|
@@ -39,16 +36,16 @@
|
|
|
39
36
|
"clean:build": "tamagui-build clean:build"
|
|
40
37
|
},
|
|
41
38
|
"dependencies": {
|
|
42
|
-
"@tamagui/compose-refs": "2.0.0-rc.
|
|
43
|
-
"@tamagui/constants": "2.0.0-rc.
|
|
44
|
-
"@tamagui/helpers": "2.0.0-rc.
|
|
45
|
-
"@tamagui/label": "2.0.0-rc.
|
|
46
|
-
"@tamagui/use-previous": "2.0.0-rc.
|
|
39
|
+
"@tamagui/compose-refs": "2.0.0-rc.40",
|
|
40
|
+
"@tamagui/constants": "2.0.0-rc.40",
|
|
41
|
+
"@tamagui/helpers": "2.0.0-rc.40",
|
|
42
|
+
"@tamagui/label": "2.0.0-rc.40",
|
|
43
|
+
"@tamagui/use-previous": "2.0.0-rc.40"
|
|
47
44
|
},
|
|
48
45
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "2.0.0-rc.
|
|
46
|
+
"@tamagui/build": "2.0.0-rc.40",
|
|
50
47
|
"react": ">=19",
|
|
51
|
-
"react-native": "0.
|
|
48
|
+
"react-native": "0.83.2"
|
|
52
49
|
},
|
|
53
50
|
"peerDependencies": {
|
|
54
51
|
"react": ">=19",
|
package/dist/cjs/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var index_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(index_exports);
|
|
14
|
-
__reExport(index_exports, require("./useSwitch"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
package/dist/cjs/useSwitch.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var useSwitch_exports = {};
|
|
24
|
-
__export(useSwitch_exports, {
|
|
25
|
-
useSwitch: () => useSwitch
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(useSwitch_exports);
|
|
28
|
-
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"), 1), import_jsx_runtime = (
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
require("react/jsx-runtime")
|
|
31
|
-
);
|
|
32
|
-
function getState(checked) {
|
|
33
|
-
return checked ? "checked" : "unchecked";
|
|
34
|
-
}
|
|
35
|
-
const BubbleInput = (props) => {
|
|
36
|
-
const { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
|
|
37
|
-
return React.useEffect(() => {
|
|
38
|
-
const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
|
|
39
|
-
inputProto,
|
|
40
|
-
"checked"
|
|
41
|
-
).set;
|
|
42
|
-
if (prevChecked !== checked && setChecked) {
|
|
43
|
-
const event = new Event("click", { bubbles });
|
|
44
|
-
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
45
|
-
}
|
|
46
|
-
}, [prevChecked, checked, bubbles]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
47
|
-
"input",
|
|
48
|
-
{
|
|
49
|
-
type: "checkbox",
|
|
50
|
-
"aria-hidden": !0,
|
|
51
|
-
defaultChecked: checked,
|
|
52
|
-
...inputProps,
|
|
53
|
-
tabIndex: -1,
|
|
54
|
-
ref,
|
|
55
|
-
style: {
|
|
56
|
-
...props.style,
|
|
57
|
-
position: "absolute",
|
|
58
|
-
pointerEvents: "none",
|
|
59
|
-
opacity: 0,
|
|
60
|
-
margin: 0
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
function useSwitch(props, [checked, setChecked], ref) {
|
|
66
|
-
{
|
|
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;
|
|
68
|
-
return {
|
|
69
|
-
switchProps: {
|
|
70
|
-
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
|
-
"aria-labelledby": ariaLabelledBy,
|
|
79
|
-
onPress: (0, import_helpers.composeEventHandlers)(props.onPress, (event) => {
|
|
80
|
-
setChecked((prevChecked) => !prevChecked), import_constants.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
81
|
-
})
|
|
82
|
-
},
|
|
83
|
-
switchRef: composedRefs,
|
|
84
|
-
/**
|
|
85
|
-
* insert as a sibling of your switch (should not be inside the switch)
|
|
86
|
-
*/
|
|
87
|
-
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
88
|
-
BubbleInput,
|
|
89
|
-
{
|
|
90
|
-
control: button,
|
|
91
|
-
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
92
|
-
name,
|
|
93
|
-
value,
|
|
94
|
-
checked,
|
|
95
|
-
required,
|
|
96
|
-
disabled,
|
|
97
|
-
style: { transform: "translateX(-100%)" }
|
|
98
|
-
}
|
|
99
|
-
) : null
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=useSwitch.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|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S,IAAI,MAAM,SAAmC,IAAI,GACnE,mBAAe,qCAAsB,KAAK,SAAgB,GAE1D,gBAAgB,yBAClB,SACE,EAAQ,OAAO,QAAQ,MAAM,IAC7B,KACF,IAEE,cAAU,8BAAgB,MAAM,GAChC,iBAAiB,MAAM,iBAAiB,KAAK,MAAM,aAAa;AACtE,WAAO;AAAA,MACL,aAAa;AAAA,QACX,MAAM;AAAA,QACN,gBAAgB;AAAA,QAChB,GAAI,yBACA;AAAA,UACE,UAAU,WAAW,SAAY;AAAA,UACjC,cAAc,SAAS,OAAO;AAAA,UAC9B,iBAAiB,WAAW,KAAK;AAAA,UACjC;AAAA,QACF,IACA,CAAC;AAAA,QACL,mBAAmB;AAAA,QACnB,aAAS,qCAAqB,MAAM,SAAS,CAAC,UAAiC;AAC7E,qBAAW,CAAC,gBAAgB,CAAC,WAAW,GACpC,0BAAS,kBACX,iCAAiC,UAAU,MAAM,qBAAqB,GAIjE,iCAAiC,WAAS,MAAM,gBAAgB;AAAA,QAEzE,CAAC;AAAA,MACH;AAAA,MACA,WAAW;AAAA;AAAA;AAAA;AAAA,MAIX,aACE,0BAAS,gBACP;AAAA,QAAC;AAAA;AAAA,UACC,SAAS;AAAA,UACT,SAAS,CAAC,iCAAiC;AAAA,UAC3C;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAIA,OAAO,EAAE,WAAW,oBAAoB;AAAA;AAAA,MAC1C,IACE;AAAA,IACR;AAAA,EACF;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/esm/useSwitch.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
-
import { isWeb } from "@tamagui/constants";
|
|
3
|
-
import { composeEventHandlers } from "@tamagui/helpers";
|
|
4
|
-
import { useLabelContext } from "@tamagui/label";
|
|
5
|
-
import { usePrevious } from "@tamagui/use-previous";
|
|
6
|
-
import * as React from "react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
function getState(checked) {
|
|
9
|
-
return checked ? "checked" : "unchecked";
|
|
10
|
-
}
|
|
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;
|
|
18
|
-
if (prevChecked !== checked && setChecked) {
|
|
19
|
-
const event = new Event("click", { bubbles });
|
|
20
|
-
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
21
|
-
}
|
|
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
|
-
);
|
|
41
|
-
};
|
|
42
|
-
function useSwitch(props, [checked, setChecked], ref) {
|
|
43
|
-
{
|
|
44
|
-
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;
|
|
45
|
-
return {
|
|
46
|
-
switchProps: {
|
|
47
|
-
role: "switch",
|
|
48
|
-
"aria-checked": checked,
|
|
49
|
-
...isWeb ? {
|
|
50
|
-
tabIndex: disabled ? void 0 : 0,
|
|
51
|
-
"data-state": getState(checked),
|
|
52
|
-
"data-disabled": disabled ? "" : void 0,
|
|
53
|
-
disabled
|
|
54
|
-
} : {},
|
|
55
|
-
"aria-labelledby": ariaLabelledBy,
|
|
56
|
-
onPress: composeEventHandlers(props.onPress, (event) => {
|
|
57
|
-
setChecked((prevChecked) => !prevChecked), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
58
|
-
})
|
|
59
|
-
},
|
|
60
|
-
switchRef: composedRefs,
|
|
61
|
-
/**
|
|
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%)" }
|
|
75
|
-
}
|
|
76
|
-
) : null
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export {
|
|
81
|
-
useSwitch
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=useSwitch.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
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,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AA,UACjC,cAAc,SAAS,OAAO;AAAA,UAC9B,iBAAiB,WAAW,KAAK;AAAA,UACjC;AAAA,QACF,IACA,CAAC;AAAA,QACL,mBAAmB;AAAA,QACnB,SAAS,qBAAqB,MAAM,SAAS,CAAC,UAAiC;AAC7E,qBAAW,CAAC,gBAAgB,CAAC,WAAW,GACpC,SAAS,kBACX,iCAAiC,UAAU,MAAM,qBAAqB,GAIjE,iCAAiC,WAAS,MAAM,gBAAgB;AAAA,QAEzE,CAAC;AAAA,MACH;AAAA,MACA,WAAW;AAAA;AAAA;AAAA;AAAA,MAIX,aACE,SAAS,gBACP;AAAA,QAAC;AAAA;AAAA,UACC,SAAS;AAAA,UACT,SAAS,CAAC,iCAAiC;AAAA,UAC3C;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAIA,OAAO,EAAE,WAAW,oBAAoB;AAAA;AAAA,MAC1C,IACE;AAAA,IACR;AAAA,EACF;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/jsx/useSwitch.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
-
import { isWeb } from "@tamagui/constants";
|
|
3
|
-
import { composeEventHandlers } from "@tamagui/helpers";
|
|
4
|
-
import { useLabelContext } from "@tamagui/label";
|
|
5
|
-
import { usePrevious } from "@tamagui/use-previous";
|
|
6
|
-
import * as React from "react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
function getState(checked) {
|
|
9
|
-
return checked ? "checked" : "unchecked";
|
|
10
|
-
}
|
|
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;
|
|
18
|
-
if (prevChecked !== checked && setChecked) {
|
|
19
|
-
const event = new Event("click", { bubbles });
|
|
20
|
-
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
21
|
-
}
|
|
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
|
-
);
|
|
41
|
-
};
|
|
42
|
-
function useSwitch(props, [checked, setChecked], ref) {
|
|
43
|
-
{
|
|
44
|
-
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;
|
|
45
|
-
return {
|
|
46
|
-
switchProps: {
|
|
47
|
-
role: "switch",
|
|
48
|
-
"aria-checked": checked,
|
|
49
|
-
...isWeb ? {
|
|
50
|
-
tabIndex: disabled ? void 0 : 0,
|
|
51
|
-
"data-state": getState(checked),
|
|
52
|
-
"data-disabled": disabled ? "" : void 0,
|
|
53
|
-
disabled
|
|
54
|
-
} : {},
|
|
55
|
-
"aria-labelledby": ariaLabelledBy,
|
|
56
|
-
onPress: composeEventHandlers(props.onPress, (event) => {
|
|
57
|
-
setChecked((prevChecked) => !prevChecked), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
58
|
-
})
|
|
59
|
-
},
|
|
60
|
-
switchRef: composedRefs,
|
|
61
|
-
/**
|
|
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%)" }
|
|
75
|
-
}
|
|
76
|
-
) : null
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export {
|
|
81
|
-
useSwitch
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=useSwitch.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
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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