@tamagui/alert-dialog 3.0.0-beta.924.1 → 3.0.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.
Files changed (52) hide show
  1. package/dist/cjs/AlertDialog.cjs +34 -31
  2. package/dist/cjs/AlertDialog.native.cjs +33 -106
  3. package/dist/cjs/AlertDialog.native.js +33 -106
  4. package/dist/cjs/AlertDialog.native.js.map +1 -1
  5. package/dist/cjs/alertDialogPart.cjs +30 -0
  6. package/dist/cjs/alertDialogPart.native.cjs +32 -0
  7. package/dist/cjs/alertDialogPart.native.js +34 -0
  8. package/dist/cjs/alertDialogPart.native.js.map +1 -0
  9. package/dist/cjs/useNativeAlertDialog.cjs +24 -0
  10. package/dist/cjs/useNativeAlertDialog.native.cjs +139 -0
  11. package/dist/cjs/useNativeAlertDialog.native.js +141 -0
  12. package/dist/cjs/useNativeAlertDialog.native.js.map +1 -0
  13. package/dist/esm/AlertDialog.mjs +35 -19
  14. package/dist/esm/AlertDialog.mjs.map +1 -1
  15. package/dist/esm/AlertDialog.native.js +33 -104
  16. package/dist/esm/AlertDialog.native.js.map +1 -1
  17. package/dist/esm/alertDialogPart.mjs +7 -0
  18. package/dist/esm/alertDialogPart.mjs.map +1 -0
  19. package/dist/esm/alertDialogPart.native.js +7 -0
  20. package/dist/esm/alertDialogPart.native.js.map +1 -0
  21. package/dist/esm/useNativeAlertDialog.mjs +4 -0
  22. package/dist/esm/useNativeAlertDialog.mjs.map +1 -0
  23. package/dist/esm/useNativeAlertDialog.native.js +112 -0
  24. package/dist/esm/useNativeAlertDialog.native.js.map +1 -0
  25. package/dist/jsx/AlertDialog.mjs +35 -19
  26. package/dist/jsx/AlertDialog.mjs.map +1 -1
  27. package/dist/jsx/AlertDialog.native.cjs +33 -106
  28. package/dist/jsx/AlertDialog.native.js +33 -106
  29. package/dist/jsx/AlertDialog.native.js.map +1 -1
  30. package/dist/jsx/alertDialogPart.mjs +7 -0
  31. package/dist/jsx/alertDialogPart.mjs.map +1 -0
  32. package/dist/jsx/alertDialogPart.native.cjs +32 -0
  33. package/dist/jsx/alertDialogPart.native.js +34 -0
  34. package/dist/jsx/alertDialogPart.native.js.map +1 -0
  35. package/dist/jsx/useNativeAlertDialog.mjs +4 -0
  36. package/dist/jsx/useNativeAlertDialog.mjs.map +1 -0
  37. package/dist/jsx/useNativeAlertDialog.native.cjs +139 -0
  38. package/dist/jsx/useNativeAlertDialog.native.js +141 -0
  39. package/dist/jsx/useNativeAlertDialog.native.js.map +1 -0
  40. package/package.json +21 -19
  41. package/src/AlertDialog.tsx +19 -141
  42. package/src/alertDialogPart.ts +26 -0
  43. package/src/useNativeAlertDialog.native.tsx +129 -0
  44. package/src/useNativeAlertDialog.ts +11 -0
  45. package/types/AlertDialog.d.ts +41 -83
  46. package/types/AlertDialog.d.ts.map +1 -1
  47. package/types/alertDialogPart.d.ts +15 -0
  48. package/types/alertDialogPart.d.ts.map +1 -0
  49. package/types/useNativeAlertDialog.d.ts +11 -0
  50. package/types/useNativeAlertDialog.d.ts.map +1 -0
  51. package/types/useNativeAlertDialog.native.d.ts +11 -0
  52. package/types/useNativeAlertDialog.native.d.ts.map +1 -0
@@ -44,18 +44,15 @@ var import_constants = require("@tamagui/constants");
44
44
  var import_core2 = require("@tamagui/core");
45
45
  var import_dialog = require("@tamagui/dialog");
46
46
  var import_helpers = require("@tamagui/helpers");
47
- require("@tamagui/use-controllable-state");
48
47
  var React = __toESM(require("react"), 1);
49
- require("react-native-web");
48
+ var import_alertDialogPart = require("./alertDialogPart.cjs");
49
+ var import_useNativeAlertDialog = require("./useNativeAlertDialog.cjs");
50
50
  var import_jsx_runtime = require("react/jsx-runtime");
51
51
  const getAlertDialogScope = (scope) => scope;
52
52
  const ROOT_NAME = "AlertDialog";
