@tamagui/alert-dialog 2.7.7 → 3.0.0-beta.643.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,275 +6,217 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  var __copyProps = (to, from, except, desc) => {
14
- 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, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // 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
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var AlertDialog_exports = {};
35
29
  __export(AlertDialog_exports, {
36
- AlertDialog: () => AlertDialog,
37
- AlertDialogAction: () => AlertDialogAction,
38
- AlertDialogCancel: () => AlertDialogCancel,
39
- AlertDialogContent: () => AlertDialogContent,
40
- AlertDialogDescription: () => AlertDialogDescription,
41
- AlertDialogDestructive: () => AlertDialogDestructive,
42
- AlertDialogOverlay: () => AlertDialogOverlay,
43
- AlertDialogPortal: () => AlertDialogPortal,
44
- AlertDialogTitle: () => AlertDialogTitle,
45
- AlertDialogTrigger: () => AlertDialogTrigger
30
+ AlertDialog: () => AlertDialog,
31
+ AlertDialogAction: () => AlertDialogAction,
32
+ AlertDialogCancel: () => AlertDialogCancel,
33
+ AlertDialogContent: () => AlertDialogContent,
34
+ AlertDialogDescription: () => AlertDialogDescription,
35
+ AlertDialogDestructive: () => AlertDialogDestructive,
36
+ AlertDialogOverlay: () => AlertDialogOverlay,
37
+ AlertDialogPortal: () => AlertDialogPortal,
38
+ AlertDialogTitle: () => AlertDialogTitle,
39
+ AlertDialogTrigger: () => AlertDialogTrigger
46
40
  });
47
41
  module.exports = __toCommonJS(AlertDialog_exports);
42
+ var import_core = require("@tamagui/core");
48
43
  var import_compose_refs = require("@tamagui/compose-refs");
49
44
  var import_constants = require("@tamagui/constants");
50
- var import_core = require("@tamagui/core");
45
+ var import_core2 = require("@tamagui/core");
51
46
  var import_dialog = require("@tamagui/dialog");
52
47
  var import_helpers = require("@tamagui/helpers");
53
48
  require("@tamagui/use-controllable-state");
54
49
  var React = __toESM(require("react"), 1);
55
50
  require("react-native-web");
56
51
  var import_jsx_runtime = require("react/jsx-runtime");
57
- const getAlertDialogScope = scope => scope;
52
+ const getAlertDialogScope = (scope) => scope;
58
53
  const ROOT_NAME = "AlertDialog";
59
- const NativeAlertDialogTriggerFrame = (0, import_core.styled)(import_core.View, {
60
- name: "AlertDialogTrigger"
61
- });
62
- const AlertDialogTrigger = NativeAlertDialogTriggerFrame.styleable(function AlertDialogTrigger2(props, forwardedRef) {
63
- if (props["__native"]) {
64
- const {
65
- __native,
66
- onPress,
67
- __onPress,
68
- ...rest
69
- } = props;
70
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(NativeAlertDialogTriggerFrame, {
71
- ...rest,
72
- onPress: (0, import_helpers.composeEventHandlers)(onPress, __onPress)
73
- });
74
- }
75
- const {
76
- scope,
77
- ...triggerProps
78
- } = props;
79
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogTrigger, {
80
- scope: getAlertDialogScope(scope),
81
- ...triggerProps,
82
- ref: forwardedRef
83
- });
54
+ const ALERT_DIALOG_PART = /* @__PURE__ */ Symbol("AlertDialogPart");
55
+ const markAlertDialogPart = (component, part) => {
56
+ Object.assign(component.staticConfig, { [ALERT_DIALOG_PART]: part });
57
+ };
58
+ const NativeAlertDialogTriggerFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogTrigger" });
59
+ markAlertDialogPart(NativeAlertDialogTriggerFrame, "trigger");
60
+ const AlertDialogTrigger = (0, import_core.createStyledHOC)(NativeAlertDialogTriggerFrame, function AlertDialogTrigger2(props, forwardedRef) {
61
+ if (props["__native"]) {
62
+ const { __native, onPress, __onPress, ...rest } = props;
63
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NativeAlertDialogTriggerFrame, {
64
+ ...rest,
65
+ onPress: (0, import_helpers.composeEventHandlers)(onPress, __onPress)
66
+ });
67
+ }
68
+ const { scope, ...triggerProps } = props;
69
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTrigger, {
70
+ scope: getAlertDialogScope(scope),
71
+ ...triggerProps,
72
+ ref: forwardedRef
73
+ });
84
74
  });
