@tamagui/switch-headless 2.0.0-rc.36 → 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.
@@ -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
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
11
- },
12
- __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
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: !0
16
+ value: true
15
17
  }), mod);
16
18
  var index_exports = {};
17
19
  module.exports = __toCommonJS(index_exports);
@@ -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
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
13
- },
14
- __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
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: !0
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":";;;;;;;;;;;;;;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":[]}
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":[]}
@@ -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
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
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, {
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
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  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);
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
- 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"), 1),
43
- import_jsx_runtime =
44
- // @ts-ignore
45
- require("react/jsx-runtime");
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
- 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;
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), input.dispatchEvent(event);
69
+ setChecked.call(input, checked);
70
+ input.dispatchEvent(event);
67
71
  }
68
- }, [prevChecked, checked, bubbles]), /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
72
+ }, [prevChecked, checked, bubbles]);
73
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
69
74
  type: "checkbox",
70
- "aria-hidden": !0,
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
- disabled,
88
- name,
89
- value,
90
- required
91
- } = props,
92
- hasConsumerStoppedPropagationRef = React.useRef(!1),
93
- [button, setButton] = React.useState(null),
94
- composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton),
95
- isFormControl = import_constants.isWeb ? button ? !!button.closest("form") : !0 : !1,
96
- labelId = (0, import_label.useLabelContext)(button),
97
- ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
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), import_constants.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
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
- __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: !0
13
- });
14
- },
15
- __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
21
- };
21
+ }
22
+ return to;
23
+ };
22
24
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
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: !0
30
- }) : target, mod)),
31
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: !0
33
- }), mod);
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
- import_compose_refs = require("@tamagui/compose-refs"),
41
- import_constants = require("@tamagui/constants"),
42
- import_helpers = require("@tamagui/helpers"),
43
- import_label = require("@tamagui/label"),
44
- import_use_previous = require("@tamagui/use-previous"),
45
- React = __toESM(require("react"), 1);
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 (1) return {
49
- switchProps: {
50
- onPress() {
51
- setChecked(function (prevChecked) {
52
- return !prevChecked;
53
- });
54
- }
55
- },
56
- switchRef: ref,
57
- bubbleInput: null
58
- };
59
- var disabled, name, value, required, hasConsumerStoppedPropagationRef, button, setButton, composedRefs, isFormControl, labelId, ariaLabelledBy;
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,iBAAA;AAAAC,QAAA,CAAAD,iBAAA;EAAAE,SAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAgC,CAAAK,iBAAA;AA4D5B,IAAAK,kBAAA,GAAAC,OAAA;EAAAC,mBAAA,GAAAD,OAAA;EAAAE,gBAAA,GAAAF,OAAA;EAAAG,cAAA,GAAAH,OAAA;EAAAI,YAAA,GAAAJ,OAAA;EAAAK,mBAAA,GAAAL,OAAA;EAAAM,KAAA,GAAAC,OAAA,CAAAP,OAAA;AAAA,SAAAJ,UAAAY,KAAA,EAAAC,KAAA,EAAAC,GAAA;EAAA,KAAAC,OAAA,EAAAC,UAAA,IAAAH,KAAA;EApCJ,OACE,OAAO;IACTI,WAAA;MAWMC,QAAA;QACIF,UAAS,WAASG,WAAU,EAAM;UAK1C,OAAM,CAAAA,WAAgB;QACd;MAGJ;IACA;IAE4BC,SAAA,EAAAN,GAAA;IAC9BO,WAAI;EACF;EACA,IAAAC,QAAA,EAAAC,IAAW,EAAK1B,KAAA,EAAO2B,QAAO,EAC9BC,gCAAyB,EAAAC,MAAA,EAAAC,SAAA,EAAAC,YAAA,EAAAC,aAAA,EAAAC,OAAA,EAAAC,cAAA;AAAA","ignoreList":[]}
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;MACAC,SAAM,EAAAN,GAAA;MACNO,WAAM;IAAoB;EACxB,OACA;IACF;MAAAC,QAAA;MAA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,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":[]}
@@ -10,56 +10,70 @@ function getState(checked) {
10
10
  }
