@tamagui/switch-headless 2.0.0-rc.35 → 2.0.0-rc.36-1775243248161
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 +77 -58
- package/dist/cjs/useSwitch.native.js +98 -41
- package/dist/cjs/useSwitch.native.js.map +1 -1
- package/dist/esm/useSwitch.mjs +61 -43
- package/dist/esm/useSwitch.mjs.map +1 -1
- package/dist/esm/useSwitch.native.js +71 -12
- package/dist/esm/useSwitch.native.js.map +1 -1
- package/dist/jsx/index.native.js +7 -5
- package/dist/jsx/useSwitch.mjs +61 -43
- package/dist/jsx/useSwitch.mjs.map +1 -1
- package/dist/jsx/useSwitch.native.js +98 -41
- package/dist/jsx/useSwitch.native.js.map +1 -1
- package/package.json +7 -7
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,77 @@ 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
|
-
|
|
45
|
-
|
|
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 =
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
require("react/jsx-runtime");
|
|
46
48
|
function getState(checked) {
|
|
47
49
|
return checked ? "checked" : "unchecked";
|
|
48
50
|
}
|
|
49
51
|
const BubbleInput = props => {
|
|
50
52
|
const {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const input = ref.current
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
control,
|
|
54
|
+
checked,
|
|
55
|
+
bubbles = true,
|
|
56
|
+
...inputProps
|
|
57
|
+
} = props;
|
|
58
|
+
const ref = React.useRef(null);
|
|
59
|
+
const prevChecked = (0, import_use_previous.usePrevious)(checked);
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
const input = ref.current;
|
|
62
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
63
|
+
const descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked");
|
|
64
|
+
const setChecked = descriptor.set;
|
|
62
65
|
if (prevChecked !== checked && setChecked) {
|
|
63
66
|
const event = new Event("click", {
|
|
64
67
|
bubbles
|
|
65
68
|
});
|
|
66
|
-
setChecked.call(input, checked)
|
|
69
|
+
setChecked.call(input, checked);
|
|
70
|
+
input.dispatchEvent(event);
|
|
67
71
|
}
|
|
68
|
-
}, [prevChecked, checked, bubbles])
|
|
72
|
+
}, [prevChecked, checked, bubbles]);
|
|
73
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
|
|
69
74
|
type: "checkbox",
|
|
70
|
-
"aria-hidden":
|
|
75
|
+
"aria-hidden": true,
|
|
71
76
|
defaultChecked: checked,
|
|
72
77
|
...inputProps,
|
|
73
78
|
tabIndex: -1,
|
|
@@ -82,19 +87,29 @@ const BubbleInput = props => {
|
|
|
82
87
|
});
|
|
83
88
|
};
|
|
84
89
|
function useSwitch(props, [checked, setChecked], ref) {
|
|
85
|
-
{
|
|
90
|
+
if (false) {
|
|
91
|
+
return {
|
|
92
|
+
switchProps: {
|
|
93
|
+
onPress() {
|
|
94
|
+
setChecked(prevChecked => !prevChecked);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
switchRef: ref,
|
|
98
|
+
bubbleInput: null
|
|
99
|
+
};
|
|
100
|
+
} else {
|
|
86
101
|
const {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
disabled,
|
|
103
|
+
name,
|
|
104
|
+
value,
|
|
105
|
+
required
|
|
106
|
+
} = props;
|
|
107
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
108
|
+
const [button, setButton] = React.useState(null);
|
|
109
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);
|
|
110
|
+
const isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
111
|
+
const labelId = (0, import_label.useLabelContext)(button);
|
|
112
|
+
const ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
98
113
|
return {
|
|
99
114
|
switchProps: {
|
|
100
115
|
role: "switch",
|
|
@@ -107,7 +122,11 @@ function useSwitch(props, [checked, setChecked], ref) {
|
|
|
107
122
|
} : {}),
|
|
108
123
|
"aria-labelledby": ariaLabelledBy,
|
|
109
124
|
onPress: (0, import_helpers.composeEventHandlers)(props.onPress, event => {
|
|
110
|
-
setChecked(prevChecked => !prevChecked)
|
|
125
|
+
setChecked(prevChecked => !prevChecked);
|
|
126
|
+
if (import_constants.isWeb && isFormControl) {
|
|
127
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
128
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
129
|
+
}
|
|
111
130
|
})
|
|
112
131
|
},
|
|
113
132
|
switchRef: composedRefs,
|
|
@@ -4,58 +4,115 @@ 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
|
-
var import_jsx_runtime = require("react/jsx-runtime")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
43
|
+
var import_constants = require("@tamagui/constants");
|
|
44
|
+
var import_helpers = require("@tamagui/helpers");
|
|
45
|
+
var import_label = require("@tamagui/label");
|
|
46
|
+
var import_use_previous = require("@tamagui/use-previous");
|
|
47
|
+
var React = __toESM(require("react"), 1);
|
|
46
48
|
function useSwitch(props, param, ref) {
|
|
47
49
|
var [checked, setChecked] = param;
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
if (true) {
|
|
51
|
+
return {
|
|
52
|
+
switchProps: {
|
|
53
|
+
onPress() {
|
|
54
|
+
setChecked(function (prevChecked) {
|
|
55
|
+
return !prevChecked;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
switchRef: ref,
|
|
60
|
+
bubbleInput: null
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
var {
|
|
64
|
+
disabled,
|
|
65
|
+
name,
|
|
66
|
+
value,
|
|
67
|
+
required
|
|
68
|
+
} = props;
|
|
69
|
+
var hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
70
|
+
var [button, setButton] = React.useState(null);
|
|
71
|
+
var composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);
|
|
72
|
+
var isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
73
|
+
var labelId = (0, import_label.useLabelContext)(button);
|
|
74
|
+
var ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
75
|
+
return {
|
|
76
|
+
switchProps: {
|
|
77
|
+
role: "switch",
|
|
78
|
+
"aria-checked": checked,
|
|
79
|
+
...(import_constants.isWeb ? {
|
|
80
|
+
tabIndex: disabled ? void 0 : 0,
|
|
81
|
+
"data-state": getState(checked),
|
|
82
|
+
"data-disabled": disabled ? "" : void 0,
|
|
83
|
+
disabled
|
|
84
|
+
} : {}),
|
|
85
|
+
"aria-labelledby": ariaLabelledBy,
|
|
86
|
+
onPress: (0, import_helpers.composeEventHandlers)(props.onPress, function (event) {
|
|
87
|
+
setChecked(function (prevChecked) {
|
|
88
|
+
return !prevChecked;
|
|
89
|
+
});
|
|
90
|
+
if (import_constants.isWeb && isFormControl) {
|
|
91
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
92
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
switchRef: composedRefs,
|
|
97
|
+
/**
|
|
98
|
+
* insert as a sibling of your switch (should not be inside the switch)
|
|
99
|
+
*/
|
|
100
|
+
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(BubbleInput, {
|
|
101
|
+
control: button,
|
|
102
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
103
|
+
name,
|
|
104
|
+
value,
|
|
105
|
+
checked,
|
|
106
|
+
required,
|
|
107
|
+
disabled,
|
|
108
|
+
// We transform because the input is absolutely positioned but we have
|
|
109
|
+
// rendered it **after** the button. This pulls it back to sit on top
|
|
110
|
+
// of the button.
|
|
111
|
+
style: {
|
|
112
|
+
transform: "translateX(-100%)"
|
|
113
|
+
}
|
|
114
|
+
}) : null
|
|
115
|
+
};
|
|
116
|
+
}
|
|
60
117
|
}
|
|
61
118
|
//# sourceMappingURL=useSwitch.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useSwitch_exports","__export","useSwitch","module","exports","import_jsx_runtime","require","import_compose_refs","import_constants","import_helpers","import_label","import_use_previous","React","__toESM","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput","disabled","name","required","hasConsumerStoppedPropagationRef","button","setButton","composedRefs","isFormControl","labelId","ariaLabelledBy"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useSwitch_exports","__export","useSwitch","module","exports","import_jsx_runtime","require","import_compose_refs","import_constants","import_helpers","import_label","import_use_previous","React","__toESM","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput","disabled","name","required","hasConsumerStoppedPropagationRef","useRef","button","setButton","useState","composedRefs","useComposedRefs","isFormControl","isWeb","Boolean","closest","labelId","useLabelContext","ariaLabelledBy","labeledBy","role","tabIndex","getState","composeEventHandlers","event","current","isPropagationStopped","stopPropagation","jsx","BubbleInput","control","bubbles","style","transform"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,iBAAA;AAAAC,QAAA,CAAAD,iBAAA;EAAAE,SAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAgC,CAAAK,iBAAA;AAChC,IAAAK,kBAAA,GAAsBC,OAAA;AACtB,IAAAC,mBAAqC,GAAAD,OAAA;AACrC,IAAAE,gBAAgC,GAAAF,OAAA;AAChC,IAAAG,cAAA,GAAAH,OAA4B;AAC5B,IAAAI,YAAuB,GAAAJ,OAAA;AAuDnB,IAAAK,mBAAA,GAAAL,OAAA;AAAA,IAAAM,KAAA,GAAAC,OAAA,CAAAP,OAAA;AAAA,SAAAJ,UAAAY,KAAA,EAAAC,KAAA,EAAAC,GAAA;EAAA,KAAAC,OAAA,EAAAC,UAAA,IAAAH,KAAA;EApCJ,QAAS;IACP,OAAO;MACTI,WAAA;QAWMC,QAAA;UACIF,UAAS,WAASG,WAAU;YAC9B,OAAM,CAAMA,WAA6B;UACzC;QAGA;MACJ;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AAA7B,kBAAA,CAAA6C,GAAA,EAAAC,WAAA;QAC1CC,OAAA,EAAAvB,MAAA;QACFwB,OAAA,GAAA1B,gCAAA,CAAAoB,OAAA;QACAtB,IAAA;QACA1B,KAAA;QACFkB,OAAA;QACFS,QAAO;QACLF,QAAQ;QACR;QAEA;QACA;QAEA8B,KAAM;UAMAC,SAAA;QACN;MACA,KAAO;IAAA;EACQ;AACL","ignoreList":[]}
|
package/dist/esm/useSwitch.mjs
CHANGED
|
@@ -10,56 +10,70 @@ 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 descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked");
|
|
24
|
+
const setChecked = descriptor.set;
|
|
24
25
|
if (prevChecked !== checked && setChecked) {
|
|
25
26
|
const event = new Event("click", {
|
|
26
27
|
bubbles
|
|
27
28
|
});
|
|
28
|
-
setChecked.call(input, checked)
|
|
29
|
+
setChecked.call(input, checked);
|
|
30
|
+
input.dispatchEvent(event);
|
|
29
31
|
}
|
|
30
|
-
}, [prevChecked, checked, bubbles])
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
}, [prevChecked, checked, bubbles]);
|
|
33
|
+
return (
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
/* @__PURE__ */
|
|
36
|
+
jsx("input", {
|
|
37
|
+
type: "checkbox",
|
|
38
|
+
"aria-hidden": true,
|
|
39
|
+
defaultChecked: checked,
|
|
40
|
+
...inputProps,
|
|
41
|
+
tabIndex: -1,
|
|
42
|
+
ref,
|
|
43
|
+
style: {
|
|
44
|
+
...props.style,
|
|
45
|
+
position: "absolute",
|
|
46
|
+
pointerEvents: "none",
|
|
47
|
+
opacity: 0,
|
|
48
|
+
margin: 0
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
);
|
|
48
52
|
};
|
|
49
53
|
function useSwitch(props, [checked, setChecked], ref) {
|
|
50
|
-
{
|
|
54
|
+
if (false) {
|
|
55
|
+
return {
|
|
56
|
+
switchProps: {
|
|
57
|
+
onPress() {
|
|
58
|
+
setChecked(prevChecked => !prevChecked);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
switchRef: ref,
|
|
62
|
+
bubbleInput: null
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
51
65
|
const {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
disabled,
|
|
67
|
+
name,
|
|
68
|
+
value,
|
|
69
|
+
required
|
|
70
|
+
} = props;
|
|
71
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
72
|
+
const [button, setButton] = React.useState(null);
|
|
73
|
+
const composedRefs = useComposedRefs(ref, setButton);
|
|
74
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
75
|
+
const labelId = useLabelContext(button);
|
|
76
|
+
const ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
63
77
|
return {
|
|
64
78
|
switchProps: {
|
|
65
79
|
role: "switch",
|
|
@@ -72,7 +86,11 @@ function useSwitch(props, [checked, setChecked], ref) {
|
|
|
72
86
|
} : {}),
|
|
73
87
|
"aria-labelledby": ariaLabelledBy,
|
|
74
88
|
onPress: composeEventHandlers(props.onPress, event => {
|
|
75
|
-
setChecked(prevChecked => !prevChecked)
|
|
89
|
+
setChecked(prevChecked => !prevChecked);
|
|
90
|
+
if (isWeb && isFormControl) {
|
|
91
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
92
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
93
|
+
}
|
|
76
94
|
})
|
|
77
95
|
},
|
|
78
96
|
switchRef: composedRefs,
|
|
@@ -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","
|
|
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","descriptor","Object","getOwnPropertyDescriptor","setChecked","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","switchProps","onPress","switchRef","bubbleInput","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","Boolean","closest","labelId","ariaLabelledBy","labeledBy","role","isPropagationStopped","stopPropagation","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;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U,KAAA,CAAMiC,oBAAA,CAAqB;YAItE,IAAI,CAACZ,gCAAA,CAAiC/B,OAAA,EAASU,KAAA,CAAMkC,eAAA,CAAgB;UACvE;QACF,CAAC;MACH;MACAnB,SAAA,EAAWU,YAAA;MAAA;AAAA;AAAA;MAIXT,WAAA,EACE5C,KAAA,IAASsD,aAAA,GACP,eAAAjD,GAAA,CAACG,WAAA;QACCE,OAAA,EAASwC,MAAA;QACTvC,OAAA,EAAS,CAACsC,gCAAA,CAAiC/B,OAAA;QAC3C4B,IAAA;QACAC,KAAA;QACAxC,OAAA;QACAyC,QAAA;QACAH,QAAA;QAIAV,KAAA,EAAO;UAAE4B,SAAA,EAAW;QAAoB;MAAA,CAC1C,IACE;IACR;EACF;AACF","ignoreList":[]}
|
|
@@ -1,20 +1,79 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
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";
|
|
2
6
|
import { usePrevious } from "@tamagui/use-previous";
|
|
3
7
|
import * as React from "react";
|
|
4
8
|
function useSwitch(props, param, ref) {
|
|
5
9
|
var [checked, setChecked] = param;
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
if (true) {
|
|
11
|
+
return {
|
|
12
|
+
switchProps: {
|
|
13
|
+
onPress() {
|
|
14
|
+
setChecked(function (prevChecked) {
|
|
15
|
+
return !prevChecked;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
switchRef: ref,
|
|
20
|
+
bubbleInput: null
|
|
21
|
+
};
|
|
22
|
+
} else {
|
|
23
|
+
var {
|
|
24
|
+
disabled,
|
|
25
|
+
name,
|
|
26
|
+
value,
|
|
27
|
+
required
|
|
28
|
+
} = props;
|
|
29
|
+
var hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
30
|
+
var [button, setButton] = React.useState(null);
|
|
31
|
+
var composedRefs = useComposedRefs(ref, setButton);
|
|
32
|
+
var isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
33
|
+
var labelId = useLabelContext(button);
|
|
34
|
+
var ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
35
|
+
return {
|
|
36
|
+
switchProps: {
|
|
37
|
+
role: "switch",
|
|
38
|
+
"aria-checked": checked,
|
|
39
|
+
...(isWeb ? {
|
|
40
|
+
tabIndex: disabled ? void 0 : 0,
|
|
41
|
+
"data-state": getState(checked),
|
|
42
|
+
"data-disabled": disabled ? "" : void 0,
|
|
43
|
+
disabled
|
|
44
|
+
} : {}),
|
|
45
|
+
"aria-labelledby": ariaLabelledBy,
|
|
46
|
+
onPress: composeEventHandlers(props.onPress, function (event) {
|
|
47
|
+
setChecked(function (prevChecked) {
|
|
48
|
+
return !prevChecked;
|
|
49
|
+
});
|
|
50
|
+
if (isWeb && isFormControl) {
|
|
51
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
52
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
},
|
|
56
|
+
switchRef: composedRefs,
|
|
57
|
+
/**
|
|
58
|
+
* insert as a sibling of your switch (should not be inside the switch)
|
|
59
|
+
*/
|
|
60
|
+
bubbleInput: isWeb && isFormControl ? /* @__PURE__ */_jsx(BubbleInput, {
|
|
61
|
+
control: button,
|
|
62
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
63
|
+
name,
|
|
64
|
+
value,
|
|
65
|
+
checked,
|
|
66
|
+
required,
|
|
67
|
+
disabled,
|
|
68
|
+
// We transform because the input is absolutely positioned but we have
|
|
69
|
+
// rendered it **after** the button. This pulls it back to sit on top
|
|
70
|
+
// of the button.
|
|
71
|
+
style: {
|
|
72
|
+
transform: "translateX(-100%)"
|
|
73
|
+
}
|
|
74
|
+
}) : null
|
|
75
|
+
};
|
|
76
|
+
}
|
|
18
77
|
}
|
|
19
78
|
export { useSwitch };
|
|
20
79
|
//# 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","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","useComposedRefs","isWeb","composeEventHandlers","useLabelContext","usePrevious","React","useSwitch","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput","disabled","name","value","required","hasConsumerStoppedPropagationRef","useRef","button","setButton","useState","composedRefs","isFormControl","Boolean","closest","labelId","ariaLabelledBy","labeledBy","role","tabIndex","getState","event","current","isPropagationStopped","stopPropagation","BubbleInput","control","bubbles","style","transform"],"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;IAWA,OAAM;MACJI,WAAQ,EAAS;QACXC,OAAMA,CAAA;UACNF,UAAA,WAAc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ACFnB,IAAA;QACAC,KAAA;QACAT,OAAA;QACFU,QAAA;QACFH,QAAO;QACL;QACA;QAEA;QACA0B,KAAM;UAEAC,SAAA;QAMN;MACA,KAAM;IACN;EAAO;AACQ;AACL,SACUtC,SACZ","ignoreList":[]}
|
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,56 +10,70 @@ 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 descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked");
|
|
24
|
+
const setChecked = descriptor.set;
|
|
24
25
|
if (prevChecked !== checked && setChecked) {
|
|
25
26
|
const event = new Event("click", {
|
|
26
27
|
bubbles
|
|
27
28
|
});
|
|
28
|
-
setChecked.call(input, checked)
|
|
29
|
+
setChecked.call(input, checked);
|
|
30
|
+
input.dispatchEvent(event);
|
|
29
31
|
}
|
|
30
|
-
}, [prevChecked, checked, bubbles])
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
}, [prevChecked, checked, bubbles]);
|
|
33
|
+
return (
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
/* @__PURE__ */
|
|
36
|
+
jsx("input", {
|
|
37
|
+
type: "checkbox",
|
|
38
|
+
"aria-hidden": true,
|
|
39
|
+
defaultChecked: checked,
|
|
40
|
+
...inputProps,
|
|
41
|
+
tabIndex: -1,
|
|
42
|
+
ref,
|
|
43
|
+
style: {
|
|
44
|
+
...props.style,
|
|
45
|
+
position: "absolute",
|
|
46
|
+
pointerEvents: "none",
|
|
47
|
+
opacity: 0,
|
|
48
|
+
margin: 0
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
);
|
|
48
52
|
};
|
|
49
53
|
function useSwitch(props, [checked, setChecked], ref) {
|
|
50
|
-
{
|
|
54
|
+
if (false) {
|
|
55
|
+
return {
|
|
56
|
+
switchProps: {
|
|
57
|
+
onPress() {
|
|
58
|
+
setChecked(prevChecked => !prevChecked);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
switchRef: ref,
|
|
62
|
+
bubbleInput: null
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
51
65
|
const {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
disabled,
|
|
67
|
+
name,
|
|
68
|
+
value,
|
|
69
|
+
required
|
|
70
|
+
} = props;
|
|
71
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
72
|
+
const [button, setButton] = React.useState(null);
|
|
73
|
+
const composedRefs = useComposedRefs(ref, setButton);
|
|
74
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
75
|
+
const labelId = useLabelContext(button);
|
|
76
|
+
const ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
63
77
|
return {
|
|
64
78
|
switchProps: {
|
|
65
79
|
role: "switch",
|
|
@@ -72,7 +86,11 @@ function useSwitch(props, [checked, setChecked], ref) {
|
|
|
72
86
|
} : {}),
|
|
73
87
|
"aria-labelledby": ariaLabelledBy,
|
|
74
88
|
onPress: composeEventHandlers(props.onPress, event => {
|
|
75
|
-
setChecked(prevChecked => !prevChecked)
|
|
89
|
+
setChecked(prevChecked => !prevChecked);
|
|
90
|
+
if (isWeb && isFormControl) {
|
|
91
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
92
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
93
|
+
}
|
|
76
94
|
})
|
|
77
95
|
},
|
|
78
96
|
switchRef: composedRefs,
|
|
@@ -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","
|
|
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","descriptor","Object","getOwnPropertyDescriptor","setChecked","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","switchProps","onPress","switchRef","bubbleInput","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","Boolean","closest","labelId","ariaLabelledBy","labeledBy","role","isPropagationStopped","stopPropagation","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,OAAOA,OAAA,GAAU,YAAY;AAC/B;AAWA,MAAMC,WAAA,GAAeC,KAAA,IAA4B;EAC/C,MAAM;IAAEC,OAAA;IAASH,OAAA;IAASI,OAAA,GAAU;IAAM,GAAGC;EAAW,IAAIH,KAAA;EAC5D,MAAMI,GAAA,GAAMT,KAAA,CAAMU,MAAA,CAAyB,IAAI;EAC/C,MAAMC,WAAA,GAAcZ,WAAA,CAAYI,OAAO;EAGvCH,KAAA,CAAMY,SAAA,CAAU,MAAM;IACpB,MAAMC,KAAA,GAAQJ,GAAA,CAAIK,OAAA;IAClB,MAAMC,UAAA,GAAaC,MAAA,CAAOC,gBAAA,CAAiBC,SAAA;IAC3C,MAAMC,UAAA,GAAaC,MAAA,CAAOC,wBAAA,CACxBN,UAAA,EACA,SAC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GACEK,OAAA,CAAQL,MAAA,CAAOM,OAAA,CAAQ,MAAM,CAAC,IAC9B,OACF;IAEJ,MAAMC,OAAA,GAAUvD,eAAA,CAAgBgD,MAAM;IACtC,MAAMQ,cAAA,GAAiBjD,KAAA,CAAM,iBAAiB,KAAKA,KAAA,CAAMkD,SAAA,IAAaF,OAAA;IACtE,OAAO;MACLhB,WAAA,EAAa;QACXmB,IAAA,EAAM;QACN,gBAAgBrD,OAAA;QAChB,IAAIP,KAAA,GACA;UACEkC,QAAA,EAAUW,QAAA,GAAW,SAAY;UACjC,cAAcvC,QAAA,CAASC,OAAO;UAC9B,iBAAiBsC,QAAA,GAAW,KAAK;UACjCA;QACF,IACA,CAAC;QACL,mBAAmBa,cAAA;QACnBhB,OAAA,EAASzC,oBAAA,CAAqBQ,KAAA,CAAMiC,OAAA,EAAUd,KAAA,IAAiC;UAC7EF,UAAA,CAAYX,WAAA,IAAgB,CAACA,WAAW;UACxC,IAAIf,KAAA,IAASsD,aAAA,EAAe;YAC1BL,gCAAA,CAAiC/B,OAAA,GAAUU,KAAA,CAAMiC,oBAAA,CAAqB;YAItE,IAAI,CAACZ,gCAAA,CAAiC/B,OAAA,EAASU,KAAA,CAAMkC,eAAA,CAAgB;UACvE;QACF,CAAC;MACH;MACAnB,SAAA,EAAWU,YAAA;MAAA;AAAA;AAAA;MAIXT,WAAA,EACE5C,KAAA,IAASsD,aAAA,GACP,eAAAjD,GAAA,CAACG,WAAA;QACCE,OAAA,EAASwC,MAAA;QACTvC,OAAA,EAAS,CAACsC,gCAAA,CAAiC/B,OAAA;QAC3C4B,IAAA;QACAC,KAAA;QACAxC,OAAA;QACAyC,QAAA;QACAH,QAAA;QAIAV,KAAA,EAAO;UAAE4B,SAAA,EAAW;QAAoB;MAAA,CAC1C,IACE;IACR;EACF;AACF","ignoreList":[]}
|
|
@@ -4,58 +4,115 @@ 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
|
-
var import_jsx_runtime = require("react/jsx-runtime")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
43
|
+
var import_constants = require("@tamagui/constants");
|
|
44
|
+
var import_helpers = require("@tamagui/helpers");
|
|
45
|
+
var import_label = require("@tamagui/label");
|
|
46
|
+
var import_use_previous = require("@tamagui/use-previous");
|
|
47
|
+
var React = __toESM(require("react"), 1);
|
|
46
48
|
function useSwitch(props, param, ref) {
|
|
47
49
|
var [checked, setChecked] = param;
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
if (true) {
|
|
51
|
+
return {
|
|
52
|
+
switchProps: {
|
|
53
|
+
onPress() {
|
|
54
|
+
setChecked(function (prevChecked) {
|
|
55
|
+
return !prevChecked;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
switchRef: ref,
|
|
60
|
+
bubbleInput: null
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
var {
|
|
64
|
+
disabled,
|
|
65
|
+
name,
|
|
66
|
+
value,
|
|
67
|
+
required
|
|
68
|
+
} = props;
|
|
69
|
+
var hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
70
|
+
var [button, setButton] = React.useState(null);
|
|
71
|
+
var composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);
|
|
72
|
+
var isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
73
|
+
var labelId = (0, import_label.useLabelContext)(button);
|
|
74
|
+
var ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
75
|
+
return {
|
|
76
|
+
switchProps: {
|
|
77
|
+
role: "switch",
|
|
78
|
+
"aria-checked": checked,
|
|
79
|
+
...(import_constants.isWeb ? {
|
|
80
|
+
tabIndex: disabled ? void 0 : 0,
|
|
81
|
+
"data-state": getState(checked),
|
|
82
|
+
"data-disabled": disabled ? "" : void 0,
|
|
83
|
+
disabled
|
|
84
|
+
} : {}),
|
|
85
|
+
"aria-labelledby": ariaLabelledBy,
|
|
86
|
+
onPress: (0, import_helpers.composeEventHandlers)(props.onPress, function (event) {
|
|
87
|
+
setChecked(function (prevChecked) {
|
|
88
|
+
return !prevChecked;
|
|
89
|
+
});
|
|
90
|
+
if (import_constants.isWeb && isFormControl) {
|
|
91
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
92
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
switchRef: composedRefs,
|
|
97
|
+
/**
|
|
98
|
+
* insert as a sibling of your switch (should not be inside the switch)
|
|
99
|
+
*/
|
|
100
|
+
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(BubbleInput, {
|
|
101
|
+
control: button,
|
|
102
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
103
|
+
name,
|
|
104
|
+
value,
|
|
105
|
+
checked,
|
|
106
|
+
required,
|
|
107
|
+
disabled,
|
|
108
|
+
// We transform because the input is absolutely positioned but we have
|
|
109
|
+
// rendered it **after** the button. This pulls it back to sit on top
|
|
110
|
+
// of the button.
|
|
111
|
+
style: {
|
|
112
|
+
transform: "translateX(-100%)"
|
|
113
|
+
}
|
|
114
|
+
}) : null
|
|
115
|
+
};
|
|
116
|
+
}
|
|
60
117
|
}
|
|
61
118
|
//# 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","import_jsx_runtime","require","import_compose_refs","import_constants","import_helpers","import_label","import_use_previous","React","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput","disabled","required","hasConsumerStoppedPropagationRef","button","setButton","composedRefs","isFormControl","labelId","ariaLabelledBy"],"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;
|
|
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","import_jsx_runtime","require","import_compose_refs","import_constants","import_helpers","import_label","import_use_previous","React","props","param","ref","checked","setChecked","switchProps","onPress","prevChecked","switchRef","bubbleInput","disabled","required","hasConsumerStoppedPropagationRef","useRef","button","setButton","useState","composedRefs","useComposedRefs","isFormControl","isWeb","Boolean","closest","labelId","useLabelContext","ariaLabelledBy","labeledBy","role","tabIndex","getState","composeEventHandlers","event","current","isPropagationStopped","stopPropagation","jsx","BubbleInput","control","bubbles","style","transform"],"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,CAAAC,MAAS,EAAAC,GAAsB;EACtC,SAAOC,IAAA,IAAUD,GAAA,EACnBb,SAAA,CAAAY,MAAA,EAAAE,IAAA;IAAAC,GAAA,EAAAF,GAAA,CAAAC,IAAA;IAAAE,UAAA;EAAA;AAWA;AACE,IAAAC,WAAQ,GAAAA,CAASC,EAAA,EAAAC,IAAA,EAASC,MAAA,EAAAC,IAAU,KAAM;EAC1C,IAAAF,IAAM,IAAM,OAAMA,IAAA,KAAyB,QAAI,WAAAA,IAAA;IAC/C,KAAM,IAAAG,GAAA,IAAAlB,iBAA0B,CAAAe,IAAO,GAGvC,IAAM,CAAAX,YAAU,CAAMe,IAAA,CAAAL,EAAA,EAAAI,GAAA,KAAAA,GAAA,KAAAF,MAAA,EACpBpB,SAAM,CAAQkB,EAAA,EAAII,GAAA;MAAAP,GAAA,EAAAA,CAAA,KAAAI,IAAA,CAAAG,GAAA;MAAAN,UAAA,IAAAK,IAAA,GAAAnB,gBAAA,CAAAiB,IAAA,EAAAG,GAAA,MAAAD,IAAA,CAAAL;IAAA;EAClB;EACA,OAAAE,EAAM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AAA;QAAA;QACU;QACkC;QAC3C6B,KACA;UACAC,SAAA;QAAA;MACA,KACA;IAAA;EAIwC;AAAA","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.36-1775243248161",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"clean:build": "tamagui-build clean:build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tamagui/compose-refs": "2.0.0-rc.
|
|
40
|
-
"@tamagui/constants": "2.0.0-rc.
|
|
41
|
-
"@tamagui/helpers": "2.0.0-rc.
|
|
42
|
-
"@tamagui/label": "2.0.0-rc.
|
|
43
|
-
"@tamagui/use-previous": "2.0.0-rc.
|
|
39
|
+
"@tamagui/compose-refs": "2.0.0-rc.36-1775243248161",
|
|
40
|
+
"@tamagui/constants": "2.0.0-rc.36-1775243248161",
|
|
41
|
+
"@tamagui/helpers": "2.0.0-rc.36-1775243248161",
|
|
42
|
+
"@tamagui/label": "2.0.0-rc.36-1775243248161",
|
|
43
|
+
"@tamagui/use-previous": "2.0.0-rc.36-1775243248161"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@tamagui/build": "2.0.0-rc.
|
|
46
|
+
"@tamagui/build": "2.0.0-rc.36-1775243248161",
|
|
47
47
|
"react": ">=19",
|
|
48
48
|
"react-native": "0.83.2"
|
|
49
49
|
},
|