85
75
  const AlertDialogPortal = function AlertDialogPortal2(props) {
86
- const {
87
- scope,
88
- ...portalProps
89
- } = props;
90
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogPortal, {
91
- scope: getAlertDialogScope(scope),
92
- ...portalProps
93
- });
76
+ const { scope, ...portalProps } = props;
77
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogPortal, {
78
+ scope: getAlertDialogScope(scope),
79
+ ...portalProps
80
+ });
94
81
  };
95
- const AlertDialogOverlay = (0, import_core.styled)(import_dialog.DialogOverlayFrame, {
96
- name: "AlertDialogOverlay"
97
- }).styleable(function AlertDialogOverlay2(props, forwardedRef) {
98
- const {
99
- scope,
100
- ...overlayProps
101
- } = props;
102
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogOverlay, {
103
- scope: getAlertDialogScope(scope),
104
- ...overlayProps,
105
- ref: forwardedRef
106
- });
82
+ const AlertDialogOverlayFrame = (0, import_core2.styled)(import_dialog.DialogOverlayFrame, { displayName: "AlertDialogOverlay" });
83
+ const AlertDialogOverlay = (0, import_core.createStyledHOC)(AlertDialogOverlayFrame, function AlertDialogOverlay2(props, forwardedRef) {
84
+ const { scope, ...overlayProps } = props;
85
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogOverlay, {
86
+ scope: getAlertDialogScope(scope),
87
+ ...overlayProps,
88
+ ref: forwardedRef
89
+ });
107
90
  });
108
91
  const CONTENT_NAME = "AlertDialogContent";
109
- const {
110
- Provider: AlertDialogContextProvider,
111
- useStyledContext: useAlertDialogContentContext
112
- } = (0, import_core.createStyledContext)({}, "AlertDialogContext");
113
- const AlertDialogContent = React.forwardRef(function AlertDialogContent2(props, forwardedRef) {
114
- const {
115
- scope,
116
- children,
117
- ...contentProps
118
- } = props;
119
- const dialogScope = getAlertDialogScope(scope);
120
- const contentRef = React.useRef(null);
121
- const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef);
122
- const cancelRef = React.useRef(null);
123
- const destructiveRef = React.useRef(null);
124
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogWarningProvider, {
125
- contentName: CONTENT_NAME,
126
- titleName: TITLE_NAME,
127
- docsSlug: "alert-dialog",
128
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AlertDialogContextProvider, {
129
- scope,
130
- cancelRef,
131
- destructiveRef,
132
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_dialog.DialogContent, {
133
- role: "alertdialog",
134
- "aria-modal": true,
135
- scope: dialogScope,
136
- ...contentProps,
137
- ref: composedRefs,
138
- onOpenAutoFocus: (0, import_helpers.composeEventHandlers)(contentProps.onOpenAutoFocus, event => {
139
- event.preventDefault();
140
- if (import_constants.isWeb) cancelRef.current?.focus({
141
- preventScroll: true
142
- });
143
- }),
144
- onPointerDownOutside: event => event.preventDefault(),
145
- onInteractOutside: event => event.preventDefault(),
146
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Slottable, {
147
- children
148
- }), process.env.NODE_ENV === "development" && /* @__PURE__ */(0, import_jsx_runtime.jsx)(DescriptionWarning, {
149
- contentRef
150
- })]
151
- })
152
- })
153
- });
92
+ const { Provider: AlertDialogContextProvider, useStyledContext: useAlertDialogContentContext } = (0, import_core2.createStyledContext)({}, "AlertDialogContext");
93
+ const AlertDialogContent = (0, import_core.createRefComponent)(function AlertDialogContent2(props, forwardedRef) {
94
+ const { scope, children, ...contentProps } = props;
95
+ const dialogScope = getAlertDialogScope(scope);
96
+ const contentRef = React.useRef(null);
97
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef);
98
+ const cancelRef = React.useRef(null);
99
+ const destructiveRef = React.useRef(null);
100
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogWarningProvider, {
101
+ contentName: CONTENT_NAME,
102
+ titleName: TITLE_NAME,
103
+ docsSlug: "alert-dialog",
104
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialogContextProvider, {
105
+ scope,
106
+ cancelRef,
107
+ destructiveRef,
108
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogContent, {
109
+ role: "alertdialog",
110
+ "aria-modal": true,
111
+ scope: dialogScope,
112
+ ...contentProps,
113
+ ref: composedRefs,
114
+ onOpenAutoFocus: (0, import_helpers.composeEventHandlers)(contentProps.onOpenAutoFocus, (event) => {
115
+ event.cancel();
116
+ if (import_constants.isWeb) cancelRef.current?.focus({ preventScroll: true });
117
+ }),
118
+ onPointerDownOutside: (event) => event.cancel(),
119
+ onInteractOutside: (event) => event.cancel(),
120
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core2.Slottable, { children }), process.env.NODE_ENV === "development" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionWarning, { contentRef })]
121
+ })
122
+ })
123
+ });
154
124
  });