53
- const ALERT_DIALOG_PART = /* @__PURE__ */ Symbol("AlertDialogPart");
54
- const markAlertDialogPart = (component, part) => {
55
- Object.assign(component.staticConfig, { [ALERT_DIALOG_PART]: part });
56
- };
57
- const NativeAlertDialogTriggerFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogTrigger" });
58
- markAlertDialogPart(NativeAlertDialogTriggerFrame, "trigger");
53
+ const TRIGGER_NAME = "AlertDialogTrigger";
54
+ const NativeAlertDialogTriggerFrame = (0, import_core2.styled)(import_core2.View, { displayName: TRIGGER_NAME });
55
+ (0, import_alertDialogPart.markAlertDialogPart)(NativeAlertDialogTriggerFrame, "trigger");
59
56
  const AlertDialogTrigger = (0, import_core.createStyledHOC)(NativeAlertDialogTriggerFrame, function AlertDialogTrigger2(props, forwardedRef) {
60
57
  if (props["__native"]) {
61
58
  const { __native, onPress, __onPress, ...rest } = props;
@@ -78,7 +75,8 @@ const AlertDialogPortal = function AlertDialogPortal2(props) {
78
75
  ...portalProps
79
76
  });
80
77
  };
81
- const AlertDialogOverlayFrame = (0, import_core2.styled)(import_dialog.DialogOverlayFrame, { displayName: "AlertDialogOverlay" });
78
+ const OVERLAY_NAME = "AlertDialogOverlay";
79
+ const AlertDialogOverlayFrame = (0, import_core2.styled)(import_dialog.DialogOverlayFrame, { displayName: OVERLAY_NAME });
82
80
  const AlertDialogOverlay = (0, import_core.createStyledHOC)(AlertDialogOverlayFrame, function AlertDialogOverlay2(props, forwardedRef) {
83
81
  const { scope, ...overlayProps } = props;
84
82
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogOverlay, {
@@ -89,7 +87,8 @@ const AlertDialogOverlay = (0, import_core.createStyledHOC)(AlertDialogOverlayFr
89
87
  });
90
88
  const CONTENT_NAME = "AlertDialogContent";
91
89
  const { Provider: AlertDialogContextProvider, useStyledContext: useAlertDialogContentContext } = (0, import_core2.createStyledContext)({}, "AlertDialogContext");
92
- const AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialogContent2(props, forwardedRef) {
90
+ const AlertDialogContentFrame = (0, import_core2.styled)(import_dialog.DialogContentFrame, { displayName: CONTENT_NAME });
91
+ const AlertDialogContent = (0, import_core.createStyledHOC)(AlertDialogContentFrame, function AlertDialogContent2(props, forwardedRef) {
93
92
  const { scope, children, ...contentProps } = props;
94
93
  const dialogScope = getAlertDialogScope(scope);
95
94
  const contentRef = React.useRef(null);
@@ -112,7 +111,9 @@ const AlertDialogContent = (0, import_core.createRefComponent)(function AlertDia
112
111
  ref: composedRefs,
113
112
  onOpenAutoFocus: (0, import_helpers.composeEventHandlers)(contentProps.onOpenAutoFocus, (event) => {
114
113
  event.cancel();
115
- if (import_constants.isWeb) cancelRef.current?.focus({ preventScroll: true });
114
+ if (import_constants.isWeb) {
115
+ cancelRef.current?.focus({ preventScroll: true });
116
+ }
116
117
  }),
117
118
  onPointerDownOutside: (event) => event.cancel(),
118
119
  onInteractOutside: (event) => event.cancel(),
@@ -123,7 +124,7 @@ const AlertDialogContent = (0, import_core.createRefComponent)(function AlertDia
123
124
  });
124
125
  const TITLE_NAME = "AlertDialogTitle";
125
126
  const AlertDialogTitleFrame = (0, import_core2.styled)(import_core2.View, { displayName: TITLE_NAME });
126
- markAlertDialogPart(AlertDialogTitleFrame, "title");
127
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogTitleFrame, "title");
127
128
  const AlertDialogTitle = (0, import_core.createStyledHOC)(AlertDialogTitleFrame, function AlertDialogTitle2(props, forwardedRef) {
128
129
  const { scope, ...titleProps } = props;
129
130
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, {
@@ -134,7 +135,7 @@ const AlertDialogTitle = (0, import_core.createStyledHOC)(AlertDialogTitleFrame,
134
135
  });
135
136
  const DESCRIPTION_NAME = "AlertDialogDescription";
136
137
  const AlertDialogDescriptionFrame = (0, import_core2.styled)(import_core2.View, { displayName: DESCRIPTION_NAME });
137
- markAlertDialogPart(AlertDialogDescriptionFrame, "description");
138
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogDescriptionFrame, "description");
138
139
  const AlertDialogDescription = (0, import_core.createStyledHOC)(AlertDialogDescriptionFrame, function AlertDialogDescription2(props, forwardedRef) {
139
140
  const { scope, ...descriptionProps } = props;
140
141
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, {
@@ -143,8 +144,9 @@ const AlertDialogDescription = (0, import_core.createStyledHOC)(AlertDialogDescr
143
144
  ref: forwardedRef
144
145
  });
145
146
  });
146
- const AlertDialogActionFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogAction" });
147
- markAlertDialogPart(AlertDialogActionFrame, "action");
147
+ const ACTION_NAME = "AlertDialogAction";
148
+ const AlertDialogActionFrame = (0, import_core2.styled)(import_core2.View, { displayName: ACTION_NAME });
149
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogActionFrame, "action");
148
150
  const AlertDialogAction = (0, import_core.createStyledHOC)(AlertDialogActionFrame, function AlertDialogAction2(props, forwardedRef) {
149
151
  const { scope, ...actionProps } = props;
150
152
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
@@ -153,8 +155,9 @@ const AlertDialogAction = (0, import_core.createStyledHOC)(AlertDialogActionFram
153
155
  ref: forwardedRef
154
156
  });
155
157
  });
156
- const AlertDialogCancelFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogCancel" });
157
- markAlertDialogPart(AlertDialogCancelFrame, "cancel");
158
+ const CANCEL_NAME = "AlertDialogCancel";
159
+ const AlertDialogCancelFrame = (0, import_core2.styled)(import_core2.View, { displayName: CANCEL_NAME });
160
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogCancelFrame, "cancel");
158
161
  const AlertDialogCancel = (0, import_core.createStyledHOC)(AlertDialogCancelFrame, function AlertDialogCancel2(props, forwardedRef) {
159
162
  const { scope, ...cancelProps } = props;
160
163
  const { cancelRef } = useAlertDialogContentContext(scope);
@@ -165,8 +168,9 @@ const AlertDialogCancel = (0, import_core.createStyledHOC)(AlertDialogCancelFram
165
168
  ref
166
169
  });
167
170
  });
168
- const AlertDialogDestructiveFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogDestructive" });
169
- markAlertDialogPart(AlertDialogDestructiveFrame, "destructive");
171
+ const DESTRUCTIVE_NAME = "AlertDialogDestructive";
172
+ const AlertDialogDestructiveFrame = (0, import_core2.styled)(import_core2.View, { displayName: DESTRUCTIVE_NAME });
173
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogDestructiveFrame, "destructive");
170
174
  const AlertDialogDestructive = (0, import_core.createStyledHOC)(AlertDialogDestructiveFrame, function AlertDialogDestructive2(props, forwardedRef) {
171
175
  const { scope, ...destructiveProps } = props;
172
176
  const { destructiveRef } = useAlertDialogContentContext(scope);
@@ -178,35 +182,34 @@ const AlertDialogDestructive = (0, import_core.createStyledHOC)(AlertDialogDestr
178
182
  });
179
183
  });
