@tamagui/checkbox-headless 2.7.7 → 3.0.0-beta.637.1
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/BubbleInput.cjs +58 -71
- package/dist/cjs/BubbleInput.native.cjs +77 -0
- package/dist/cjs/BubbleInput.native.js +58 -70
- package/dist/cjs/BubbleInput.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +22 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useCheckbox.cjs +64 -80
- package/dist/cjs/useCheckbox.native.cjs +95 -0
- package/dist/cjs/useCheckbox.native.js +71 -86
- package/dist/cjs/useCheckbox.native.js.map +1 -1
- package/dist/cjs/utils.cjs +18 -19
- package/dist/cjs/utils.native.cjs +35 -0
- package/dist/cjs/utils.native.js +18 -18
- package/dist/cjs/utils.native.js.map +1 -1
- package/dist/esm/BubbleInput.mjs +42 -45
- package/dist/esm/BubbleInput.mjs.map +1 -1
- package/dist/esm/BubbleInput.native.js +43 -46
- package/dist/esm/BubbleInput.native.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.native.js +3 -3
- package/dist/esm/useCheckbox.mjs +48 -54
- package/dist/esm/useCheckbox.mjs.map +1 -1
- package/dist/esm/useCheckbox.native.js +56 -62
- package/dist/esm/useCheckbox.native.js.map +1 -1
- package/dist/esm/utils.mjs +3 -2
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/utils.native.js +3 -2
- package/dist/esm/utils.native.js.map +1 -1
- package/dist/jsx/BubbleInput.mjs +42 -45
- package/dist/jsx/BubbleInput.mjs.map +1 -1
- package/dist/jsx/BubbleInput.native.cjs +77 -0
- package/dist/jsx/BubbleInput.native.js +58 -70
- package/dist/jsx/BubbleInput.native.js.map +1 -1
- package/dist/jsx/index.js +3 -3
- package/dist/jsx/index.mjs +3 -3
- package/dist/jsx/index.native.cjs +22 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/useCheckbox.mjs +48 -54
- package/dist/jsx/useCheckbox.mjs.map +1 -1
- package/dist/jsx/useCheckbox.native.cjs +95 -0
- package/dist/jsx/useCheckbox.native.js +71 -86
- package/dist/jsx/useCheckbox.native.js.map +1 -1
- package/dist/jsx/utils.mjs +3 -2
- package/dist/jsx/utils.mjs.map +1 -1
- package/dist/jsx/utils.native.cjs +35 -0
- package/dist/jsx/utils.native.js +18 -18
- package/dist/jsx/utils.native.js.map +1 -1
- package/package.json +12 -12
- package/types/BubbleInput.d.ts +1 -1
- package/types/BubbleInput.d.ts.map +1 -1
- package/types/useCheckbox.d.ts +4 -4
- package/types/utils.d.ts +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
package/dist/cjs/useCheckbox.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -5,36 +6,27 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
30
26
|
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
28
|
var useCheckbox_exports = {};
|
|
35
|
-
__export(useCheckbox_exports, {
|
|
36
|
-
useCheckbox: () => useCheckbox
|
|
37
|
-
});
|
|
29
|
+
__export(useCheckbox_exports, { useCheckbox: () => useCheckbox });
|
|
38
30
|
module.exports = __toCommonJS(useCheckbox_exports);
|
|
39
31
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
40
32
|
var import_constants = require("@tamagui/constants");
|
|
@@ -45,58 +37,50 @@ var import_BubbleInput = require("./BubbleInput.cjs");
|
|
|
45
37
|
var import_utils = require("./utils.cjs");
|
|
46
38
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
39
|
function useCheckbox(props, [checked, setChecked], ref) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"data-disabled": disabled ? "" : void 0,
|
|
96
|
-
disabled,
|
|
97
|
-
onKeyDown: disabled ? void 0 : handleKeyDown
|
|
98
|
-
}),
|
|
99
|
-
onPress: disabled ? void 0 : handlePress
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
40
|
+
const { labelledBy: ariaLabelledby, name, required, disabled, value = "on", onCheckedChange, ...checkboxProps } = props;
|
|
41
|
+
const [button, setButton] = import_react.default.useState(null);
|
|
42
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);
|
|
43
|
+
const hasConsumerStoppedPropagationRef = import_react.default.useRef(false);
|
|
44
|
+
const isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
45
|
+
const labelId = (0, import_label.useLabelContext)(button);
|
|
46
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
47
|
+
const parentKeyDown = props.onKeyDown;
|
|
48
|
+
const handleKeyDown = (0, import_react.useMemo)(() => (0, import_helpers.composeEventHandlers)(parentKeyDown, (event) => {
|
|
49
|
+
if (event.key === "Enter") event.preventDefault();
|
|
50
|
+
}), [parentKeyDown]);
|
|
51
|
+
const handlePress = (0, import_react.useMemo)(() => (0, import_helpers.composeEventHandlers)(props.onPress, (event) => {
|
|
52
|
+
setChecked((prevChecked) => (0, import_utils.isIndeterminate)(prevChecked) ? true : !prevChecked);
|
|
53
|
+
if (isFormControl && "isPropagationStopped" in event) {
|
|
54
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
55
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
56
|
+
}
|
|
57
|
+
}), [isFormControl]);
|
|
58
|
+
return {
|
|
59
|
+
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {
|
|
60
|
+
isHidden: true,
|
|
61
|
+
control: button,
|
|
62
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
63
|
+
name,
|
|
64
|
+
value,
|
|
65
|
+
checked,
|
|
66
|
+
required,
|
|
67
|
+
disabled
|
|
68
|
+
}) : null,
|
|
69
|
+
checkboxRef: composedRefs,
|
|
70
|
+
checkboxProps: {
|
|
71
|
+
role: "checkbox",
|
|
72
|
+
"aria-labelledby": labelledBy,
|
|
73
|
+
"aria-checked": (0, import_utils.isIndeterminate)(checked) ? "mixed" : checked,
|
|
74
|
+
...checkboxProps,
|
|
75
|
+
...import_constants.isWeb && {
|
|
76
|
+
type: "button",
|
|
77
|
+
value,
|
|
78
|
+
"data-state": (0, import_utils.getState)(checked),
|
|
79
|
+
"data-disabled": disabled ? "" : void 0,
|
|
80
|
+
disabled,
|
|
81
|
+
onKeyDown: disabled ? void 0 : handleKeyDown
|
|
82
|
+
},
|
|
83
|
+
onPress: disabled ? void 0 : handlePress
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var useCheckbox_exports = {};
|
|
31
|
+
__export(useCheckbox_exports, { useCheckbox: () => useCheckbox });
|
|
32
|
+
module.exports = __toCommonJS(useCheckbox_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
35
|
+
var import_constants = require("@tamagui/constants");
|
|
36
|
+
var import_helpers = require("@tamagui/helpers");
|
|
37
|
+
var import_label = require("@tamagui/label");
|
|
38
|
+
var import_react = __toESM(require("react"), 1);
|
|
39
|
+
var import_BubbleInput = require("./BubbleInput.native.js");
|
|
40
|
+
var import_utils = require("./utils.native.js");
|
|
41
|
+
function useCheckbox(props, param, ref) {
|
|
42
|
+
var [checked, setChecked] = param;
|
|
43
|
+
var { labelledBy: ariaLabelledby, name, required, disabled, value = "on", onCheckedChange, ...checkboxProps } = props;
|
|
44
|
+
var [button, setButton] = import_react.default.useState(null);
|
|
45
|
+
var composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);
|
|
46
|
+
var hasConsumerStoppedPropagationRef = import_react.default.useRef(false);
|
|
47
|
+
var isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
48
|
+
var labelId = (0, import_label.useLabelContext)(button);
|
|
49
|
+
var labelledBy = ariaLabelledby || labelId;
|
|
50
|
+
var parentKeyDown = props.onKeyDown;
|
|
51
|
+
var handleKeyDown = (0, import_react.useMemo)(function() {
|
|
52
|
+
return (0, import_helpers.composeEventHandlers)(parentKeyDown, function(event) {
|
|
53
|
+
if (event.key === "Enter") event.preventDefault();
|
|
54
|
+
});
|
|
55
|
+
}, [parentKeyDown]);
|
|
56
|
+
var handlePress = (0, import_react.useMemo)(function() {
|
|
57
|
+
return (0, import_helpers.composeEventHandlers)(props.onPress, function(event) {
|
|
58
|
+
setChecked(function(prevChecked) {
|
|
59
|
+
return (0, import_utils.isIndeterminate)(prevChecked) ? true : !prevChecked;
|
|
60
|
+
});
|
|
61
|
+
if (isFormControl && "isPropagationStopped" in event) {
|
|
62
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
63
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}, [isFormControl]);
|
|
67
|
+
return {
|
|
68
|
+
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {
|
|
69
|
+
isHidden: true,
|
|
70
|
+
control: button,
|
|
71
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
72
|
+
name,
|
|
73
|
+
value,
|
|
74
|
+
checked,
|
|
75
|
+
required,
|
|
76
|
+
disabled
|
|
77
|
+
}) : null,
|
|
78
|
+
checkboxRef: composedRefs,
|
|
79
|
+
checkboxProps: {
|
|
80
|
+
role: "checkbox",
|
|
81
|
+
"aria-labelledby": labelledBy,
|
|
82
|
+
"aria-checked": (0, import_utils.isIndeterminate)(checked) ? "mixed" : checked,
|
|
83
|
+
...checkboxProps,
|
|
84
|
+
...import_constants.isWeb && {
|
|
85
|
+
type: "button",
|
|
86
|
+
value,
|
|
87
|
+
"data-state": (0, import_utils.getState)(checked),
|
|
88
|
+
"data-disabled": disabled ? "" : void 0,
|
|
89
|
+
disabled,
|
|
90
|
+
onKeyDown: disabled ? void 0 : handleKeyDown
|
|
91
|
+
},
|
|
92
|
+
onPress: disabled ? void 0 : handlePress
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,36 +8,27 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
14
15
|
};
|
|
15
16
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
23
24
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
32
28
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
30
|
var useCheckbox_exports = {};
|
|
37
|
-
__export(useCheckbox_exports, {
|
|
38
|
-
useCheckbox: () => useCheckbox
|
|
39
|
-
});
|
|
31
|
+
__export(useCheckbox_exports, { useCheckbox: () => useCheckbox });
|
|
40
32
|
module.exports = __toCommonJS(useCheckbox_exports);
|
|
41
33
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
34
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
@@ -47,66 +39,59 @@ var import_react = __toESM(require("react"), 1);
|
|
|
47
39
|
var import_BubbleInput = require("./BubbleInput.native.js");
|
|
48
40
|
var import_utils = require("./utils.native.js");
|
|
49
41
|
function useCheckbox(props, param, ref) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
"data-state": (0, import_utils.getState)(checked),
|
|
104
|
-
"data-disabled": disabled ? "" : void 0,
|
|
105
|
-
disabled,
|
|
106
|
-
onKeyDown: disabled ? void 0 : handleKeyDown
|
|
107
|
-
}),
|
|
108
|
-
onPress: disabled ? void 0 : handlePress
|
|
109
|
-
}
|
|
110
|
-
};
|
|
42
|
+
var [checked, setChecked] = param;
|
|
43
|
+
var { labelledBy: ariaLabelledby, name, required, disabled, value = "on", onCheckedChange, ...checkboxProps } = props;
|
|
44
|
+
var [button, setButton] = import_react.default.useState(null);
|
|
45
|
+
var composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);
|
|
46
|
+
var hasConsumerStoppedPropagationRef = import_react.default.useRef(false);
|
|
47
|
+
var isFormControl = import_constants.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
48
|
+
var labelId = (0, import_label.useLabelContext)(button);
|
|
49
|
+
var labelledBy = ariaLabelledby || labelId;
|
|
50
|
+
var parentKeyDown = props.onKeyDown;
|
|
51
|
+
var handleKeyDown = (0, import_react.useMemo)(function() {
|
|
52
|
+
return (0, import_helpers.composeEventHandlers)(parentKeyDown, function(event) {
|
|
53
|
+
if (event.key === "Enter") event.preventDefault();
|
|
54
|
+
});
|
|
55
|
+
}, [parentKeyDown]);
|
|
56
|
+
var handlePress = (0, import_react.useMemo)(function() {
|
|
57
|
+
return (0, import_helpers.composeEventHandlers)(props.onPress, function(event) {
|
|
58
|
+
setChecked(function(prevChecked) {
|
|
59
|
+
return (0, import_utils.isIndeterminate)(prevChecked) ? true : !prevChecked;
|
|
60
|
+
});
|
|
61
|
+
if (isFormControl && "isPropagationStopped" in event) {
|
|
62
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
63
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}, [isFormControl]);
|
|
67
|
+
return {
|
|
68
|
+
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {
|
|
69
|
+
isHidden: true,
|
|
70
|
+
control: button,
|
|
71
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
72
|
+
name,
|
|
73
|
+
value,
|
|
74
|
+
checked,
|
|
75
|
+
required,
|
|
76
|
+
disabled
|
|
77
|
+
}) : null,
|
|
78
|
+
checkboxRef: composedRefs,
|
|
79
|
+
checkboxProps: {
|
|
80
|
+
role: "checkbox",
|
|
81
|
+
"aria-labelledby": labelledBy,
|
|
82
|
+
"aria-checked": (0, import_utils.isIndeterminate)(checked) ? "mixed" : checked,
|
|
83
|
+
...checkboxProps,
|
|
84
|
+
...import_constants.isWeb && {
|
|
85
|
+
type: "button",
|
|
86
|
+
value,
|
|
87
|
+
"data-state": (0, import_utils.getState)(checked),
|
|
88
|
+
"data-disabled": disabled ? "" : void 0,
|
|
89
|
+
disabled,
|
|
90
|
+
onKeyDown: disabled ? void 0 : handleKeyDown
|
|
91
|
+
},
|
|
92
|
+
onPress: disabled ? void 0 : handlePress
|
|
93
|
+
}
|
|
94
|
+
};
|
|
111
95
|
}
|
|
96
|
+
|
|
112
97
|
//# sourceMappingURL=useCheckbox.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useCheckbox.native.js","names":[],"sources":["cjs/useCheckbox.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useCheckbox_exports = {};\n__export(useCheckbox_exports, {\n useCheckbox: () => useCheckbox\n});\nmodule.exports = __toCommonJS(useCheckbox_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_compose_refs = require(\"@tamagui/compose-refs\");\nvar import_constants = require(\"@tamagui/constants\");\nvar import_helpers = require(\"@tamagui/helpers\");\nvar import_label = require(\"@tamagui/label\");\nvar import_react = __toESM(require(\"react\"), 1);\nvar import_BubbleInput = require(\"./BubbleInput\");\nvar import_utils = require(\"./utils\");\nfunction useCheckbox(props, param, ref) {\n var [checked, setChecked] = param;\n var { labelledBy: ariaLabelledby, name, required, disabled, value = \"on\", onCheckedChange, ...checkboxProps } = props;\n var [button, setButton] = import_react.default.useState(null);\n var composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton);\n var hasConsumerStoppedPropagationRef = import_react.default.useRef(false);\n var isFormControl = import_constants.isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n var labelId = (0, import_label.useLabelContext)(button);\n var labelledBy = ariaLabelledby || labelId;\n var parentKeyDown = props.onKeyDown;\n var handleKeyDown = (0, import_react.useMemo)(function() {\n return (0, import_helpers.composeEventHandlers)(parentKeyDown, function(event) {\n if (event.key === \"Enter\") event.preventDefault();\n });\n }, [\n parentKeyDown\n ]);\n var handlePress = (0, import_react.useMemo)(function() {\n return (0, import_helpers.composeEventHandlers)(props.onPress, function(event) {\n setChecked(function(prevChecked) {\n return (0, import_utils.isIndeterminate)(prevChecked) ? true : !prevChecked;\n });\n if (isFormControl && \"isPropagationStopped\" in event) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n }\n });\n }, [\n isFormControl\n ]);\n return {\n bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {\n isHidden: true,\n control: button,\n bubbles: !hasConsumerStoppedPropagationRef.current,\n name,\n value,\n checked,\n required,\n disabled\n }) : null,\n checkboxRef: composedRefs,\n checkboxProps: {\n role: \"checkbox\",\n \"aria-labelledby\": labelledBy,\n \"aria-checked\": (0, import_utils.isIndeterminate)(checked) ? \"mixed\" : checked,\n ...checkboxProps,\n ...import_constants.isWeb && {\n type: \"button\",\n value,\n \"data-state\": (0, import_utils.getState)(checked),\n \"data-disabled\": disabled ? \"\" : void 0,\n disabled,\n onKeyDown: disabled ? void 0 : handleKeyDown\n },\n onPress: disabled ? void 0 : handlePress\n }\n };\n}\n//# sourceMappingURL=useCheckbox.js.map\n"],"mappings":"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"}
|
package/dist/cjs/utils.cjs
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
+
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
6
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
10
11
|
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
19
20
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
22
|
var utils_exports = {};
|
|
24
23
|
__export(utils_exports, {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
getState: () => getState,
|
|
25
|
+
isIndeterminate: () => isIndeterminate
|
|
27
26
|
});
|
|
28
27
|
module.exports = __toCommonJS(utils_exports);
|
|
29
28
|
function isIndeterminate(checked) {
|
|
30
|
-
|
|
29
|
+
return checked === "indeterminate";
|
|
31
30
|
}
|
|
32
31
|
function getState(checked) {
|
|
33
|
-
|
|
34
|
-
}
|
|
32
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
33
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var utils_exports = {};
|
|
25
|
+
__export(utils_exports, {
|
|
26
|
+
getState: () => getState,
|
|
27
|
+
isIndeterminate: () => isIndeterminate
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(utils_exports);
|
|
30
|
+
function isIndeterminate(checked) {
|
|
31
|
+
return checked === "indeterminate";
|
|
32
|
+
}
|
|
33
|
+
function getState(checked) {
|
|
34
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
35
|
+
}
|
package/dist/cjs/utils.native.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
24
|
var utils_exports = {};
|
|
26
25
|
__export(utils_exports, {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
getState: () => getState,
|
|
27
|
+
isIndeterminate: () => isIndeterminate
|
|
29
28
|
});
|
|
30
29
|
module.exports = __toCommonJS(utils_exports);
|
|
31
30
|
function isIndeterminate(checked) {
|
|
32
|
-
|
|
31
|
+
return checked === "indeterminate";
|
|
33
32
|
}
|
|
34
33
|
function getState(checked) {
|
|
35
|
-
|
|
34
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
36
35
|
}
|
|
36
|
+
|
|
37
37
|
//# sourceMappingURL=utils.native.js.map
|