155
125
  const TITLE_NAME = "AlertDialogTitle";
156
- const AlertDialogTitle = (0, import_core.styled)(import_core.View, {
157
- name: TITLE_NAME
158
- }).styleable(function AlertDialogTitle2(props, forwardedRef) {
159
- const {
160
- scope,
161
- ...titleProps
162
- } = props;
163
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, {
164
- scope: getAlertDialogScope(scope),
165
- ...titleProps,
166
- ref: forwardedRef
167
- });
126
+ const AlertDialogTitleFrame = (0, import_core2.styled)(import_core2.View, { displayName: TITLE_NAME });
127
+ markAlertDialogPart(AlertDialogTitleFrame, "title");
128
+ const AlertDialogTitle = (0, import_core.createStyledHOC)(AlertDialogTitleFrame, function AlertDialogTitle2(props, forwardedRef) {
129
+ const { scope, ...titleProps } = props;
130
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, {
131
+ scope: getAlertDialogScope(scope),
132
+ ...titleProps,
133
+ ref: forwardedRef
134
+ });
168
135
  });
169
136
  const DESCRIPTION_NAME = "AlertDialogDescription";
170
- const AlertDialogDescription = (0, import_core.styled)(import_core.View, {
171
- name: DESCRIPTION_NAME
172
- }).styleable(function AlertDialogDescription2(props, forwardedRef) {
173
- const {
174
- scope,
175
- ...descriptionProps
176
- } = props;
177
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, {
178
- scope: getAlertDialogScope(scope),
179
- ...descriptionProps,
180
- ref: forwardedRef
181
- });
137
+ const AlertDialogDescriptionFrame = (0, import_core2.styled)(import_core2.View, { displayName: DESCRIPTION_NAME });
138
+ markAlertDialogPart(AlertDialogDescriptionFrame, "description");
139
+ const AlertDialogDescription = (0, import_core.createStyledHOC)(AlertDialogDescriptionFrame, function AlertDialogDescription2(props, forwardedRef) {
140
+ const { scope, ...descriptionProps } = props;
141
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, {
142
+ scope: getAlertDialogScope(scope),
143
+ ...descriptionProps,
144
+ ref: forwardedRef
145
+ });
182
146
  });
183
- const AlertDialogAction = (0, import_core.styled)(import_core.View, {
184
- name: "AlertDialogAction"
185
- }).styleable(function AlertDialogAction2(props, forwardedRef) {
186
- const {
187
- scope,
188
- ...actionProps
189
- } = props;
190
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
191
- scope: getAlertDialogScope(scope),
192
- ...actionProps,
193
- ref: forwardedRef
194
- });
147
+ const AlertDialogActionFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogAction" });
148
+ markAlertDialogPart(AlertDialogActionFrame, "action");
149
+ const AlertDialogAction = (0, import_core.createStyledHOC)(AlertDialogActionFrame, function AlertDialogAction2(props, forwardedRef) {
150
+ const { scope, ...actionProps } = props;
151
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
152
+ scope: getAlertDialogScope(scope),
153
+ ...actionProps,
154
+ ref: forwardedRef
155
+ });
195
156
  });
196
- const AlertDialogCancel = (0, import_core.styled)(import_core.View, {
197
- name: "AlertDialogCancel"
198
- }).styleable(function AlertDialogCancel2(props, forwardedRef) {
199
- const {
200
- scope,
201
- ...cancelProps
202
- } = props;
203
- const {
204
- cancelRef
205
- } = useAlertDialogContentContext(scope);
206
- const ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, cancelRef);
207
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
208
- scope: getAlertDialogScope(scope),
209
- ...cancelProps,
210
- ref
211
- });
157
+ const AlertDialogCancelFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogCancel" });
158
+ markAlertDialogPart(AlertDialogCancelFrame, "cancel");
159
+ const AlertDialogCancel = (0, import_core.createStyledHOC)(AlertDialogCancelFrame, function AlertDialogCancel2(props, forwardedRef) {
160
+ const { scope, ...cancelProps } = props;
161
+ const { cancelRef } = useAlertDialogContentContext(scope);
162
+ const ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, cancelRef);
163
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
164
+ scope: getAlertDialogScope(scope),
165
+ ...cancelProps,
166
+ ref
167
+ });
212
168
  });