180
184
  const DescriptionWarning = ({ contentRef }) => {
181
- if (process.env.NODE_ENV === "development") React.useEffect(() => {
182
- if (!import_constants.isWeb) return;
183
- if (!document.getElementById(contentRef.current?.getAttribute("aria-describedby"))) console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
185
+ if (process.env.NODE_ENV === "development") {
186
+ React.useEffect(() => {
187
+ if (!import_constants.isWeb) return;
188
+ const hasDescription = document.getElementById(contentRef.current?.getAttribute("aria-describedby"));
189
+ if (!hasDescription) {
190
+ console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
184
191
 
185
192
  You can add a description to the \`${CONTENT_NAME}\` by passing a \`${DESCRIPTION_NAME}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
186
193
 
187
194
  Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${CONTENT_NAME}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
188
195
 
189
196
  For more information, see https://tamagui.dev/docs/components/alert-dialog`);
190
- }, [contentRef]);
197
+ }
198
+ }, [contentRef]);
199
+ }
191
200
  return null;
192
201
  };
193
202
  const AlertDialogInner = (props) => {
194
203
  const { scope, native, ...alertDialogProps } = props;
195
204
  const dialogScope = getAlertDialogScope(scope);
205
+ const nativeAlert = (0, import_useNativeAlertDialog.useNativeAlertDialog)(props);
206
+ if (nativeAlert) return nativeAlert;
196
207
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, {
197
208
  scope: dialogScope,
198
209
  ...alertDialogProps,
199
210
  modal: true
200
211
  });
201
212
  };
