@tamagui/switch-headless 1.116.0 → 1.116.2

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