213
- const AlertDialogDestructive = (0, import_core.styled)(import_core.View, {
214
- name: "AlertDialogDestructive"
215
- }).styleable(function AlertDialogDestructive2(props, forwardedRef) {
216
- const {
217
- scope,
218
- ...destructiveProps
219
- } = props;
220
- const {
221
- destructiveRef
222
- } = useAlertDialogContentContext(scope);
223
- const ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, destructiveRef);
224
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
225
- scope: getAlertDialogScope(scope),
226
- ...destructiveProps,
227
- ref
228
- });
169
+ const AlertDialogDestructiveFrame = (0, import_core2.styled)(import_core2.View, { displayName: "AlertDialogDestructive" });
170
+ markAlertDialogPart(AlertDialogDestructiveFrame, "destructive");
171
+ const AlertDialogDestructive = (0, import_core.createStyledHOC)(AlertDialogDestructiveFrame, function AlertDialogDestructive2(props, forwardedRef) {
172
+ const { scope, ...destructiveProps } = props;
173
+ const { destructiveRef } = useAlertDialogContentContext(scope);
174
+ const ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, destructiveRef);
175
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
176
+ scope: getAlertDialogScope(scope),
177
+ ...destructiveProps,
178
+ ref
179
+ });
229
180
  });
230
- const DescriptionWarning = ({
231
- contentRef
232
- }) => {
233
- if (process.env.NODE_ENV === "development") React.useEffect(() => {
234
- if (!import_constants.isWeb) return;
235
- if (!document.getElementById(
236
- // @ts-ignore
237
- contentRef.current?.getAttribute("aria-describedby"))) console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
181
+ const DescriptionWarning = ({ contentRef }) => {
182
+ if (process.env.NODE_ENV === "development") React.useEffect(() => {
183
+ if (!import_constants.isWeb) return;
184
+ 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.
238
185
 
239
186
  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.
240
187
 
241
188
  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.
242
189
 
243
190
  For more information, see https://tamagui.dev/docs/components/alert-dialog`);
244
- }, [contentRef]);
245
- return null;
191
+ }, [contentRef]);
192
+ return null;
246
193
  };
247
- const AlertDialogInner = props => {
248
- const {
249
- scope,
250
- native,
251
- ...alertDialogProps
252
- } = props;
253
- const dialogScope = getAlertDialogScope(scope);
254
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.Dialog, {
255
- scope: dialogScope,
256
- ...alertDialogProps,
257
- modal: true
258
- });
194
+ const AlertDialogInner = (props) => {
195
+ const { scope, native, ...alertDialogProps } = props;
196
+ const dialogScope = getAlertDialogScope(scope);
197
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, {
198
+ scope: dialogScope,
199
+ ...alertDialogProps,
200
+ modal: true
201
+ });
259
202
  };
260
203
  function forEachChildDeep(children, onChild) {
261
- for (const child of children) {
262
- if (!React.isValidElement(child)) continue;
263
- if (!onChild(child)) continue;
264
- const childProps = child.props;
265
- if (childProps.children) forEachChildDeep(React.Children.toArray(childProps.children), onChild);
266
- }
204
+ for (const child of children) {
205
+ if (!React.isValidElement(child)) continue;
206
+ if (!onChild(child)) continue;
207
+ const childProps = child.props;
208
+ if (childProps.children) forEachChildDeep(React.Children.toArray(childProps.children), onChild);
209
+ }
267
210
  }
268
211
  const AlertDialog = (0, import_helpers.withStaticProperties)(AlertDialogInner, {
269
- Trigger: AlertDialogTrigger,
270
- Portal: AlertDialogPortal,
271
- Overlay: AlertDialogOverlay,
272
- Content: AlertDialogContent,
273
- Action: AlertDialogAction,
274
- Cancel: AlertDialogCancel,
275
- Destructive: AlertDialogDestructive,
276
- Title: AlertDialogTitle,
277
- Description: AlertDialogDescription
212
+ Trigger: AlertDialogTrigger,
213
+ Portal: AlertDialogPortal,
214
+ Overlay: AlertDialogOverlay,
215
+ Content: AlertDialogContent,
216
+ Action: AlertDialogAction,
217
+ Cancel: AlertDialogCancel,
218
+ Destructive: AlertDialogDestructive,
219
+ Title: AlertDialogTitle,
220
+ Description: AlertDialogDescription
278
221
  });
279
- AlertDialog.displayName = ROOT_NAME;
222
+ AlertDialog.displayName = ROOT_NAME;