202
- function forEachChildDeep(children, onChild) {
203
- for (const child of children) {
204
- if (!React.isValidElement(child)) continue;
205
- if (!onChild(child)) continue;
206
- const childProps = child.props;
207
- if (childProps.children) forEachChildDeep(React.Children.toArray(childProps.children), onChild);
208
- }
209
- }
210
213
  const AlertDialog = (0, import_helpers.withStaticProperties)(AlertDialogInner, {
211
214
  Trigger: AlertDialogTrigger,
212
215
  Portal: AlertDialogPortal,
@@ -47,19 +47,16 @@ var import_constants = require("@tamagui/constants");
47
47
  var import_core2 = require("@tamagui/core");
48
48
  var import_dialog = require("@tamagui/dialog");
49
49
  var import_helpers = require("@tamagui/helpers");
50
- var import_use_controllable_state = require("@tamagui/use-controllable-state");
51
50
  var React = __toESM(require("react"), 1);
52
- var import_react_native = require("react-native");
51
+ var import_alertDialogPart = require("./alertDialogPart.native.js");
52
+ var import_useNativeAlertDialog = require("./useNativeAlertDialog.native.js");
53
53
  var getAlertDialogScope = function(scope) {
54
54
  return scope;
55
55
  };
56
56
  var ROOT_NAME = "AlertDialog";
57
- var ALERT_DIALOG_PART = /* @__PURE__ */ Symbol("AlertDialogPart");
58
- var markAlertDialogPart = function(component, part) {
59
- Object.assign(component.staticConfig, { [ALERT_DIALOG_PART]: part });
60
- };
61
- var NativeAlertDialogTriggerFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogTrigger" });
62
- markAlertDialogPart(NativeAlertDialogTriggerFrame, "trigger");
57
+ var TRIGGER_NAME = "AlertDialogTrigger";
58
+ var NativeAlertDialogTriggerFrame = (0, import_core2.styled)(import_core2.View, { displayName: TRIGGER_NAME });
59
+ (0, import_alertDialogPart.markAlertDialogPart)(NativeAlertDialogTriggerFrame, "trigger");
63
60
  var AlertDialogTrigger = (0, import_core.createStyledHOC)(NativeAlertDialogTriggerFrame, function AlertDialogTrigger2(props, forwardedRef) {
64
61
  if (props["__native"]) {
65
62
  var { __native, onPress, __onPress, ...rest } = props;
@@ -82,7 +79,8 @@ var AlertDialogPortal = function AlertDialogPortal2(props) {
82
79
  ...portalProps
83
80
  });
84
81
  };
85
- var AlertDialogOverlayFrame = (0, import_core2.styled)(import_dialog.DialogOverlayFrame, { displayName: "AlertDialogOverlay" });
82
+ var OVERLAY_NAME = "AlertDialogOverlay";
83
+ var AlertDialogOverlayFrame = (0, import_core2.styled)(import_dialog.DialogOverlayFrame, { displayName: OVERLAY_NAME });
86
84
  var AlertDialogOverlay = (0, import_core.createStyledHOC)(AlertDialogOverlayFrame, function AlertDialogOverlay2(props, forwardedRef) {
87
85
  var { scope, ...overlayProps } = props;
88
86
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogOverlay, {
@@ -93,7 +91,8 @@ var AlertDialogOverlay = (0, import_core.createStyledHOC)(AlertDialogOverlayFram
93
91
  });
94
92
  var CONTENT_NAME = "AlertDialogContent";
95
93
  var { Provider: AlertDialogContextProvider, useStyledContext: useAlertDialogContentContext } = (0, import_core2.createStyledContext)({}, "AlertDialogContext");
96
- var AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialogContent2(props, forwardedRef) {
94
+ var AlertDialogContentFrame = (0, import_core2.styled)(import_dialog.DialogContentFrame, { displayName: CONTENT_NAME });
95
+ var AlertDialogContent = (0, import_core.createStyledHOC)(AlertDialogContentFrame, function AlertDialogContent2(props, forwardedRef) {
97
96
  var { scope, children, ...contentProps } = props;
98
97
  var dialogScope = getAlertDialogScope(scope);
99
98
  var contentRef = React.useRef(null);
@@ -118,7 +117,7 @@ var AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialo
118
117
  event.cancel();
119
118
  if (import_constants.isWeb) {
120
119
  var _cancelRef_current;
121
- (_cancelRef_current = cancelRef.current) === null || _cancelRef_current === void 0 || _cancelRef_current.focus({ preventScroll: true });
120
+ (_cancelRef_current = cancelRef.current) === null || _cancelRef_current === void 0 ? void 0 : _cancelRef_current.focus({ preventScroll: true });
122
121
  }
123
122
  }),
124
123
  onPointerDownOutside: function(event) {
@@ -134,7 +133,7 @@ var AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialo
134
133
  });
135
134
  var TITLE_NAME = "AlertDialogTitle";
136
135
  var AlertDialogTitleFrame = (0, import_core2.styled)(import_core2.View, { displayName: TITLE_NAME });
137
- markAlertDialogPart(AlertDialogTitleFrame, "title");
136
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogTitleFrame, "title");
138
137
  var AlertDialogTitle = (0, import_core.createStyledHOC)(AlertDialogTitleFrame, function AlertDialogTitle2(props, forwardedRef) {
139
138
  var { scope, ...titleProps } = props;
140
139
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, {
@@ -145,7 +144,7 @@ var AlertDialogTitle = (0, import_core.createStyledHOC)(AlertDialogTitleFrame, f
145
144
  });
146
145
  var DESCRIPTION_NAME = "AlertDialogDescription";
147
146
  var AlertDialogDescriptionFrame = (0, import_core2.styled)(import_core2.View, { displayName: DESCRIPTION_NAME });
148
- markAlertDialogPart(AlertDialogDescriptionFrame, "description");
147
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogDescriptionFrame, "description");
149
148
  var AlertDialogDescription = (0, import_core.createStyledHOC)(AlertDialogDescriptionFrame, function AlertDialogDescription2(props, forwardedRef) {
150
149
  var { scope, ...descriptionProps } = props;
151
150
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, {
@@ -154,8 +153,9 @@ var AlertDialogDescription = (0, import_core.createStyledHOC)(AlertDialogDescrip
154
153
  ref: forwardedRef
155
154
  });
156
155
  });
157
- var AlertDialogActionFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogAction" });
158
- markAlertDialogPart(AlertDialogActionFrame, "action");
156
+ var ACTION_NAME = "AlertDialogAction";
157
+ var AlertDialogActionFrame = (0, import_core2.styled)(import_core2.View, { displayName: ACTION_NAME });
158
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogActionFrame, "action");
159
159
  var AlertDialogAction = (0, import_core.createStyledHOC)(AlertDialogActionFrame, function AlertDialogAction2(props, forwardedRef) {
160
160
  var { scope, ...actionProps } = props;
161
161
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
@@ -164,8 +164,9 @@ var AlertDialogAction = (0, import_core.createStyledHOC)(AlertDialogActionFrame,
164
164
  ref: forwardedRef
165
165
  });
166
166
  });
167
- var AlertDialogCancelFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogCancel" });
168
- markAlertDialogPart(AlertDialogCancelFrame, "cancel");
167
+ var CANCEL_NAME = "AlertDialogCancel";
168
+ var AlertDialogCancelFrame = (0, import_core2.styled)(import_core2.View, { displayName: CANCEL_NAME });
169
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogCancelFrame, "cancel");
169
170
  var AlertDialogCancel = (0, import_core.createStyledHOC)(AlertDialogCancelFrame, function AlertDialogCancel2(props, forwardedRef) {
170
171
  var { scope, ...cancelProps } = props;
171
172
  var { cancelRef } = useAlertDialogContentContext(scope);
@@ -176,8 +177,9 @@ var AlertDialogCancel = (0, import_core.createStyledHOC)(AlertDialogCancelFrame,
176
177
  ref
177
178
  });
178
179
  });
179
- var AlertDialogDestructiveFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogDestructive" });
180
- markAlertDialogPart(AlertDialogDestructiveFrame, "destructive");
180
+ var DESTRUCTIVE_NAME = "AlertDialogDestructive";
181
+ var AlertDialogDestructiveFrame = (0, import_core2.styled)(import_core2.View, { displayName: DESTRUCTIVE_NAME });
182
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogDestructiveFrame, "destructive");
181
183
  var AlertDialogDestructive = (0, import_core.createStyledHOC)(AlertDialogDestructiveFrame, function AlertDialogDestructive2(props, forwardedRef) {
182
184
  var { scope, ...destructiveProps } = props;
183
185
  var { destructiveRef } = useAlertDialogContentContext(scope);
@@ -190,110 +192,35 @@ var AlertDialogDestructive = (0, import_core.createStyledHOC)(AlertDialogDestruc
190
192
  });
191
193
  var DescriptionWarning = function(param) {
192
194
  var { contentRef } = param;
193
- if (process.env.NODE_ENV === "development") React.useEffect(function() {
194
- var _contentRef_current;
195
- if (!import_constants.isWeb) return;
196
- if (!document.getElementById((_contentRef_current = contentRef.current) === null || _contentRef_current === void 0 ? void 0 : _contentRef_current.getAttribute("aria-describedby"))) console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
195
+ if (process.env.NODE_ENV === "development") {
196
+ React.useEffect(function() {
197
+ var _contentRef_current;
198
+ if (!import_constants.isWeb) return;
199
+ var hasDescription = document.getElementById((_contentRef_current = contentRef.current) === null || _contentRef_current === void 0 ? void 0 : _contentRef_current.getAttribute("aria-describedby"));
200
+ if (!hasDescription) {
201
+ console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
197
202
 
198
203
  You can add a description to the \`${CONTENT_NAME}\` by passing a \`${DESCRIPTION_NAME}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
199
204
 
200
205
  Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${CONTENT_NAME}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
201
206
 
202
207
  For more information, see https://tamagui.dev/docs/components/alert-dialog`);
203
- }, [contentRef]);
208
+ }
209
+ }, [contentRef]);
210
+ }
204
211
  return null;
205
212
  };
