@tamagui/switch-headless 1.89.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
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 src_exports = {};
13
+ module.exports = __toCommonJS(src_exports);
14
+ __reExport(src_exports, require("./useSwitch"), module.exports);
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,wBAAd;",
5
+ "names": []
6
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from == "object" || typeof from == "function")
8
+ for (let key of __getOwnPropNames(from))
9
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ return to;
11
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
12
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
13
+ var src_exports = {};
14
+ module.exports = __toCommonJS(src_exports);
15
+ __reExport(src_exports, require("./useSwitch"), module.exports);
16
+ // Annotate the CommonJS export names for ESM import in node:
17
+ 0 && (module.exports = {
18
+ ...require("./useSwitch")
19
+ });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,wBAAd;",
5
+ "names": []
6
+ }
@@ -0,0 +1,102 @@
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")), 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
+ 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;
67
+ return {
68
+ switchProps: {
69
+ role: "switch",
70
+ "aria-checked": checked,
71
+ ...import_constants.isWeb ? {
72
+ tabIndex: disabled ? void 0 : 0,
73
+ "data-state": getState(checked),
74
+ "data-disabled": disabled ? "" : void 0,
75
+ disabled
76
+ } : {},
77
+ ...props,
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
+ //# sourceMappingURL=useSwitch.js.map
@@ -0,0 +1,6 @@
1
+ {
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;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,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var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: !0 });
10
+ }, __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from == "object" || typeof from == "function")
12
+ for (let key of __getOwnPropNames(from))
13
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
22
+ mod
23
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
24
+ var useSwitch_exports = {};
25
+ __export(useSwitch_exports, {
26
+ useSwitch: () => useSwitch
27
+ });
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
+ );
33
+ function getState(checked) {
34
+ return checked ? "checked" : "unchecked";
35
+ }
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;
43
+ if (prevChecked !== checked && setChecked) {
44
+ const event = new Event("click", { bubbles });
45
+ setChecked.call(input, checked), input.dispatchEvent(event);
46
+ }
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
+ );
65
+ };
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;
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
+ ...props,
79
+ "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());
82
+ })
83
+ },
84
+ switchRef: composedRefs,
85
+ /**
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%)" }
99
+ }
100
+ ) : null
101
+ };
102
+ }
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ useSwitch
106
+ });
107
+ //# sourceMappingURL=useSwitch.js.map
@@ -0,0 +1,6 @@
1
+ {
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;AAAA,MACC,MAAK;AAAA,MACL,eAAW;AAAA,MACX,gBAAgB;AAAA,MACf,GAAG;AAAA,MACJ,UAA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R;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./useSwitch";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
@@ -0,0 +1 @@
1
+ export * from "./useSwitch.mjs";
@@ -0,0 +1,2 @@
1
+ export * from "./useSwitch";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
@@ -0,0 +1,82 @@
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
+ 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;
44
+ return {
45
+ switchProps: {
46
+ 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,
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
+ export {
80
+ useSwitch
81
+ };
82
+ //# sourceMappingURL=useSwitch.js.map
@@ -0,0 +1,6 @@
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,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E,UAAU,WAAW,SAAY;AAAA,QACjC,cAAc,SAAS,OAAO;AAAA,QAC9B,iBAAiB,WAAW,KAAK;AAAA,QACjC;AAAA,MACF,IACA,CAAC;AAAA,MACL,GAAG;AAAA,MACH,mBAAmB;AAAA,MACnB,SAAS,qBAAqB,MAAM,SAAS,CAAC,UAAiC;AAC7E,mBAAW,CAAC,gBAAgB,CAAC,WAAW,GACpC,SAAS,kBACX,iCAAiC,UAAU,MAAM,qBAAqB,GAIjE,iCAAiC,WAAS,MAAM,gBAAgB;AAAA,MAEzE,CAAC;AAAA,IACH;AAAA,IACA,WAAW;AAAA;AAAA;AAAA;AAAA,IAIX,aACE,SAAS,gBACP;AAAA,MAAC;AAAA;AAAA,QACC,SAAS;AAAA,QACT,SAAS,CAAC,iCAAiC;AAAA,QAC3C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAIA,OAAO,EAAE,WAAW,oBAAoB;AAAA;AAAA,IAC1C,IACE;AAAA,EACR;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,96 @@
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 {
13
+ control,
14
+ checked,
15
+ bubbles = !0,
16
+ ...inputProps
17
+ } = props,
18
+ ref = React.useRef(null),
19
+ prevChecked = usePrevious(checked);
20
+ return React.useEffect(() => {
21
+ const input = ref.current,
22
+ inputProto = window.HTMLInputElement.prototype,
23
+ setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
24
+ if (prevChecked !== checked && setChecked) {
25
+ const event = new Event("click", {
26
+ bubbles
27
+ });
28
+ setChecked.call(input, checked), input.dispatchEvent(event);
29
+ }
30
+ }, [prevChecked, checked, bubbles]),
31
+ // @ts-ignore
32
+ /* @__PURE__ */
33
+ jsx("input", {
34
+ type: "checkbox",
35
+ "aria-hidden": !0,
36
+ defaultChecked: checked,
37
+ ...inputProps,
38
+ tabIndex: -1,
39
+ ref,
40
+ style: {
41
+ ...props.style,
42
+ position: "absolute",
43
+ pointerEvents: "none",
44
+ opacity: 0,
45
+ margin: 0
46
+ }
47
+ });
48
+ };
49
+ function useSwitch(props, [checked, setChecked], ref) {
50
+ const {
51
+ disabled,
52
+ name,
53
+ value,
54
+ required
55
+ } = props,
56
+ hasConsumerStoppedPropagationRef = React.useRef(!1),
57
+ [button, setButton] = React.useState(null),
58
+ composedRefs = useComposedRefs(ref, setButton),
59
+ isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
60
+ labelId = useLabelContext(button),
61
+ ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
62
+ return {
63
+ switchProps: {
64
+ role: "switch",
65
+ "aria-checked": checked,
66
+ ...(isWeb ? {
67
+ tabIndex: disabled ? void 0 : 0,
68
+ "data-state": getState(checked),
69
+ "data-disabled": disabled ? "" : void 0,
70
+ disabled
71
+ } : {}),
72
+ ...props,
73
+ "aria-labelledby": ariaLabelledBy,
74
+ onPress: composeEventHandlers(props.onPress, event => {
75
+ setChecked(prevChecked => !prevChecked), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
76
+ })
77
+ },
78
+ switchRef: composedRefs,
79
+ /**
80
+ * insert as a sibling of your switch (should not be inside the switch)
81
+ */
82
+ bubbleInput: isWeb && isFormControl ? /* @__PURE__ */jsx(BubbleInput, {
83
+ control: button,
84
+ bubbles: !hasConsumerStoppedPropagationRef.current,
85
+ name,
86
+ value,
87
+ checked,
88
+ required,
89
+ disabled,
90
+ style: {
91
+ transform: "translateX(-100%)"
92
+ }
93
+ }) : null
94
+ };
95
+ }
96
+ export { useSwitch };
@@ -0,0 +1,82 @@
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
+ 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;
44
+ return {
45
+ switchProps: {
46
+ 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,
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
+ export {
80
+ useSwitch
81
+ };
82
+ //# sourceMappingURL=useSwitch.js.map
@@ -0,0 +1,6 @@
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,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC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A;AAAA,IAIX,aACE,SAAS,gBACP;AAAA,MAAC;AAAA;AAAA,QACC,SAAS;AAAA,QACT,SAAS,CAAC,iCAAiC;AAAA,QAC3C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAIA,OAAO,EAAE,WAAW,oBAAoB;AAAA;AAAA,IAC1C,IACE;AAAA,EACR;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./useSwitch";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
@@ -0,0 +1 @@
1
+ export * from "./useSwitch.mjs";
@@ -0,0 +1,2 @@
1
+ export * from "./useSwitch";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
@@ -0,0 +1,82 @@
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
+ 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;
44
+ return {
45
+ switchProps: {
46
+ 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,
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
+ export {
80
+ useSwitch
81
+ };
82
+ //# sourceMappingURL=useSwitch.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+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B,QAAS,SAAS,EAAQ,OAAO,QAAQ,MAAM,IAAK,KAAQ,IAE5E,UAAU,gBAAgB,MAAM,GAChC,iBAAiB,MAAM,iBAAiB,KAAK,MAAM,aAAa;AACtE,SAAO;AAAA,IACL,aAAa;AAAA,MACX,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,GAAI,QACA;AAAA,QACE,UAAU,WAAW,SAAY;AAAA,QACjC,cAAc,SAAS,OAAO;AAAA,QAC9B,iBAAiB,WAAW,KAAK;AAAA,QACjC;AAAA,MACF,IACA,CAAC;AAAA,MACL,GAAG;AAAA,MACH,mBAAmB;AAAA,MACnB,SAAS,qBAAqB,MAAM,SAAS,CAAC,UAAiC;AAC7E,mBAAW,CAAC,gBAAgB,CAAC,WAAW,GACpC,SAAS,kBACX,iCAAiC,UAAU,MAAM,qBAAqB,GAIjE,iCAAiC,WAAS,MAAM,gBAAgB;AAAA,MAEzE,CAAC;AAAA,IACH;AAAA,IACA,WAAW;AAAA;AAAA;AAAA;AAAA,IAIX,aACE,SAAS,gBACP;AAAA,MAAC;AAAA;AAAA,QACC,SAAS;AAAA,QACT,SAAS,CAAC,iCAAiC;AAAA,QAC3C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAIA,OAAO,EAAE,WAAW,oBAAoB;AAAA;AAAA,IAC1C,IACE;AAAA,EACR;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,96 @@
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 {
13
+ control,
14
+ checked,
15
+ bubbles = !0,
16
+ ...inputProps
17
+ } = props,
18
+ ref = React.useRef(null),
19
+ prevChecked = usePrevious(checked);
20
+ return React.useEffect(() => {
21
+ const input = ref.current,
22
+ inputProto = window.HTMLInputElement.prototype,
23
+ setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
24
+ if (prevChecked !== checked && setChecked) {
25
+ const event = new Event("click", {
26
+ bubbles
27
+ });
28
+ setChecked.call(input, checked), input.dispatchEvent(event);
29
+ }
30
+ }, [prevChecked, checked, bubbles]),
31
+ // @ts-ignore
32
+ /* @__PURE__ */
33
+ jsx("input", {
34
+ type: "checkbox",
35
+ "aria-hidden": !0,
36
+ defaultChecked: checked,
37
+ ...inputProps,
38
+ tabIndex: -1,
39
+ ref,
40
+ style: {
41
+ ...props.style,
42
+ position: "absolute",
43
+ pointerEvents: "none",
44
+ opacity: 0,
45
+ margin: 0
46
+ }
47
+ });
48
+ };
49
+ function useSwitch(props, [checked, setChecked], ref) {
50
+ const {
51
+ disabled,
52
+ name,
53
+ value,
54
+ required
55
+ } = props,
56
+ hasConsumerStoppedPropagationRef = React.useRef(!1),
57
+ [button, setButton] = React.useState(null),
58
+ composedRefs = useComposedRefs(ref, setButton),
59
+ isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
60
+ labelId = useLabelContext(button),
61
+ ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
62
+ return {
63
+ switchProps: {
64
+ role: "switch",
65
+ "aria-checked": checked,
66
+ ...(isWeb ? {
67
+ tabIndex: disabled ? void 0 : 0,
68
+ "data-state": getState(checked),
69
+ "data-disabled": disabled ? "" : void 0,
70
+ disabled
71
+ } : {}),
72
+ ...props,
73
+ "aria-labelledby": ariaLabelledBy,
74
+ onPress: composeEventHandlers(props.onPress, event => {
75
+ setChecked(prevChecked => !prevChecked), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
76
+ })
77
+ },
78
+ switchRef: composedRefs,
79
+ /**
80
+ * insert as a sibling of your switch (should not be inside the switch)
81
+ */
82
+ bubbleInput: isWeb && isFormControl ? /* @__PURE__ */jsx(BubbleInput, {
83
+ control: button,
84
+ bubbles: !hasConsumerStoppedPropagationRef.current,
85
+ name,
86
+ value,
87
+ checked,
88
+ required,
89
+ disabled,
90
+ style: {
91
+ transform: "translateX(-100%)"
92
+ }
93
+ }) : null
94
+ };
95
+ }
96
+ export { useSwitch };
@@ -0,0 +1,82 @@
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
+ 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;
44
+ return {
45
+ switchProps: {
46
+ 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,
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
+ export {
80
+ useSwitch
81
+ };
82
+ //# sourceMappingURL=useSwitch.js.map
@@ -0,0 +1,6 @@
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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AAS,qBAAqB,MAAM,SAAS,CAAC,UAAiC;AAC7E,mBAAW,CAAC,gBAAgB,CAAC,WAAW,GACpC,SAAS,kBACX,iCAAiC,UAAU,MAAM,qBAAqB,GAIjE,iCAAiC,WAAS,MAAM,gBAAgB;AAAA,MAEzE,CAAC;AAAA,IACH;AAAA,IACA,WAAW;AAAA;AAAA;AAAA;AAAA,IAIX,aACE,SAAS,gBACP;AAAA,MAAC;AAAA;AAAA,QACC,SAAS;AAAA,QACT,SAAS,CAAC,iCAAiC;AAAA,QAC3C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAIA,OAAO,EAAE,WAAW,oBAAoB;AAAA;AAAA,IAC1C,IACE;AAAA,EACR;AACF;",
5
+ "names": []
6
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@tamagui/switch-headless",
3
+ "version": "1.89.0",
4
+ "sideEffects": [
5
+ "*.css"
6
+ ],
7
+ "source": "src/index.ts",
8
+ "types": "./types/index.d.ts",
9
+ "main": "dist/cjs",
10
+ "module": "dist/esm",
11
+ "module:jsx": "dist/jsx",
12
+ "files": [
13
+ "src",
14
+ "types",
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tamagui-build",
19
+ "watch": "tamagui-build --watch",
20
+ "lint": "../../node_modules/.bin/biome check src",
21
+ "lint:fix": "../../node_modules/.bin/biome check --apply-unsafe src",
22
+ "clean": "tamagui-build clean",
23
+ "clean:build": "tamagui-build clean:build"
24
+ },
25
+ "exports": {
26
+ "./package.json": "./package.json",
27
+ ".": {
28
+ "types": "./types/index.d.ts",
29
+ "import": "./dist/esm/index.js",
30
+ "require": "./dist/cjs/index.js",
31
+ "react-native": "./dist/cjs/index.native.js"
32
+ }
33
+ },
34
+ "dependencies": {
35
+ "@tamagui/compose-refs": "1.89.0",
36
+ "@tamagui/constants": "1.89.0",
37
+ "@tamagui/helpers": "1.89.0",
38
+ "@tamagui/label": "1.89.0",
39
+ "@tamagui/use-previous": "1.89.0"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "*",
43
+ "react-native": "*"
44
+ },
45
+ "devDependencies": {
46
+ "@tamagui/build": "1.89.0",
47
+ "react": "^18.2.0",
48
+ "react-native": "^0.72.6"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './useSwitch'
@@ -0,0 +1,140 @@
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 type { GestureResponderEvent, PressableProps, View, ViewProps } from 'react-native'
8
+
9
+ type SwitchBaseProps = ViewProps & Pick<PressableProps, 'onPress'>
10
+
11
+ export type SwitchExtraProps = {
12
+ labeledBy?: string
13
+ disabled?: boolean
14
+ name?: string
15
+ value?: string
16
+ checked?: boolean
17
+ defaultChecked?: boolean
18
+ required?: boolean
19
+ onCheckedChange?(checked: boolean): void
20
+ }
21
+
22
+ export type SwitchProps = SwitchBaseProps & SwitchExtraProps
23
+ export type SwitchState = boolean
24
+
25
+ function getState(checked: SwitchState) {
26
+ return checked ? 'checked' : 'unchecked'
27
+ }
28
+
29
+ type InputProps = React.HTMLProps<'input'>
30
+
31
+ interface BubbleInputProps extends Omit<InputProps, 'checked'> {
32
+ checked: boolean
33
+ control: HTMLElement | null
34
+ bubbles: boolean
35
+ }
36
+
37
+ // TODO make this native friendly
38
+ const BubbleInput = (props: BubbleInputProps) => {
39
+ const { control, checked, bubbles = true, ...inputProps } = props
40
+ const ref = React.useRef<HTMLInputElement>(null)
41
+ const prevChecked = usePrevious(checked)
42
+
43
+ // Bubble checked change to parents (e.g form change event)
44
+ React.useEffect(() => {
45
+ const input = ref.current!
46
+ const inputProto = window.HTMLInputElement.prototype
47
+ const descriptor = Object.getOwnPropertyDescriptor(
48
+ inputProto,
49
+ 'checked'
50
+ ) as PropertyDescriptor
51
+ const setChecked = descriptor.set
52
+ if (prevChecked !== checked && setChecked) {
53
+ const event = new Event('click', { bubbles })
54
+ setChecked.call(input, checked)
55
+ input.dispatchEvent(event)
56
+ }
57
+ }, [prevChecked, checked, bubbles])
58
+
59
+ return (
60
+ // @ts-ignore
61
+ <input
62
+ type="checkbox"
63
+ aria-hidden
64
+ defaultChecked={checked}
65
+ {...inputProps}
66
+ tabIndex={-1}
67
+ ref={ref}
68
+ style={{
69
+ ...props.style,
70
+ position: 'absolute',
71
+ pointerEvents: 'none',
72
+ opacity: 0,
73
+ margin: 0,
74
+ }}
75
+ />
76
+ )
77
+ }
78
+
79
+ export function useSwitch<R extends View, P extends SwitchProps>(
80
+ props: P,
81
+ [checked, setChecked]: [SwitchState, React.Dispatch<React.SetStateAction<SwitchState>>],
82
+ ref: React.Ref<R>
83
+ ) {
84
+ const { disabled, name, value, required } = props
85
+ const hasConsumerStoppedPropagationRef = React.useRef(false)
86
+ const [button, setButton] = React.useState<HTMLButtonElement | null>(null)
87
+ const composedRefs = useComposedRefs<View>(ref, setButton as any)
88
+
89
+ // We set this to true by default so that events bubble to forms without JS (SSR)
90
+ const isFormControl = isWeb ? (button ? Boolean(button.closest('form')) : true) : false
91
+
92
+ const labelId = useLabelContext(button)
93
+ const ariaLabelledBy = props['aria-labelledby'] || props.labeledBy || labelId
94
+ return {
95
+ switchProps: {
96
+ role: 'switch',
97
+ 'aria-checked': checked,
98
+ ...(isWeb
99
+ ? {
100
+ tabIndex: disabled ? undefined : 0,
101
+ 'data-state': getState(checked),
102
+ 'data-disabled': disabled ? '' : undefined,
103
+ disabled: disabled,
104
+ }
105
+ : {}),
106
+ ...props,
107
+ 'aria-labelledby': ariaLabelledBy,
108
+ onPress: composeEventHandlers(props.onPress, (event: GestureResponderEvent) => {
109
+ setChecked((prevChecked) => !prevChecked)
110
+ if (isWeb && isFormControl) {
111
+ hasConsumerStoppedPropagationRef.current = event.isPropagationStopped()
112
+ // if switch is in a form, stop propagation from the button so that we only propagate
113
+ // one click event (from the input). We propagate changes from an input so that native
114
+ // form validation works and form events reflect switch updates.
115
+ if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation()
116
+ }
117
+ }),
118
+ } satisfies SwitchBaseProps,
119
+ switchRef: composedRefs,
120
+ /**
121
+ * insert as a sibling of your switch (should not be inside the switch)
122
+ */
123
+ bubbleInput:
124
+ isWeb && isFormControl ? (
125
+ <BubbleInput
126
+ control={button}
127
+ bubbles={!hasConsumerStoppedPropagationRef.current}
128
+ name={name}
129
+ value={value}
130
+ checked={checked}
131
+ required={required}
132
+ disabled={disabled}
133
+ // We transform because the input is absolutely positioned but we have
134
+ // rendered it **after** the button. This pulls it back to sit on top
135
+ // of the button.
136
+ style={{ transform: 'translateX(-100%)' }}
137
+ />
138
+ ) : null,
139
+ }
140
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useSwitch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ import type { GestureResponderEvent, PressableProps, View, ViewProps } from 'react-native';
3
+ type SwitchBaseProps = ViewProps & Pick<PressableProps, 'onPress'>;
4
+ export type SwitchExtraProps = {
5
+ labeledBy?: string;
6
+ disabled?: boolean;
7
+ name?: string;
8
+ value?: string;
9
+ checked?: boolean;
10
+ defaultChecked?: boolean;
11
+ required?: boolean;
12
+ onCheckedChange?(checked: boolean): void;
13
+ };
14
+ export type SwitchProps = SwitchBaseProps & SwitchExtraProps;
15
+ export type SwitchState = boolean;
16
+ export declare function useSwitch<R extends View, P extends SwitchProps>(props: P, [checked, setChecked]: [SwitchState, React.Dispatch<React.SetStateAction<SwitchState>>], ref: React.Ref<R>): {
17
+ switchProps: {
18
+ tabIndex?: number | undefined;
19
+ 'data-state'?: string | undefined;
20
+ 'data-disabled'?: string | undefined;
21
+ disabled?: boolean | undefined;
22
+ role: "switch";
23
+ 'aria-checked': boolean;
24
+ } & P & {
25
+ 'aria-labelledby': string | undefined;
26
+ onPress: import("@tamagui/helpers").EventHandler<GestureResponderEvent> | undefined;
27
+ };
28
+ switchRef: (node: View) => void;
29
+ /**
30
+ * insert as a sibling of your switch (should not be inside the switch)
31
+ */
32
+ bubbleInput: JSX.Element | null;
33
+ };
34
+ export {};
35
+ //# sourceMappingURL=useSwitch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSwitch.d.ts","sourceRoot":"","sources":["../src/useSwitch.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE1F,KAAK,eAAe,GAAG,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAA;AAElE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,eAAe,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CACzC,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,gBAAgB,CAAA;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAA;AAwDjC,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,WAAW,EAC7D,KAAK,EAAE,CAAC,EACR,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EACvF,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;;;;;;;;;;;;;IAsCf;;OAEG;;EAkBN"}