11
11
  const BubbleInput = props => {
12
12
  const {
13
- control,
14
- checked,
15
- bubbles = !0,
16
- ...inputProps
17
- } = props,
18
- ref = React.useRef(null),
19
- prevChecked = usePrevious(checked);
20
- return React.useEffect(() => {
21
- const input = ref.current,
22
- inputProto = window.HTMLInputElement.prototype,
23
- setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
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), input.dispatchEvent(event);
29
+ setChecked.call(input, checked);
30
+ input.dispatchEvent(event);
29
31
  }
30
- }, [prevChecked, checked, bubbles]),
31
- // @ts-ignore
32
- /* @__PURE__ */
33
- jsx("input", {
34
- type: "checkbox",
35
- "aria-hidden": !0,
36
- defaultChecked: checked,
37
- ...inputProps,
38
- tabIndex: -1,
39
- ref,
40
- style: {
41
- ...props.style,
42
- position: "absolute",
43
- pointerEvents: "none",
44
- opacity: 0,
45
- margin: 0
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
- disabled,
53
- name,
54
- value,
55
- required
56
- } = props,
57
- hasConsumerStoppedPropagationRef = React.useRef(!1),
58
- [button, setButton] = React.useState(null),
59
- composedRefs = useComposedRefs(ref, setButton),
60
- isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
61
- labelId = useLabelContext(button),
62
- ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
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), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
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","setChecked","Object","getOwnPropertyDescriptor","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","closest","labelId","ariaLabelledBy","labeledBy","switchProps","role","onPress","isPropagationStopped","stopPropagation","switchRef","bubbleInput","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;MAAEC,OAAA;MAASH,OAAA;MAASI,OAAA,GAAU;MAAM,GAAGC;IAAW,IAAIH,KAAA;IACtDI,GAAA,GAAMT,KAAA,CAAMU,MAAA,CAAyB,IAAI;IACzCC,WAAA,GAAcZ,WAAA,CAAYI,OAAO;EAGvC,OAAAH,KAAA,CAAMY,SAAA,CAAU,MAAM;IACpB,MAAMC,KAAA,GAAQJ,GAAA,CAAIK,OAAA;MACZC,UAAA,GAAaC,MAAA,CAAOC,gBAAA,CAAiBC,SAAA;MAKrCC,UAAA,GAJaC,MAAA,CAAOC,wBAAA,CACxBN,UAAA,EACA,SACF,EAC8BO,GAAA;IAC9B,IAAIX,WAAA,KAAgBR,OAAA,IAAWgB,UAAA,EA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Y;UACjC,cAAclC,QAAA,CAASC,OAAO;UAC9B,iBAAiBiC,QAAA,GAAW,KAAK;UACjCA;QACF,IACA,CAAC;QACL,mBAAmBY,cAAA;QACnBI,OAAA,EAASvD,oBAAA,CAAqBQ,KAAA,CAAM+C,OAAA,EAAU7B,KAAA,IAAiC;UAC7EJ,UAAA,CAAYR,WAAA,IAAgB,CAACA,WAAW,GACpCf,KAAA,IAASiD,aAAA,KACXL,gCAAA,CAAiC1B,OAAA,GAAUS,KAAA,CAAM8B,oBAAA,CAAqB,GAIjEb,gCAAA,CAAiC1B,OAAA,IAASS,KAAA,CAAM+B,eAAA,CAAgB;QAEzE,CAAC;MACH;MACAC,SAAA,EAAWX,YAAA;MAAA;AAAA;AAAA;MAIXY,WAAA,EACE5D,KAAA,IAASiD,aAAA,GACP,eAAA5C,GAAA,CAACG,WAAA;QACCE,OAAA,EAASmC,MAAA;QACTlC,OAAA,EAAS,CAACiC,gCAAA,CAAiC1B,OAAA;QAC3CuB,IAAA;QACAC,KAAA;QACAnC,OAAA;QACAoC,QAAA;QACAH,QAAA;QAIAN,KAAA,EAAO;UAAE2B,SAAA,EAAW;QAAoB;MAAA,CAC1C,IACE;IACR;EACF;AACF","ignoreList":[]}
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,SA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AAgB,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":[]}
@@ -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 (1) return {
7
- switchProps: {
8
- onPress() {
9
- setChecked(function (prevChecked) {
10
- return !prevChecked;
11
- });
12
- }
13
- },
14
- switchRef: ref,
15
- bubbleInput: null
16
- };
17
- var disabled, name, value, required, hasConsumerStoppedPropagationRef, button, setButton, composedRefs, isFormControl, labelId, ariaLabelledBy;
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;AAKhC,SAAAC,WAAY,QAAW;AAuDnB,YAAAC,KAAA;AApCJ,SAASC,SAASA,CAAAC,KAAA,EAAAC,KAAsB,EAAAC,GAAA;EACtC,KAAAC,OAAO,EAAAC,UAAU,IAAAH,KAAY;EAC/B,OAWA,OAAM;IACJI,WAAQ,EAAS;MAKjBC,OAAMA,CAAA;QACEF,UAAQ,WAAIG,WACZ;UAEJ,QAAAA,WAAA;QACA;MAE4B;IAC9B;IACEC,SAAM,EAAAN,GAAQ;IACdO,WAAW;EAEb;EACF,IAAIC,QAAA,EAAAC,IAAa,EAAAC,KAAA,EAASC,QAAQ,EAAAC,gCAAA,EAAAC,MAAA,EAAAC,SAAA,EAAAC,YAAA,EAAAC,aAAA,EAAAC,OAAA,EAAAC,cAAA;AAAA;AAIhC,SAACrB,SAAA","ignoreList":[]}
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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ACRC,OAAA,EAAAlB,MAAY;QACdmB,OAAA,GAAArB,gCAAA,CAAAgB,OAAA;QACFnB,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":[]}
@@ -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
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
13
- },
14
- __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
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: !0
18
+ value: true
17
19
  }), mod);
