@tamagui/switch-headless 2.0.0-rc.3 → 2.0.0-rc.30
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.js +11 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/useSwitch.native.js +0 -4
- 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/package.json +11 -14
- 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.js
CHANGED
|
@@ -3,13 +3,16 @@ 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
12
16
|
var index_exports = {};
|
|
13
17
|
module.exports = __toCommonJS(index_exports);
|
|
14
|
-
__reExport(index_exports, require("./useSwitch"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
18
|
+
__reExport(index_exports, require("./useSwitch.cjs"), module.exports);
|
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
|
@@ -1,8 +1,4 @@
|
|
|
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";
|
|
6
2
|
import { usePrevious } from "@tamagui/use-previous";
|
|
7
3
|
import * as React from "react";
|
|
8
4
|
function useSwitch(props, param, ref) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsx","_jsx","usePrevious","React","useSwitch","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","composedRefs","isFormControl","labelId","ariaLabelledBy"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,2BAAuB;
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","usePrevious","React","useSwitch","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","composedRefs","isFormControl","labelId","ariaLabelledBy"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,2BAAuB;AAKhC,SAAAC,WAAY,QAAW;AAuDnB,YAAAC,KAAA;AApCJ,SAASC,SAASA,CAAAC,KAAA,EAAAC,KAAsB,EAAAC,GAAA;EACtC,KAAAC,OAAO,EAAAC,UAAU,IAAAH,KAAY;EAC/B,OAWA,OAAM;IACJI,WAAQ,EAAS;MAKjBC,OAAMA,CAAA;QACEF,UAAQ,WAAIG,WACZ;UAEJ,QAAAA,WAAA;QACA;MAE4B;IAC9B;IACEC,SAAM,EAAAN,GAAQ;IACdO,WAAW;EAEb;EACF,IAAIC,QAAA,EAAAC,IAAa,EAAAC,KAAA,EAASC,QAAQ,EAAAC,gCAAA,EAAAC,MAAA,EAAAC,SAAA,EAAAC,YAAA,EAAAC,aAAA,EAAAC,OAAA,EAAAC,cAAA;AAAA;AAIhC,SAACrB,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/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.30",
|
|
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.30",
|
|
40
|
+
"@tamagui/constants": "2.0.0-rc.30",
|
|
41
|
+
"@tamagui/helpers": "2.0.0-rc.30",
|
|
42
|
+
"@tamagui/label": "2.0.0-rc.30",
|
|
43
|
+
"@tamagui/use-previous": "2.0.0-rc.30"
|
|
47
44
|
},
|
|
48
45
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "2.0.0-rc.
|
|
46
|
+
"@tamagui/build": "2.0.0-rc.30",
|
|
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/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
|
-
{
|
|
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,8BAuDnB;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,gBAA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AA,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,cAAc,CAAC,UAA4B;AAC/C,QAAM,EAAE,SAAS,SAAS,UAAU,IAAM,GAAG,WAAW,IAAI,OACtD,MAAM,MAAM,OAAyB,IAAI,GACzC,cAAc,YAAY,OAAO;AAGvC,eAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI,SACZ,aAAa,OAAO,iBAAiB,WAKrC,aAJa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF,EAC8B;AAC9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC5C,iBAAW,KAAK,OAAO,OAAO,GAC9B,MAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC;AAAA,EAIhC;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,eAAW;AAAA,MACX,gBAAgB;AAAA,MACf,GAAG;AAAA,MACJ,UAAU;AAAA,MACV;AAAA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|
|
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 @@
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