@tamagui/alert-dialog 2.0.0-rc.8 → 2.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.
@@ -2,33 +2,35 @@ 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 AlertDialog_exports = {};
33
35
  __export(AlertDialog_exports, {
34
36
  AlertDialog: () => AlertDialog,
@@ -43,225 +45,226 @@ __export(AlertDialog_exports, {
43
45
  AlertDialogTrigger: () => AlertDialogTrigger
44
46
  });
45
47
  module.exports = __toCommonJS(AlertDialog_exports);
46
- var import_compose_refs = require("@tamagui/compose-refs"),
47
- import_constants = require("@tamagui/constants"),
48
- import_core = require("@tamagui/core"),
49
- import_dialog = require("@tamagui/dialog"),
50
- import_helpers = require("@tamagui/helpers"),
51
- import_use_controllable_state = require("@tamagui/use-controllable-state"),
52
- React = __toESM(require("react"), 1),
53
- import_react_native = require("react-native-web"),
54
- import_jsx_runtime = require("react/jsx-runtime");
55
- const getAlertDialogScope = scope => scope,
56
- ROOT_NAME = "AlertDialog",
57
- TRIGGER_NAME = "AlertDialogTrigger",
58
- NativeAlertDialogTriggerFrame = (0, import_core.styled)(import_core.View, {
59
- name: TRIGGER_NAME
60
- }),
61
- AlertDialogTrigger = NativeAlertDialogTriggerFrame.styleable(function (props, forwardedRef) {
62
- if (props.__native) {
63
- const {
64
- __native,
65
- onPress,
66
- __onPress,
67
- ...rest
68
- } = props;
69
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(NativeAlertDialogTriggerFrame, {
70
- ...rest,
71
- onPress: (0, import_helpers.composeEventHandlers)(onPress, __onPress)
72
- });
73
- }
48
+ var import_compose_refs = require("@tamagui/compose-refs");
49
+ var import_constants = require("@tamagui/constants");
50
+ var import_core = require("@tamagui/core");
51
+ var import_dialog = require("@tamagui/dialog");
52
+ var import_helpers = require("@tamagui/helpers");
53
+ require("@tamagui/use-controllable-state");
54
+ var React = __toESM(require("react"), 1);
55
+ require("react-native-web");
56
+ var import_jsx_runtime = require("react/jsx-runtime");
57
+ const getAlertDialogScope = scope => scope;
58
+ 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"]) {
74
64
  const {
75
- scope,
76
- ...triggerProps
65
+ __native,
66
+ onPress,
67
+ __onPress,
68
+ ...rest
77
69
  } = props;
78
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogTrigger, {
79
- scope: getAlertDialogScope(scope),
80
- ...triggerProps,
81
- ref: forwardedRef
70
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(NativeAlertDialogTriggerFrame, {
71
+ ...rest,
72
+ onPress: (0, import_helpers.composeEventHandlers)(onPress, __onPress)
82
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
83
  });
84
- const AlertDialogPortal = function (props) {
85
- const {
86
- scope,
87
- ...portalProps
88
- } = props;
89
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogPortal, {
90
- scope: getAlertDialogScope(scope),
91
- ...portalProps
92
- });
93
- },
94
- OVERLAY_NAME = "AlertDialogOverlay",
95
- AlertDialogOverlayFrame = (0, import_core.styled)(import_dialog.DialogOverlayFrame, {
96
- name: OVERLAY_NAME
97
- }),
98
- AlertDialogOverlay = AlertDialogOverlayFrame.styleable(function (props, forwardedRef) {
99
- const {
84
+ });
85
+ 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
+ });
94
+ };
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
+ });
107
+ });
108
+ 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, {
100
129
  scope,
101
- ...overlayProps
102
- } = props;
103
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogOverlay, {
104
- scope: getAlertDialogScope(scope),
105
- ...overlayProps,
106
- ref: forwardedRef
107
- });
108
- }),
109
- CONTENT_NAME = "AlertDialogContent",
110
- {
111
- Provider: AlertDialogContextProvider,
112
- useStyledContext: useAlertDialogContentContext
113
- } = (0, import_core.createStyledContext)({}, "AlertDialogContext"),
114
- AlertDialogContent = React.forwardRef(function (props, forwardedRef) {
115
- const {
116
- scope,
117
- children,
118
- ...contentProps
119
- } = props,
120
- dialogScope = getAlertDialogScope(scope),
121
- contentRef = React.useRef(null),
122
- composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef),
123
- cancelRef = React.useRef(null),
124
- destructiveRef = React.useRef(null);
125
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogWarningProvider, {
126
- contentName: CONTENT_NAME,
127
- titleName: TITLE_NAME,
128
- docsSlug: "alert-dialog",
129
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AlertDialogContextProvider, {
130
- scope,
131
- cancelRef,
132
- destructiveRef,
133
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_dialog.DialogContent, {
134
- role: "alertdialog",
135
- "aria-modal": !0,
136
- scope: dialogScope,
137
- ...contentProps,
138
- ref: composedRefs,
139
- onOpenAutoFocus: (0, import_helpers.composeEventHandlers)(contentProps.onOpenAutoFocus, event => {
140
- event.preventDefault(), import_constants.isWeb && cancelRef.current?.focus({
141
- preventScroll: !0
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
- })
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
+ })]
152
151
  })
153
- });
154
- }),
155
- TITLE_NAME = "AlertDialogTitle",
156
- AlertDialogTitleFrame = (0, import_core.styled)(import_core.View, {
157
- name: TITLE_NAME
158
- }),
159
- AlertDialogTitle = AlertDialogTitleFrame.styleable(function (props, forwardedRef) {
160
- const {
161
- scope,
162
- ...titleProps
163
- } = props;
164
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, {
165
- scope: getAlertDialogScope(scope),
166
- ...titleProps,
167
- ref: forwardedRef
168
- });
169
- }),
170
- DESCRIPTION_NAME = "AlertDialogDescription",
171
- AlertDialogDescriptionFrame = (0, import_core.styled)(import_core.View, {
172
- name: DESCRIPTION_NAME
173
- }),
174
- AlertDialogDescription = AlertDialogDescriptionFrame.styleable(function (props, forwardedRef) {
175
- const {
176
- scope,
177
- ...descriptionProps
178
- } = props;
179
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, {
180
- scope: getAlertDialogScope(scope),
181
- ...descriptionProps,
182
- ref: forwardedRef
183
- });
184
- }),
185
- ACTION_NAME = "AlertDialogAction",
186
- AlertDialogActionFrame = (0, import_core.styled)(import_core.View, {
187
- name: ACTION_NAME
188
- }),
189
- AlertDialogAction = AlertDialogActionFrame.styleable(function (props, forwardedRef) {
190
- const {
191
- scope,
192
- ...actionProps
193
- } = props;
194
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
195
- scope: getAlertDialogScope(scope),
196
- ...actionProps,
197
- ref: forwardedRef
198
- });
199
- }),
200
- CANCEL_NAME = "AlertDialogCancel",
201
- AlertDialogCancelFrame = (0, import_core.styled)(import_core.View, {
202
- name: CANCEL_NAME
203
- }),
204
- AlertDialogCancel = AlertDialogCancelFrame.styleable(function (props, forwardedRef) {
205
- const {
206
- scope,
207
- ...cancelProps
208
- } = props,
209
- {
210
- cancelRef
211
- } = useAlertDialogContentContext(scope),
212
- ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, cancelRef);
213
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
214
- scope: getAlertDialogScope(scope),
215
- ...cancelProps,
216
- ref
217
- });
218
- }),
219
- DESTRUCTIVE_NAME = "AlertDialogDestructive",
220
- AlertDialogDestructiveFrame = (0, import_core.styled)(import_core.View, {
221
- name: DESTRUCTIVE_NAME
222
- }),
223
- AlertDialogDestructive = AlertDialogDestructiveFrame.styleable(function (props, forwardedRef) {
224
- const {
225
- scope,
226
- ...destructiveProps
227
- } = props,
228
- {
229
- destructiveRef
230
- } = useAlertDialogContentContext(scope),
231
- ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, destructiveRef);
232
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.DialogClose, {
233
- scope: getAlertDialogScope(scope),
234
- ...destructiveProps,
235
- ref
236
- });
237
- }),
238
- DescriptionWarning = ({
239
- contentRef
240
- }) => (process.env.NODE_ENV === "development" && React.useEffect(() => {
152
+ })
153
+ });
154
+ });
155
+ 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
+ });
168
+ });
169
+ 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
+ });
182
+ });
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
+ });
195
+ });
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
+ });
212
+ });
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
+ });
229
+ });
230
+ const DescriptionWarning = ({
231
+ contentRef
232
+ }) => {
233
+ if (process.env.NODE_ENV === "development") React.useEffect(() => {
241
234
  if (!import_constants.isWeb) return;
242
- document.getElementById(
235
+ if (!document.getElementById(
243
236
  // @ts-ignore
244
- contentRef.current?.getAttribute("aria-describedby")) || console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
237
+ contentRef.current?.getAttribute("aria-describedby"))) console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
245
238
 
246
239
  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.
247
240
 
248
241
  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.
249
242
 
250
243
  For more information, see https://tamagui.dev/docs/components/alert-dialog`);
251
- }, [contentRef]), null),
252
- AlertDialogInner = props => {
253
- const {
254
- scope,
255
- native,
256
- ...alertDialogProps
257
- } = props,
258
- dialogScope = getAlertDialogScope(scope);
259
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dialog.Dialog, {
260
- scope: dialogScope,
261
- ...alertDialogProps,
262
- modal: !0
263
- });
264
- };
244
+ }, [contentRef]);
245
+ return null;
246
+ };
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
+ });
259
+ };
260
+ 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
+ }
267
+ }
265
268
  const AlertDialog = (0, import_helpers.withStaticProperties)(AlertDialogInner, {
266
269
  Trigger: AlertDialogTrigger,
267
270
  Portal: AlertDialogPortal,