206
213
  var AlertDialogInner = function(props) {
207
214
  var { scope, native, ...alertDialogProps } = props;
208
215
  var dialogScope = getAlertDialogScope(scope);
209
- var [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
210
- prop: props.open,
211
- defaultProp: props.defaultOpen || false,
212
- onChange: props.onOpenChange,
213
- transition: true
214
- });
215
- var triggerElement = null;
216
- var title = "";
217
- var description = "";
218
- var buttons = [];
219
- forEachChildDeep(React.Children.toArray(props.children), function(child) {
220
- if (!/* @__PURE__ */ React.isValidElement(child)) return false;
221
- var part = (0, import_core2.isTamaguiElement)(child) ? child.type.staticConfig[ALERT_DIALOG_PART] : void 0;
222
- switch (part) {
223
- case "trigger":
224
- triggerElement = /* @__PURE__ */ React.cloneElement(child, { __native: true });
225
- return false;
226
- case "title":
227
- title = getStringChildren(child);
228
- return false;
229
- case "description":
230
- description = getStringChildren(child);
231
- return false;
232
- case "action":
233
- case "destructive":
234
- case "cancel":
235
- var style = part === "action" ? "default" : part === "destructive" ? "destructive" : "cancel";
236
- var text = getStringChildren(child);
237
- var onPress = function() {
238
- var _childProps_onPress;
239
- var childProps = child.props;
240
- childProps === null || childProps === void 0 || (_childProps_onPress = childProps.onPress) == null || _childProps_onPress.call(childProps, { native: true });
241
- setOpen(false);
242
- };
243
- buttons.push({
244
- style,
245
- text,
246
- onPress
247
- });
248
- return false;
249
- default: return true;
250
- }
251
- });
252
- (0, import_constants.useIsomorphicLayoutEffect)(function() {
253
- if (!open || !native) return;
254
- if (title || description) import_react_native.Alert.alert(title, description, buttons);
255
- }, [native, open]);
256
- if (native) return /* @__PURE__ */ React.cloneElement(triggerElement, { __onPress: function() {
257
- setOpen(true);
258
- } });
216
+ var nativeAlert = (0, import_useNativeAlertDialog.useNativeAlertDialog)(props);
217
+ if (nativeAlert) return nativeAlert;
259
218
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, {
260
219
  scope: dialogScope,
261
220
  ...alertDialogProps,
262
221
  modal: true
263
222
  });
