@tamagui/switch-headless 1.114.4 → 1.115.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") 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);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./useSwitch.cjs"), module.exports);
|
|
@@ -0,0 +1,130 @@
|
|
|
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,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var useSwitch_exports = {};
|
|
33
|
+
__export(useSwitch_exports, {
|
|
34
|
+
useSwitch: () => useSwitch
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(useSwitch_exports);
|
|
37
|
+
var import_compose_refs = require("@tamagui/compose-refs"),
|
|
38
|
+
import_constants = require("@tamagui/constants"),
|
|
39
|
+
import_helpers = require("@tamagui/helpers"),
|
|
40
|
+
import_label = require("@tamagui/label"),
|
|
41
|
+
import_use_previous = require("@tamagui/use-previous"),
|
|
42
|
+
React = __toESM(require("react")),
|
|
43
|
+
import_jsx_runtime =
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
require("react/jsx-runtime");
|
|
46
|
+
function getState(checked) {
|
|
47
|
+
return checked ? "checked" : "unchecked";
|
|
48
|
+
}
|
|
49
|
+
const BubbleInput = props => {
|
|
50
|
+
const {
|
|
51
|
+
control,
|
|
52
|
+
checked,
|
|
53
|
+
bubbles = !0,
|
|
54
|
+
...inputProps
|
|
55
|
+
} = props,
|
|
56
|
+
ref = React.useRef(null),
|
|
57
|
+
prevChecked = (0, import_use_previous.usePrevious)(checked);
|
|
58
|
+
return React.useEffect(() => {
|
|
59
|
+
const input = ref.current,
|
|
60
|
+
inputProto = window.HTMLInputElement.prototype,
|
|
61
|
+
setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
|
|
62
|
+
if (prevChecked !== checked && setChecked) {
|
|
63
|
+
const event = new Event("click", {
|
|
64
|
+
bubbles
|
|
65
|
+
});
|
|
66
|
+
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
67
|
+
}
|
|
68
|
+
}, [prevChecked, checked, bubbles]), /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
|
|
69
|
+
type: "checkbox",
|
|
70
|
+
"aria-hidden": !0,
|
|
71
|
+
defaultChecked: checked,
|
|
72
|
+
...inputProps,
|
|
73
|
+
tabIndex: -1,
|
|
74
|
+
ref,
|
|
75
|
+
style: {
|
|
76
|
+
...props.style,
|
|
77
|
+
position: "absolute",
|
|
78
|
+
pointerEvents: "none",
|
|
79
|
+
opacity: 0,
|
|
80
|
+
margin: 0
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
function useSwitch(props, [checked, setChecked], ref) {
|
|
85
|
+
const {
|
|
86
|
+
disabled,
|
|
87
|
+
name,
|
|
88
|
+
value,
|
|
89
|
+
required
|
|
90
|
+
} = props,
|
|
91
|
+
hasConsumerStoppedPropagationRef = React.useRef(!1),
|
|
92
|
+
[button, setButton] = React.useState(null),
|
|
93
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton),
|
|
94
|
+
isFormControl = import_constants.isWeb ? button ? !!button.closest("form") : !0 : !1,
|
|
95
|
+
labelId = (0, import_label.useLabelContext)(button),
|
|
96
|
+
ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
97
|
+
return {
|
|
98
|
+
switchProps: {
|
|
99
|
+
role: "switch",
|
|
100
|
+
"aria-checked": checked,
|
|
101
|
+
...(import_constants.isWeb ? {
|
|
102
|
+
tabIndex: disabled ? void 0 : 0,
|
|
103
|
+
"data-state": getState(checked),
|
|
104
|
+
"data-disabled": disabled ? "" : void 0,
|
|
105
|
+
disabled
|
|
106
|
+
} : {}),
|
|
107
|
+
...props,
|
|
108
|
+
"aria-labelledby": ariaLabelledBy,
|
|
109
|
+
onPress: (0, import_helpers.composeEventHandlers)(props.onPress, event => {
|
|
110
|
+
setChecked(prevChecked => !prevChecked), import_constants.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
switchRef: composedRefs,
|
|
114
|
+
/**
|
|
115
|
+
* insert as a sibling of your switch (should not be inside the switch)
|
|
116
|
+
*/
|
|
117
|
+
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(BubbleInput, {
|
|
118
|
+
control: button,
|
|
119
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
120
|
+
name,
|
|
121
|
+
value,
|
|
122
|
+
checked,
|
|
123
|
+
required,
|
|
124
|
+
disabled,
|
|
125
|
+
style: {
|
|
126
|
+
transform: "translateX(-100%)"
|
|
127
|
+
}
|
|
128
|
+
}) : null
|
|
129
|
+
};
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/switch-headless",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.0",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -29,21 +29,22 @@
|
|
|
29
29
|
"react-native": "./dist/cjs/index.native.js",
|
|
30
30
|
"types": "./types/index.d.ts",
|
|
31
31
|
"import": "./dist/esm/index.mjs",
|
|
32
|
-
"require": "./dist/cjs/index.
|
|
32
|
+
"require": "./dist/cjs/index.cjs",
|
|
33
|
+
"default": "./dist/cjs/index.native.js"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@tamagui/compose-refs": "1.
|
|
37
|
-
"@tamagui/constants": "1.
|
|
38
|
-
"@tamagui/helpers": "1.
|
|
39
|
-
"@tamagui/label": "1.
|
|
40
|
-
"@tamagui/use-previous": "1.
|
|
37
|
+
"@tamagui/compose-refs": "1.115.0",
|
|
38
|
+
"@tamagui/constants": "1.115.0",
|
|
39
|
+
"@tamagui/helpers": "1.115.0",
|
|
40
|
+
"@tamagui/label": "1.115.0",
|
|
41
|
+
"@tamagui/use-previous": "1.115.0"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"react": "*"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@tamagui/build": "1.
|
|
47
|
+
"@tamagui/build": "1.115.0",
|
|
47
48
|
"react": "^18.2.0 || ^19.0.0",
|
|
48
49
|
"react-native": "0.74.1"
|
|
49
50
|
},
|
package/dist/cjs/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var src_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(src_exports);
|
|
14
|
-
__reExport(src_exports, require("./useSwitch"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/useSwitch.js
DELETED
|
@@ -1,102 +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")), import_jsx_runtime = (
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
require("react/jsx-runtime")
|
|
31
|
-
);
|
|
32
|
-
function getState(checked) {
|
|
33
|
-
return checked ? "checked" : "unchecked";
|
|
34
|
-
}
|
|
35
|
-
const BubbleInput = (props) => {
|
|
36
|
-
const { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
|
|
37
|
-
return React.useEffect(() => {
|
|
38
|
-
const input = ref.current, inputProto = window.HTMLInputElement.prototype, setChecked = Object.getOwnPropertyDescriptor(
|
|
39
|
-
inputProto,
|
|
40
|
-
"checked"
|
|
41
|
-
).set;
|
|
42
|
-
if (prevChecked !== checked && setChecked) {
|
|
43
|
-
const event = new Event("click", { bubbles });
|
|
44
|
-
setChecked.call(input, checked), input.dispatchEvent(event);
|
|
45
|
-
}
|
|
46
|
-
}, [prevChecked, checked, bubbles]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
47
|
-
"input",
|
|
48
|
-
{
|
|
49
|
-
type: "checkbox",
|
|
50
|
-
"aria-hidden": !0,
|
|
51
|
-
defaultChecked: checked,
|
|
52
|
-
...inputProps,
|
|
53
|
-
tabIndex: -1,
|
|
54
|
-
ref,
|
|
55
|
-
style: {
|
|
56
|
-
...props.style,
|
|
57
|
-
position: "absolute",
|
|
58
|
-
pointerEvents: "none",
|
|
59
|
-
opacity: 0,
|
|
60
|
-
margin: 0
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
function useSwitch(props, [checked, setChecked], ref) {
|
|
66
|
-
const { disabled, name, value, required } = props, hasConsumerStoppedPropagationRef = React.useRef(!1), [button, setButton] = React.useState(null), composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton), isFormControl = import_constants.isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = (0, import_label.useLabelContext)(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
|
|
67
|
-
return {
|
|
68
|
-
switchProps: {
|
|
69
|
-
role: "switch",
|
|
70
|
-
"aria-checked": checked,
|
|
71
|
-
...import_constants.isWeb ? {
|
|
72
|
-
tabIndex: disabled ? void 0 : 0,
|
|
73
|
-
"data-state": getState(checked),
|
|
74
|
-
"data-disabled": disabled ? "" : void 0,
|
|
75
|
-
disabled
|
|
76
|
-
} : {},
|
|
77
|
-
...props,
|
|
78
|
-
"aria-labelledby": ariaLabelledBy,
|
|
79
|
-
onPress: (0, import_helpers.composeEventHandlers)(props.onPress, (event) => {
|
|
80
|
-
setChecked((prevChecked) => !prevChecked), import_constants.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
81
|
-
})
|
|
82
|
-
},
|
|
83
|
-
switchRef: composedRefs,
|
|
84
|
-
/**
|
|
85
|
-
* insert as a sibling of your switch (should not be inside the switch)
|
|
86
|
-
*/
|
|
87
|
-
bubbleInput: import_constants.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
88
|
-
BubbleInput,
|
|
89
|
-
{
|
|
90
|
-
control: button,
|
|
91
|
-
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
92
|
-
name,
|
|
93
|
-
value,
|
|
94
|
-
checked,
|
|
95
|
-
required,
|
|
96
|
-
disabled,
|
|
97
|
-
style: { transform: "translateX(-100%)" }
|
|
98
|
-
}
|
|
99
|
-
) : null
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
//# sourceMappingURL=useSwitch.js.map
|
|
File without changes
|
|
File without changes
|