18
20
  var index_exports = {};
19
21
  module.exports = __toCommonJS(index_exports);
@@ -10,56 +10,70 @@ function getState(checked) {
10
10
  }
11
11
  const BubbleInput = props => {
12
12
  const {
13
- control,
14
- checked,
15
- bubbles = !0,
16
- ...inputProps
17
- } = props,
18
- ref = React.useRef(null),
19
- prevChecked = usePrevious(checked);
20
- return React.useEffect(() => {
21
- const input = ref.current,
22
- inputProto = window.HTMLInputElement.prototype,
23
- setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
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), input.dispatchEvent(event);
29
+ setChecked.call(input, checked);
30
+ input.dispatchEvent(event);
29
31
  }
30
- }, [prevChecked, checked, bubbles]),
31
- // @ts-ignore
32
- /* @__PURE__ */
33
- jsx("input", {
34
- type: "checkbox",
35
- "aria-hidden": !0,
36
- defaultChecked: checked,
37
- ...inputProps,
38
- tabIndex: -1,
39
- ref,
40
- style: {
41
- ...props.style,
42
- position: "absolute",
43
- pointerEvents: "none",
44
- opacity: 0,
45
- margin: 0
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
- disabled,
53
- name,
54
- value,
55
- required
56
- } = props,
57
- hasConsumerStoppedPropagationRef = React.useRef(!1),
58
- [button, setButton] = React.useState(null),
59
- composedRefs = useComposedRefs(ref, setButton),
60
- isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
61
- labelId = useLabelContext(button),
62
- ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
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), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
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","setChecked","Object","getOwnPropertyDescriptor","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","closest","labelId","ariaLabelledBy","labeledBy","switchProps","role","onPress","isPropagationStopped","stopPropagation","switchRef","bubbleInput","transform"],"sources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;AAAA;AAAA;MAIXY,WAAA,EACE5D,KAAA,IAASiD,aAAA,GACP,eAAA5C,GAAA,CAACG,WAAA;QACCE,OAAA,EAASmC,MAAA;QACTlC,OAAA,EAAS,CAACiC,gCAAA,CAAiC1B,OAAA;QAC3CuB,IAAA;QACAC,KAAA;QACAnC,OAAA;QACAoC,QAAA;QACAH,QAAA;QAIAN,KAAA,EAAO;UAAE2B,SAAA,EAAW;QAAoB;MAAA,CAC1C,IACE;IACR;EACF;AACF","ignoreList":[]}
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,OA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,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
- __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: !0
13
- });
14
- },
15
- __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
21
- };
21
+ }
22
+ return to;
23
+ };
22
24
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
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: !0
30
- }) : target, mod)),
31
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: !0
33
- }), mod);
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
- import_compose_refs = require("@tamagui/compose-refs"),
41
- import_constants = require("@tamagui/constants"),
42
- import_helpers = require("@tamagui/helpers"),
43
- import_label = require("@tamagui/label"),
44
- import_use_previous = require("@tamagui/use-previous"),
45
- React = __toESM(require("react"), 1);
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 (1) return {
49
- switchProps: {
50
- onPress() {
51
- setChecked(function (prevChecked) {
52
- return !prevChecked;
53
- });
54
- }
55
- },
56
- switchRef: ref,
57
- bubbleInput: null
58
- };
59
- var disabled, name, value, required, hasConsumerStoppedPropagationRef, button, setButton, composedRefs, isFormControl, labelId, ariaLabelledBy;
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;EAAAC,YAAA,GAAAV,MAAA,CAAAW,SAAA,CAAAC,cAAA;AAuDnB,IAAAC,QAAA,GAAAA,CAAAC,MAAA,EAAAC,GAAA;IApCJ,SAASC,IAAA,IAASD,GAAA,EAChBb,SAAO,CAAAY,MAAU,EAAAE,IAAA;MAAAC,GAAY,EAAAF,GAAA,CAAAC,IAAA;MAAAE,UAAA;IAAA;EAC/B;EAAAC,WAAA,GAAAA,CAAAC,EAAA,EAAAC,IAAA,EAAAC,MAAA,EAAAC,IAAA;IAWA,IAAMF,IAAA,WAAeA,IAAA,YAA4B,WAAAA,IAAA,gBAC/C,KAAM,IAAEG,GAAA,IAASlB,iBAAS,CAAUe,IAAM,GAK1C,CAAAX,YAAM,CAAAe,IAAA,CAAUL,EAAA,EAAAI,GAAM,KAAAA,GAAA,KAAAF,MAAA,IAAApB,SAAA,CAAAkB,EAAA,EAAAI,GAAA;MAAAP,GAAA,EAAAA,CAAA,KAAAI,IAAA,CAAAG,GAAA;MAAA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,EAAAC,gCACzB,EAAAC,MAAA,EAAAC,SAAmC,EAAAC,YAAa,EAAKC,aAE5C,EAAAC,OAAS,EAAIC,cAAM;AAWlC","ignoreList":[]}
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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ACjC,QAAAA,WAAc;UACd;UACA,IAAAZ,gBAAA,CAAAyB,KAAA,IAAAD,aAAA;YAEFP,gCAAC,CAAAoB,OAAA,GAAAD,KAAA,CAAAE,oBAAA;YACL,KAAArB,gCAAmB,CAAAoB,OAAA,EAAAD,KAAA,CAAAG,eAAA;UACnB;QACE;MACA;MACE1B,SAAA,EAAAS,YAAA;MAIA;AAAqE;AACvE;MAEJR,WAAA,EAAAd,gBAAA,CAAAyB,KAAA,IAAAD,aAAA,sBAAA3B,kBAAA,CAAA2C,GAAA,EAAAC,WAAA;QACAC,OAAA,EAAWvB,MAAA;QAAAwB,OAAA,GAAA1B,gCAAA,CAAAoB,OAAA;QAAA5D,IAAA;QAAAc,KAAA;QAIXiB,OAAA;QAEKQ,QAAA;QAAAD,QAAA;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.36",
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.36",
40
- "@tamagui/constants": "2.0.0-rc.36",
41
- "@tamagui/helpers": "2.0.0-rc.36",
42
- "@tamagui/label": "2.0.0-rc.36",
43
- "@tamagui/use-previous": "2.0.0-rc.36"
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.36",
46
+ "@tamagui/build": "2.0.0-rc.36-1775243248161",
47
47
  "react": ">=19",
48
48
  "react-native": "0.83.2"
49
49
  },