264
223
  };
265
- function forEachChildDeep(children, onChild) {
266
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
267
- try {
268
- for (var _iterator = children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
269
- var child = _step.value;
270
- if (!/* @__PURE__ */ React.isValidElement(child)) continue;
271
- if (!onChild(child)) continue;
272
- var childProps = child.props;
273
- if (childProps.children) forEachChildDeep(React.Children.toArray(childProps.children), onChild);
274
- }
275
- } catch (err) {
276
- _didIteratorError = true;
277
- _iteratorError = err;
278
- } finally {
279
- try {
280
- if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
281
- } finally {
282
- if (_didIteratorError) throw _iteratorError;
283
- }
284
- }
285
- }
286
- function getStringChildren(child) {
287
- var string = "";
288
- forEachChildDeep(React.Children.toArray(child), function(child2) {
289
- if (typeof child2.props.children === "string") {
290
- string = child2.props.children;
291
- return false;
292
- }
293
- return true;
294
- });
295
- return string;
296
- }
297
224
  var AlertDialog = (0, import_helpers.withStaticProperties)(AlertDialogInner, {
298
225
  Trigger: AlertDialogTrigger,
299
226
  Portal: AlertDialogPortal,
@@ -47,19 +47,16 @@ var import_constants = require("@tamagui/constants");
47
47
  var import_core2 = require("@tamagui/core");
48
48
  var import_dialog = require("@tamagui/dialog");
49
49
  var import_helpers = require("@tamagui/helpers");
50
- var import_use_controllable_state = require("@tamagui/use-controllable-state");
51
50
  var React = __toESM(require("react"), 1);
52
- var import_react_native = require("react-native");
51
+ var import_alertDialogPart = require("./alertDialogPart.native.js");
52
+ var import_useNativeAlertDialog = require("./useNativeAlertDialog.native.js");
53
53
  var getAlertDialogScope = function(scope) {
54
54
  return scope;
55
55
  };
56
56
  var ROOT_NAME = "AlertDialog";
57
- var ALERT_DIALOG_PART = /* @__PURE__ */ Symbol("AlertDialogPart");
58
- var markAlertDialogPart = function(component, part) {
59
- Object.assign(component.staticConfig, { [ALERT_DIALOG_PART]: part });
60
- };
61
- var NativeAlertDialogTriggerFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogTrigger" });
62
- markAlertDialogPart(NativeAlertDialogTriggerFrame, "trigger");
57
+ var TRIGGER_NAME = "AlertDialogTrigger";
58
+ var NativeAlertDialogTriggerFrame = (0, import_core2.styled)(import_core2.View, { displayName: TRIGGER_NAME });
59
+ (0, import_alertDialogPart.markAlertDialogPart)(NativeAlertDialogTriggerFrame, "trigger");
63
60
  var AlertDialogTrigger = (0, import_core.createStyledHOC)(NativeAlertDialogTriggerFrame, function AlertDialogTrigger2(props, forwardedRef) {
64
61
  if (props["__native"]) {
65
62
  var { __native, onPress, __onPress, ...rest } = props;
@@ -82,7 +79,8 @@ var AlertDialogPortal = function AlertDialogPortal2(props) {
82
79
  ...portalProps
83
80
  });
84
81
  };
85
- var AlertDialogOverlayFrame = (0, import_core2.styled)(import_dialog.DialogOverlayFrame, { displayName: "AlertDialogOverlay" });
82
+ var OVERLAY_NAME = "AlertDialogOverlay";
83
+ var AlertDialogOverlayFrame = (0, import_core2.styled)(import_dialog.DialogOverlayFrame, { displayName: OVERLAY_NAME });
86
84
  var AlertDialogOverlay = (0, import_core.createStyledHOC)(AlertDialogOverlayFrame, function AlertDialogOverlay2(props, forwardedRef) {
87
85
  var { scope, ...overlayProps } = props;
88
86
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogOverlay, {
@@ -93,7 +91,8 @@ var AlertDialogOverlay = (0, import_core.createStyledHOC)(AlertDialogOverlayFram
93
91
  });
94
92
  var CONTENT_NAME = "AlertDialogContent";
95
93
  var { Provider: AlertDialogContextProvider, useStyledContext: useAlertDialogContentContext } = (0, import_core2.createStyledContext)({}, "AlertDialogContext");
96
- var AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialogContent2(props, forwardedRef) {
94
+ var AlertDialogContentFrame = (0, import_core2.styled)(import_dialog.DialogContentFrame, { displayName: CONTENT_NAME });
95
+ var AlertDialogContent = (0, import_core.createStyledHOC)(AlertDialogContentFrame, function AlertDialogContent2(props, forwardedRef) {
97
96
  var { scope, children, ...contentProps } = props;
98
97
  var dialogScope = getAlertDialogScope(scope);
99
98
  var contentRef = React.useRef(null);
@@ -118,7 +117,7 @@ var AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialo
118
117
  event.cancel();
119
118
  if (import_constants.isWeb) {
120
119
  var _cancelRef_current;
121
- (_cancelRef_current = cancelRef.current) === null || _cancelRef_current === void 0 || _cancelRef_current.focus({ preventScroll: true });
120
+ (_cancelRef_current = cancelRef.current) === null || _cancelRef_current === void 0 ? void 0 : _cancelRef_current.focus({ preventScroll: true });
122
121
  }
123
122
  }),
124
123
  onPointerDownOutside: function(event) {
@@ -134,7 +133,7 @@ var AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialo
134
133
  });
135
134
  var TITLE_NAME = "AlertDialogTitle";
136
135
  var AlertDialogTitleFrame = (0, import_core2.styled)(import_core2.View, { displayName: TITLE_NAME });
137
- markAlertDialogPart(AlertDialogTitleFrame, "title");
136
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogTitleFrame, "title");
138
137
  var AlertDialogTitle = (0, import_core.createStyledHOC)(AlertDialogTitleFrame, function AlertDialogTitle2(props, forwardedRef) {
139
138
  var { scope, ...titleProps } = props;
140
139
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, {
@@ -145,7 +144,7 @@ var AlertDialogTitle = (0, import_core.createStyledHOC)(AlertDialogTitleFrame, f
145
144
  });
146
145
  var DESCRIPTION_NAME = "AlertDialogDescription";
147
146
  var AlertDialogDescriptionFrame = (0, import_core2.styled)(import_core2.View, { displayName: DESCRIPTION_NAME });
148
- markAlertDialogPart(AlertDialogDescriptionFrame, "description");
147
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogDescriptionFrame, "description");
149
148
  var AlertDialogDescription = (0, import_core.createStyledHOC)(AlertDialogDescriptionFrame, function AlertDialogDescription2(props, forwardedRef) {
150
149
  var { scope, ...descriptionProps } = props;
151
150
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, {
@@ -154,8 +153,9 @@ var AlertDialogDescription = (0, import_core.createStyledHOC)(AlertDialogDescrip
154
153
  ref: forwardedRef
155
154
  });
156
155
  });
157
- var AlertDialogActionFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogAction" });
158
- markAlertDialogPart(AlertDialogActionFrame, "action");
156
+ var ACTION_NAME = "AlertDialogAction";
157
+ var AlertDialogActionFrame = (0, import_core2.styled)(import_core2.View, { displayName: ACTION_NAME });
158
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogActionFrame, "action");
159
159
  var AlertDialogAction = (0, import_core.createStyledHOC)(AlertDialogActionFrame, function AlertDialogAction2(props, forwardedRef) {
160
160
  var { scope, ...actionProps } = props;
161
161
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
@@ -164,8 +164,9 @@ var AlertDialogAction = (0, import_core.createStyledHOC)(AlertDialogActionFrame,
164
164
  ref: forwardedRef
165
165
  });
166
166
  });
167
- var AlertDialogCancelFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogCancel" });
168
- markAlertDialogPart(AlertDialogCancelFrame, "cancel");
167
+ var CANCEL_NAME = "AlertDialogCancel";
168
+ var AlertDialogCancelFrame = (0, import_core2.styled)(import_core2.View, { displayName: CANCEL_NAME });
169
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogCancelFrame, "cancel");
169
170
  var AlertDialogCancel = (0, import_core.createStyledHOC)(AlertDialogCancelFrame, function AlertDialogCancel2(props, forwardedRef) {
170
171
  var { scope, ...cancelProps } = props;
171
172
  var { cancelRef } = useAlertDialogContentContext(scope);
@@ -176,8 +177,9 @@ var AlertDialogCancel = (0, import_core.createStyledHOC)(AlertDialogCancelFrame,
176
177
  ref
177
178
  });
178
179
  });
179
- var AlertDialogDestructiveFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogDestructive" });
180
- markAlertDialogPart(AlertDialogDestructiveFrame, "destructive");
180
+ var DESTRUCTIVE_NAME = "AlertDialogDestructive";
181
+ var AlertDialogDestructiveFrame = (0, import_core2.styled)(import_core2.View, { displayName: DESTRUCTIVE_NAME });
182
+ (0, import_alertDialogPart.markAlertDialogPart)(AlertDialogDestructiveFrame, "destructive");
181
183
  var AlertDialogDestructive = (0, import_core.createStyledHOC)(AlertDialogDestructiveFrame, function AlertDialogDestructive2(props, forwardedRef) {
182
184
  var { scope, ...destructiveProps } = props;
183
185
  var { destructiveRef } = useAlertDialogContentContext(scope);
@@ -190,110 +192,35 @@ var AlertDialogDestructive = (0, import_core.createStyledHOC)(AlertDialogDestruc
190
192
  });
191
193
  var DescriptionWarning = function(param) {
192
194
  var { contentRef } = param;
193
- if (process.env.NODE_ENV === "development") React.useEffect(function() {
194
- var _contentRef_current;
195
- if (!import_constants.isWeb) return;
196
- if (!document.getElementById((_contentRef_current = contentRef.current) === null || _contentRef_current === void 0 ? void 0 : _contentRef_current.getAttribute("aria-describedby"))) console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
195
+ if (process.env.NODE_ENV === "development") {
196
+ React.useEffect(function() {
197
+ var _contentRef_current;
198
+ if (!import_constants.isWeb) return;
199
+ var hasDescription = document.getElementById((_contentRef_current = contentRef.current) === null || _contentRef_current === void 0 ? void 0 : _contentRef_current.getAttribute("aria-describedby"));
200
+ if (!hasDescription) {
201
+ console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
197
202
 
198
203
  You can add a description to the \`${CONTENT_NAME}\` by passing a \`${DESCRIPTION_NAME}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
199
204
 
200
205
  Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${CONTENT_NAME}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
201
206
 
202
207
  For more information, see https://tamagui.dev/docs/components/alert-dialog`);
203
- }, [contentRef]);
208
+ }
209
+ }, [contentRef]);
210
+ }
204
211
  return null;
205
212
  };
206
213
  var AlertDialogInner = function(props) {
207
214
  var { scope, native, ...alertDialogProps } = props;
208
215
  var dialogScope = getAlertDialogScope(scope);
209
- var [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
210
- prop: props.open,
211
- defaultProp: props.defaultOpen || false,
212
- onChange: props.onOpenChange,
213
- transition: true
214
- });
215
- var triggerElement = null;
216
- var title = "";
217
- var description = "";
218
- var buttons = [];
219
- forEachChildDeep(React.Children.toArray(props.children), function(child) {
220
- if (!/* @__PURE__ */ React.isValidElement(child)) return false;
221
- var part = (0, import_core2.isTamaguiElement)(child) ? child.type.staticConfig[ALERT_DIALOG_PART] : void 0;
222
- switch (part) {
223
- case "trigger":
224
- triggerElement = /* @__PURE__ */ React.cloneElement(child, { __native: true });
225
- return false;
226
- case "title":
227
- title = getStringChildren(child);
228
- return false;
229
- case "description":
230
- description = getStringChildren(child);
231
- return false;
232
- case "action":
233
- case "destructive":
234
- case "cancel":
235
- var style = part === "action" ? "default" : part === "destructive" ? "destructive" : "cancel";
236
- var text = getStringChildren(child);
237
- var onPress = function() {
238
- var _childProps_onPress;
239
- var childProps = child.props;
240
- childProps === null || childProps === void 0 || (_childProps_onPress = childProps.onPress) == null || _childProps_onPress.call(childProps, { native: true });
241
- setOpen(false);
242
- };
243
- buttons.push({
244
- style,
245
- text,
246
- onPress
247
- });
248
- return false;
249
- default: return true;
250
- }
251
- });
252
- (0, import_constants.useIsomorphicLayoutEffect)(function() {
253
- if (!open || !native) return;
254
- if (title || description) import_react_native.Alert.alert(title, description, buttons);
255
- }, [native, open]);
256
- if (native) return /* @__PURE__ */ React.cloneElement(triggerElement, { __onPress: function() {
257
- setOpen(true);
258
- } });
216
+ var nativeAlert = (0, import_useNativeAlertDialog.useNativeAlertDialog)(props);
217
+ if (nativeAlert) return nativeAlert;
259
218
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, {
260
219
  scope: dialogScope,
261
220
  ...alertDialogProps,
262
221
  modal: true
263
222
  });
264
223
  };
265
- function forEachChildDeep(children, onChild) {
266
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
267
- try {
268
- for (var _iterator = children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
269
- var child = _step.value;
270
- if (!/* @__PURE__ */ React.isValidElement(child)) continue;
271
- if (!onChild(child)) continue;
272
- var childProps = child.props;
273
- if (childProps.children) forEachChildDeep(React.Children.toArray(childProps.children), onChild);
274
- }
275
- } catch (err) {
276
- _didIteratorError = true;
277
- _iteratorError = err;
278
- } finally {
279
- try {
280
- if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
281
- } finally {
282
- if (_didIteratorError) throw _iteratorError;
283
- }
284
- }
285
- }
286
- function getStringChildren(child) {
287
- var string = "";
288
- forEachChildDeep(React.Children.toArray(child), function(child2) {
289
- if (typeof child2.props.children === "string") {
290
- string = child2.props.children;
291
- return false;
292
- }
293
- return true;
294
- });
295
- return string;
296
- }
297
224
  var AlertDialog = (0, import_helpers.withStaticProperties)(AlertDialogInner, {
298
225
  Trigger: AlertDialogTrigger,
299
226
  Portal: AlertDialogPortal,