@tamagui/alert-dialog 1.0.1-beta.136 → 1.0.1-beta.139
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.
- package/dist/cjs/AlertDialog.js +20 -18
- package/dist/cjs/AlertDialog.js.map +2 -2
- package/dist/esm/AlertDialog.js +20 -18
- package/dist/esm/AlertDialog.js.map +2 -2
- package/dist/jsx/AlertDialog.js +20 -18
- package/dist/jsx/AlertDialog.js.map +2 -2
- package/package.json +17 -17
- package/src/AlertDialog.tsx +22 -18
package/dist/cjs/AlertDialog.js
CHANGED
|
@@ -169,21 +169,23 @@ const AlertDialogCancel = React.forwardRef((props, forwardedRef) => {
|
|
|
169
169
|
});
|
|
170
170
|
AlertDialogCancel.displayName = CANCEL_NAME;
|
|
171
171
|
const DescriptionWarning = ({ contentRef }) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
172
|
+
if (process.env.NODE_ENV === "development") {
|
|
173
|
+
React.useEffect(() => {
|
|
174
|
+
var _a;
|
|
175
|
+
if (!import_core.isWeb)
|
|
176
|
+
return;
|
|
177
|
+
const hasDescription = document.getElementById((_a = contentRef.current) == null ? void 0 : _a.getAttribute("aria-describedby"));
|
|
178
|
+
if (!hasDescription) {
|
|
179
|
+
console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
|
|
180
|
+
|
|
181
|
+
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.
|
|
182
|
+
|
|
183
|
+
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.
|
|
184
|
+
|
|
185
|
+
For more information, see https://tamagui.dev/docs/components/alert-dialog`);
|
|
186
|
+
}
|
|
187
|
+
}, [contentRef]);
|
|
188
|
+
}
|
|
187
189
|
return null;
|
|
188
190
|
};
|
|
189
191
|
const AlertDialogInner = (props) => {
|
|
@@ -223,9 +225,9 @@ const AlertDialogInner = (props) => {
|
|
|
223
225
|
const style = name === ACTION_NAME ? "default" : "cancel";
|
|
224
226
|
const text = getStringChildren(child);
|
|
225
227
|
const onPress = () => {
|
|
226
|
-
var _a
|
|
227
|
-
;
|
|
228
|
-
(
|
|
228
|
+
var _a;
|
|
229
|
+
const childProps = child.props;
|
|
230
|
+
(_a = childProps == null ? void 0 : childProps.onPress) == null ? void 0 : _a.call(childProps, { native: true });
|
|
229
231
|
setOpen(false);
|
|
230
232
|
};
|
|
231
233
|
buttons.push({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AlertDialog.tsx"],
|
|
4
|
-
"sourcesContent": ["// forked from radix-ui\n// https://github.com/radix-ui/primitives/blob/main/packages/react/alert-dialog/src/AlertDialog.tsx\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Slottable,\n TamaguiElement,\n composeEventHandlers,\n isTamaguiElement,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport {\n Dialog,\n DialogClose,\n DialogCloseProps,\n DialogContent,\n DialogContentProps,\n DialogDescription,\n DialogDescriptionProps,\n DialogOverlay,\n DialogOverlayProps,\n DialogPortal,\n DialogPortalProps,\n DialogProps,\n DialogTitle,\n DialogTitleProps,\n DialogTrigger,\n DialogTriggerProps,\n DialogWarningProvider,\n createDialogScope,\n} from '@tamagui/dialog'\nimport { YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { Alert } from 'react-native'\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst ROOT_NAME = 'AlertDialog'\n\ntype ScopedProps<P> = P & { __scopeAlertDialog?: Scope }\nconst [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [\n createDialogScope,\n])\n\nconst useDialogScope = createDialogScope()\n\ntype AlertDialogProps = DialogProps & {\n native?: boolean\n}\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'AlertDialogTrigger'\n\ninterface AlertDialogTriggerProps extends DialogTriggerProps {}\n\nconst NativeAlertDialogTriggerFrame = styled(YStack, {\n name: 'DialogTrigger',\n})\n\nconst AlertDialogTrigger = React.forwardRef<TamaguiElement, AlertDialogTriggerProps>(\n (props: ScopedProps<AlertDialogTriggerProps>, forwardedRef) => {\n if (props['__native']) {\n const { __native, onPress, __onPress, ...rest } = props as any\n return (\n <NativeAlertDialogTriggerFrame\n {...rest}\n onPress={composeEventHandlers(onPress, __onPress)}\n />\n )\n }\n\n const { __scopeAlertDialog, ...triggerProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTrigger {...dialogScope} {...triggerProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'AlertDialogPortal'\n\ninterface AlertDialogPortalProps extends DialogPortalProps {}\n\nconst AlertDialogPortal: React.FC<AlertDialogPortalProps> = (\n props: ScopedProps<AlertDialogPortalProps>\n) => {\n const { __scopeAlertDialog, ...portalProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogPortal {...dialogScope} {...portalProps} />\n}\n\nAlertDialogPortal.displayName = PORTAL_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'AlertDialogOverlay'\n\ninterface AlertDialogOverlayProps extends DialogOverlayProps {}\n\nconst AlertDialogOverlay = React.forwardRef<TamaguiElement, AlertDialogOverlayProps>(\n (props: ScopedProps<AlertDialogOverlayProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...overlayProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogOverlay {...dialogScope} {...overlayProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogOverlay.displayName = OVERLAY_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'AlertDialogContent'\n\ntype AlertDialogContentContextValue = {\n cancelRef: React.MutableRefObject<TamaguiElement | null>\n}\n\nconst [AlertDialogContentProvider, useAlertDialogContentContext] =\n createAlertDialogContext<AlertDialogContentContextValue>(CONTENT_NAME)\n\ninterface AlertDialogContentProps\n extends Omit<DialogContentProps, 'onPointerDownOutside' | 'onInteractOutside'> {}\n\nconst AlertDialogContent = React.forwardRef<TamaguiElement, AlertDialogContentProps>(\n (props: ScopedProps<AlertDialogContentProps>, forwardedRef) => {\n const { __scopeAlertDialog, children, ...contentProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const contentRef = React.useRef<TamaguiElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const cancelRef = React.useRef<TamaguiElement | null>(null)\n\n return (\n <DialogWarningProvider\n contentName={CONTENT_NAME}\n titleName={TITLE_NAME}\n docsSlug=\"alert-dialog\"\n >\n <AlertDialogContentProvider scope={__scopeAlertDialog} cancelRef={cancelRef}>\n <DialogContent\n // @ts-ignore\n role=\"alertdialog\"\n {...dialogScope}\n {...contentProps}\n ref={composedRefs}\n onOpenAutoFocus={composeEventHandlers(contentProps.onOpenAutoFocus, (event) => {\n event.preventDefault()\n if (isWeb) {\n // @ts-ignore\n cancelRef.current?.focus({ preventScroll: true })\n }\n })}\n onPointerDownOutside={(event) => event.preventDefault()}\n onInteractOutside={(event) => event.preventDefault()}\n >\n {/**\n * We have to use `Slottable` here as we cannot wrap the `AlertDialogContentProvider`\n * around everything, otherwise the `DescriptionWarning` would be rendered straight away.\n * This is because we want the accessibility checks to run only once the content is actually\n * open and that behaviour is already encapsulated in `DialogContent`.\n */}\n <Slottable>{children}</Slottable>\n {process.env.NODE_ENV === 'development' && (\n <DescriptionWarning contentRef={contentRef} />\n )}\n </DialogContent>\n </AlertDialogContentProvider>\n </DialogWarningProvider>\n )\n }\n)\n\nAlertDialogContent.displayName = CONTENT_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'AlertDialogTitle'\n\ntype AlertDialogTitleProps = DialogTitleProps\n\nconst AlertDialogTitle = React.forwardRef<TamaguiElement, AlertDialogTitleProps>(\n (props: ScopedProps<AlertDialogTitleProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...titleProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTitle {...dialogScope} {...titleProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'AlertDialogDescription'\n\ntype AlertDialogDescriptionProps = DialogDescriptionProps\n\nconst AlertDialogDescription = React.forwardRef<TamaguiElement, AlertDialogDescriptionProps>(\n (props: ScopedProps<AlertDialogDescriptionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...descriptionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogDescription {...dialogScope} {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'AlertDialogAction'\n\ntype AlertDialogActionProps = DialogCloseProps\n\nconst AlertDialogAction = React.forwardRef<TamaguiElement, AlertDialogActionProps>(\n (props: ScopedProps<AlertDialogActionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...actionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogClose {...dialogScope} {...actionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogCancel\n * -----------------------------------------------------------------------------------------------*/\n\nconst CANCEL_NAME = 'AlertDialogCancel'\n\ninterface AlertDialogCancelProps extends DialogCloseProps {}\n\nconst AlertDialogCancel = React.forwardRef<TamaguiElement, AlertDialogCancelProps>(\n (props: ScopedProps<AlertDialogCancelProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...cancelProps } = props\n const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog)\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const ref = useComposedRefs(forwardedRef, cancelRef)\n return <DialogClose {...dialogScope} {...cancelProps} ref={ref} />\n }\n)\n\nAlertDialogCancel.displayName = CANCEL_NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype DescriptionWarningProps = {\n contentRef: React.RefObject<TamaguiElement>\n}\n\nconst DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef }) => {\n const MESSAGE = `\\`${CONTENT_NAME}\\` requires a description for the component to be accessible for screen reader users.\n\nYou 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.\n\nAlternatively, 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.\n\nFor more information, see https://tamagui.dev/docs/components/alert-dialog`\n\n React.useEffect(() => {\n if (!isWeb) return\n const hasDescription = document.getElementById(\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n contentRef.current?.getAttribute('aria-describedby')!\n )\n if (!hasDescription) console.warn(MESSAGE)\n }, [MESSAGE, contentRef])\n\n return null\n}\n\nconst AlertDialogInner: React.FC<AlertDialogProps> = (props: ScopedProps<AlertDialogProps>) => {\n const { __scopeAlertDialog, native, ...alertDialogProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n const [open, setOpen] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen || false,\n onChange: props.onOpenChange,\n })\n\n let triggerElement: any = null\n let title = ''\n let description = ''\n const buttons: {\n text: string\n onPress: (value?: string | undefined) => void\n style?: 'default' | 'cancel' | 'destructive'\n }[] = []\n\n forEachChildDeep(React.Children.toArray(props.children), (child) => {\n if (!React.isValidElement(child)) return false\n const name = isTamaguiElement(child)\n ? child.type.staticConfig.componentName\n : (child.type['displayName'] as string | undefined)\n switch (name) {\n case TRIGGER_NAME: {\n triggerElement = React.cloneElement(child as any, {\n __native: true,\n })\n return false\n }\n case TITLE_NAME: {\n title = getStringChildren(child)\n return false\n }\n case DESCRIPTION_NAME: {\n description = getStringChildren(child)\n return false\n }\n case ACTION_NAME:\n case CANCEL_NAME: {\n const style = name === ACTION_NAME ? 'default' : 'cancel'\n const text = getStringChildren(child)\n const onPress = () => {\n ;(child.props as any)?.onPress?.({ native: true })\n setOpen(false)\n }\n buttons.push({\n style,\n text,\n // @ts-ignore\n onPress,\n })\n return false\n }\n default: {\n return true\n }\n }\n })\n\n React.useLayoutEffect(() => {\n if (!open || !native) return\n if (title || description) {\n Alert.alert(title, description, buttons)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [native, open])\n\n if (native) {\n return React.cloneElement(triggerElement, {\n __onPress: () => {\n setOpen(true)\n },\n })\n }\n }\n\n return <Dialog {...dialogScope} {...alertDialogProps} modal />\n}\n\nfunction forEachChildDeep(\n children: React.ReactNode[],\n onChild: (el: React.ReactElement) => boolean\n) {\n for (const child of children) {\n if (!React.isValidElement(child)) continue\n if (!onChild(child)) continue\n if (child.props.children) {\n forEachChildDeep(React.Children.toArray(child.props.children), onChild)\n }\n }\n}\n\nfunction getStringChildren(child: React.ReactElement) {\n let string = ''\n forEachChildDeep(React.Children.toArray(child), (child) => {\n if (typeof child.props.children === 'string') {\n string = child.props.children\n return false\n }\n return true\n })\n return string\n}\n\nconst AlertDialog = withStaticProperties(AlertDialogInner, {\n Trigger: AlertDialogTrigger,\n Portal: AlertDialogPortal,\n Overlay: AlertDialogOverlay,\n Content: AlertDialogContent,\n Action: AlertDialogAction,\n Cancel: AlertDialogCancel,\n Title: AlertDialogTitle,\n Description: AlertDialogDescription,\n})\n\nAlertDialog.displayName = ROOT_NAME\n\nexport {\n createAlertDialogScope,\n //\n AlertDialog,\n AlertDialogTrigger,\n AlertDialogPortal,\n AlertDialogOverlay,\n AlertDialogContent,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogTitle,\n AlertDialogDescription,\n}\nexport type {\n AlertDialogProps,\n AlertDialogTriggerProps,\n AlertDialogPortalProps,\n AlertDialogOverlayProps,\n AlertDialogContentProps,\n AlertDialogActionProps,\n AlertDialogCancelProps,\n AlertDialogTitleProps,\n AlertDialogDescriptionProps,\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAgC;AAChC,kBAQO;AACP,4BAA0C;AAC1C,oBAmBO;AACP,oBAAuB;AACvB,oCAAqC;AACrC,YAAuB;AACvB,0BAAsB;AAMtB,MAAM,YAAY;AAGlB,MAAM,CAAC,0BAA0B,0BAA0B,8CAAmB,WAAW;AAAA,EACvF;AACF,CAAC;AAED,MAAM,iBAA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;AAIpB,MAAM,oBAAoB,MAAM,WAC9B,CAAC,OAA4C,iBAAiB;AAC5D,QAAM,EAAE,uBAAuB,gBAAgB;AAC/C,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAa,GAAG;AAAA,IAAc,GAAG;AAAA,IAAa,KAAK;AAAA,GAAc;AAC3E,CACF;AAEA,kBAAkB,cAAc;AAMhC,MAAM,cAAc;AAIpB,MAAM,oBAAoB,MAAM,WAC9B,CAAC,OAA4C,iBAAiB;AAC5D,QAAM,EAAE,uBAAuB,gBAAgB;AAC/C,QAAM,EAAE,cAAc,6BAA6B,aAAa,kBAAkB;AAClF,QAAM,cAAc,eAAe,kBAAkB;AACrD,QAAM,MAAM,yCAAgB,cAAc,SAAS;AACnD,SAAO,oCAAC;AAAA,IAAa,GAAG;AAAA,IAAc,GAAG;AAAA,IAAa;AAAA,GAAU;AAClE,CACF;AAEA,kBAAkB,cAAc;AAQhC,MAAM,qBAAwD,CAAC,EAAE,iBAAiB;AAChF,
|
|
4
|
+
"sourcesContent": ["// forked from radix-ui\n// https://github.com/radix-ui/primitives/blob/main/packages/react/alert-dialog/src/AlertDialog.tsx\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Slottable,\n TamaguiElement,\n composeEventHandlers,\n isTamaguiElement,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport {\n Dialog,\n DialogClose,\n DialogCloseProps,\n DialogContent,\n DialogContentProps,\n DialogDescription,\n DialogDescriptionProps,\n DialogOverlay,\n DialogOverlayProps,\n DialogPortal,\n DialogPortalProps,\n DialogProps,\n DialogTitle,\n DialogTitleProps,\n DialogTrigger,\n DialogTriggerProps,\n DialogWarningProvider,\n createDialogScope,\n} from '@tamagui/dialog'\nimport { YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { Alert } from 'react-native'\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst ROOT_NAME = 'AlertDialog'\n\ntype ScopedProps<P> = P & { __scopeAlertDialog?: Scope }\nconst [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [\n createDialogScope,\n])\n\nconst useDialogScope = createDialogScope()\n\ntype AlertDialogProps = DialogProps & {\n native?: boolean\n}\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'AlertDialogTrigger'\n\ninterface AlertDialogTriggerProps extends DialogTriggerProps {}\n\nconst NativeAlertDialogTriggerFrame = styled(YStack, {\n name: 'DialogTrigger',\n})\n\nconst AlertDialogTrigger = React.forwardRef<TamaguiElement, AlertDialogTriggerProps>(\n (props: ScopedProps<AlertDialogTriggerProps>, forwardedRef) => {\n if (props['__native']) {\n const { __native, onPress, __onPress, ...rest } = props as any\n return (\n <NativeAlertDialogTriggerFrame\n {...rest}\n onPress={composeEventHandlers(onPress, __onPress)}\n />\n )\n }\n\n const { __scopeAlertDialog, ...triggerProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTrigger {...dialogScope} {...triggerProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'AlertDialogPortal'\n\ninterface AlertDialogPortalProps extends DialogPortalProps {}\n\nconst AlertDialogPortal: React.FC<AlertDialogPortalProps> = (\n props: ScopedProps<AlertDialogPortalProps>\n) => {\n const { __scopeAlertDialog, ...portalProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogPortal {...dialogScope} {...portalProps} />\n}\n\nAlertDialogPortal.displayName = PORTAL_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'AlertDialogOverlay'\n\ninterface AlertDialogOverlayProps extends DialogOverlayProps {}\n\nconst AlertDialogOverlay = React.forwardRef<TamaguiElement, AlertDialogOverlayProps>(\n (props: ScopedProps<AlertDialogOverlayProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...overlayProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogOverlay {...dialogScope} {...overlayProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogOverlay.displayName = OVERLAY_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'AlertDialogContent'\n\ntype AlertDialogContentContextValue = {\n cancelRef: React.MutableRefObject<TamaguiElement | null>\n}\n\nconst [AlertDialogContentProvider, useAlertDialogContentContext] =\n createAlertDialogContext<AlertDialogContentContextValue>(CONTENT_NAME)\n\ninterface AlertDialogContentProps\n extends Omit<DialogContentProps, 'onPointerDownOutside' | 'onInteractOutside'> {}\n\nconst AlertDialogContent = React.forwardRef<TamaguiElement, AlertDialogContentProps>(\n (props: ScopedProps<AlertDialogContentProps>, forwardedRef) => {\n const { __scopeAlertDialog, children, ...contentProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const contentRef = React.useRef<TamaguiElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const cancelRef = React.useRef<TamaguiElement | null>(null)\n\n return (\n <DialogWarningProvider\n contentName={CONTENT_NAME}\n titleName={TITLE_NAME}\n docsSlug=\"alert-dialog\"\n >\n <AlertDialogContentProvider scope={__scopeAlertDialog} cancelRef={cancelRef}>\n <DialogContent\n // @ts-ignore\n role=\"alertdialog\"\n {...dialogScope}\n {...contentProps}\n ref={composedRefs}\n onOpenAutoFocus={composeEventHandlers(contentProps.onOpenAutoFocus, (event) => {\n event.preventDefault()\n if (isWeb) {\n // @ts-ignore\n cancelRef.current?.focus({ preventScroll: true })\n }\n })}\n onPointerDownOutside={(event) => event.preventDefault()}\n onInteractOutside={(event) => event.preventDefault()}\n >\n {/**\n * We have to use `Slottable` here as we cannot wrap the `AlertDialogContentProvider`\n * around everything, otherwise the `DescriptionWarning` would be rendered straight away.\n * This is because we want the accessibility checks to run only once the content is actually\n * open and that behaviour is already encapsulated in `DialogContent`.\n */}\n <Slottable>{children}</Slottable>\n {process.env.NODE_ENV === 'development' && (\n <DescriptionWarning contentRef={contentRef} />\n )}\n </DialogContent>\n </AlertDialogContentProvider>\n </DialogWarningProvider>\n )\n }\n)\n\nAlertDialogContent.displayName = CONTENT_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'AlertDialogTitle'\n\ntype AlertDialogTitleProps = DialogTitleProps\n\nconst AlertDialogTitle = React.forwardRef<TamaguiElement, AlertDialogTitleProps>(\n (props: ScopedProps<AlertDialogTitleProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...titleProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTitle {...dialogScope} {...titleProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'AlertDialogDescription'\n\ntype AlertDialogDescriptionProps = DialogDescriptionProps\n\nconst AlertDialogDescription = React.forwardRef<TamaguiElement, AlertDialogDescriptionProps>(\n (props: ScopedProps<AlertDialogDescriptionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...descriptionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogDescription {...dialogScope} {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'AlertDialogAction'\n\ntype AlertDialogActionProps = DialogCloseProps\n\nconst AlertDialogAction = React.forwardRef<TamaguiElement, AlertDialogActionProps>(\n (props: ScopedProps<AlertDialogActionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...actionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogClose {...dialogScope} {...actionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogCancel\n * -----------------------------------------------------------------------------------------------*/\n\nconst CANCEL_NAME = 'AlertDialogCancel'\n\ninterface AlertDialogCancelProps extends DialogCloseProps {}\n\nconst AlertDialogCancel = React.forwardRef<TamaguiElement, AlertDialogCancelProps>(\n (props: ScopedProps<AlertDialogCancelProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...cancelProps } = props\n const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog)\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const ref = useComposedRefs(forwardedRef, cancelRef)\n return <DialogClose {...dialogScope} {...cancelProps} ref={ref} />\n }\n)\n\nAlertDialogCancel.displayName = CANCEL_NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype DescriptionWarningProps = {\n contentRef: React.RefObject<TamaguiElement>\n}\n\nconst DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef }) => {\n if (process.env.NODE_ENV === 'development') {\n React.useEffect(() => {\n if (!isWeb) return\n const hasDescription = document.getElementById(\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n contentRef.current?.getAttribute('aria-describedby')!\n )\n if (!hasDescription) {\n // eslint-disable-next-line no-console\n console.warn(`\\`${CONTENT_NAME}\\` requires a description for the component to be accessible for screen reader users.\n \n 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.\n \n 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.\n \n For more information, see https://tamagui.dev/docs/components/alert-dialog`)\n }\n }, [contentRef])\n }\n\n return null\n}\n\nconst AlertDialogInner: React.FC<AlertDialogProps> = (props: ScopedProps<AlertDialogProps>) => {\n const { __scopeAlertDialog, native, ...alertDialogProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n const [open, setOpen] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen || false,\n onChange: props.onOpenChange,\n })\n\n let triggerElement: any = null\n let title = ''\n let description = ''\n const buttons: {\n text: string\n onPress: (value?: string | undefined) => void\n style?: 'default' | 'cancel' | 'destructive'\n }[] = []\n\n forEachChildDeep(React.Children.toArray(props.children), (child) => {\n if (!React.isValidElement(child)) return false\n const name = isTamaguiElement(child)\n ? child.type.staticConfig.componentName\n : (child.type['displayName'] as string | undefined)\n switch (name) {\n case TRIGGER_NAME: {\n triggerElement = React.cloneElement(child as any, {\n __native: true,\n })\n return false\n }\n case TITLE_NAME: {\n title = getStringChildren(child)\n return false\n }\n case DESCRIPTION_NAME: {\n description = getStringChildren(child)\n return false\n }\n case ACTION_NAME:\n case CANCEL_NAME: {\n const style = name === ACTION_NAME ? 'default' : 'cancel'\n const text = getStringChildren(child)\n const onPress = () => {\n const childProps = child.props as any\n childProps?.onPress?.({ native: true })\n setOpen(false)\n }\n buttons.push({\n style,\n text,\n // @ts-ignore\n onPress,\n })\n return false\n }\n default: {\n return true\n }\n }\n })\n\n React.useLayoutEffect(() => {\n if (!open || !native) return\n if (title || description) {\n Alert.alert(title, description, buttons)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [native, open])\n\n if (native) {\n return React.cloneElement(triggerElement, {\n __onPress: () => {\n setOpen(true)\n },\n })\n }\n }\n\n return <Dialog {...dialogScope} {...alertDialogProps} modal />\n}\n\nfunction forEachChildDeep(\n children: React.ReactNode[],\n onChild: (el: React.ReactElement) => boolean\n) {\n for (const child of children) {\n if (!React.isValidElement(child)) continue\n if (!onChild(child)) continue\n if (child.props.children) {\n forEachChildDeep(React.Children.toArray(child.props.children), onChild)\n }\n }\n}\n\nfunction getStringChildren(child: React.ReactElement) {\n let string = ''\n forEachChildDeep(React.Children.toArray(child), (child) => {\n if (typeof child.props.children === 'string') {\n string = child.props.children\n return false\n }\n return true\n })\n return string\n}\n\nconst AlertDialog = withStaticProperties(AlertDialogInner, {\n Trigger: AlertDialogTrigger,\n Portal: AlertDialogPortal,\n Overlay: AlertDialogOverlay,\n Content: AlertDialogContent,\n Action: AlertDialogAction,\n Cancel: AlertDialogCancel,\n Title: AlertDialogTitle,\n Description: AlertDialogDescription,\n})\n\nAlertDialog.displayName = ROOT_NAME\n\nexport {\n createAlertDialogScope,\n //\n AlertDialog,\n AlertDialogTrigger,\n AlertDialogPortal,\n AlertDialogOverlay,\n AlertDialogContent,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogTitle,\n AlertDialogDescription,\n}\nexport type {\n AlertDialogProps,\n AlertDialogTriggerProps,\n AlertDialogPortalProps,\n AlertDialogOverlayProps,\n AlertDialogContentProps,\n AlertDialogActionProps,\n AlertDialogCancelProps,\n AlertDialogTitleProps,\n AlertDialogDescriptionProps,\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAgC;AAChC,kBAQO;AACP,4BAA0C;AAC1C,oBAmBO;AACP,oBAAuB;AACvB,oCAAqC;AACrC,YAAuB;AACvB,0BAAsB;AAMtB,MAAM,YAAY;AAGlB,MAAM,CAAC,0BAA0B,0BAA0B,8CAAmB,WAAW;AAAA,EACvF;AACF,CAAC;AAED,MAAM,iBA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;AACf,kBAAQ,IAAI;AAAA,QACd;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,oCAAC;AAAA,IAAQ,GAAG;AAAA,IAAc,GAAG;AAAA,IAAkB,OAAK;AAAA,GAAC;AAC9D;AAEA,0BACE,UACA,SACA;AACA,aAAW,SAAS,UAAU;AAC5B,QAAI,CAAC,MAAM,eAAe,KAAK;AAAG;AAClC,QAAI,CAAC,QAAQ,KAAK;AAAG;AACrB,QAAI,MAAM,MAAM,UAAU;AACxB,uBAAiB,MAAM,SAAS,QAAQ,MAAM,MAAM,QAAQ,GAAG,OAAO;AAAA,IACxE;AAAA,EACF;AACF;AAEA,2BAA2B,OAA2B;AACpD,MAAI,SAAS;AACb,mBAAiB,MAAM,SAAS,QAAQ,KAAK,GAAG,CAAC,WAAU;AACzD,QAAI,OAAO,OAAM,MAAM,aAAa,UAAU;AAC5C,eAAS,OAAM,MAAM;AACrB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AACD,SAAO;AACT;AAEA,MAAM,cAAc,sCAAqB,kBAAkB;AAAA,EACzD,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,aAAa;AACf,CAAC;AAED,YAAY,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/AlertDialog.js
CHANGED
|
@@ -152,21 +152,23 @@ const AlertDialogCancel = React.forwardRef((props, forwardedRef) => {
|
|
|
152
152
|
});
|
|
153
153
|
AlertDialogCancel.displayName = CANCEL_NAME;
|
|
154
154
|
const DescriptionWarning = ({ contentRef }) => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
155
|
+
if (process.env.NODE_ENV === "development") {
|
|
156
|
+
React.useEffect(() => {
|
|
157
|
+
var _a;
|
|
158
|
+
if (!isWeb)
|
|
159
|
+
return;
|
|
160
|
+
const hasDescription = document.getElementById((_a = contentRef.current) == null ? void 0 : _a.getAttribute("aria-describedby"));
|
|
161
|
+
if (!hasDescription) {
|
|
162
|
+
console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
|
|
163
|
+
|
|
164
|
+
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.
|
|
165
|
+
|
|
166
|
+
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.
|
|
167
|
+
|
|
168
|
+
For more information, see https://tamagui.dev/docs/components/alert-dialog`);
|
|
169
|
+
}
|
|
170
|
+
}, [contentRef]);
|
|
171
|
+
}
|
|
170
172
|
return null;
|
|
171
173
|
};
|
|
172
174
|
const AlertDialogInner = (props) => {
|
|
@@ -206,9 +208,9 @@ const AlertDialogInner = (props) => {
|
|
|
206
208
|
const style = name === ACTION_NAME ? "default" : "cancel";
|
|
207
209
|
const text = getStringChildren(child);
|
|
208
210
|
const onPress = () => {
|
|
209
|
-
var _a
|
|
210
|
-
;
|
|
211
|
-
(
|
|
211
|
+
var _a;
|
|
212
|
+
const childProps = child.props;
|
|
213
|
+
(_a = childProps == null ? void 0 : childProps.onPress) == null ? void 0 : _a.call(childProps, { native: true });
|
|
212
214
|
setOpen(false);
|
|
213
215
|
};
|
|
214
216
|
buttons.push({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AlertDialog.tsx"],
|
|
4
|
-
"sourcesContent": ["// forked from radix-ui\n// https://github.com/radix-ui/primitives/blob/main/packages/react/alert-dialog/src/AlertDialog.tsx\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Slottable,\n TamaguiElement,\n composeEventHandlers,\n isTamaguiElement,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport {\n Dialog,\n DialogClose,\n DialogCloseProps,\n DialogContent,\n DialogContentProps,\n DialogDescription,\n DialogDescriptionProps,\n DialogOverlay,\n DialogOverlayProps,\n DialogPortal,\n DialogPortalProps,\n DialogProps,\n DialogTitle,\n DialogTitleProps,\n DialogTrigger,\n DialogTriggerProps,\n DialogWarningProvider,\n createDialogScope,\n} from '@tamagui/dialog'\nimport { YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { Alert } from 'react-native'\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst ROOT_NAME = 'AlertDialog'\n\ntype ScopedProps<P> = P & { __scopeAlertDialog?: Scope }\nconst [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [\n createDialogScope,\n])\n\nconst useDialogScope = createDialogScope()\n\ntype AlertDialogProps = DialogProps & {\n native?: boolean\n}\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'AlertDialogTrigger'\n\ninterface AlertDialogTriggerProps extends DialogTriggerProps {}\n\nconst NativeAlertDialogTriggerFrame = styled(YStack, {\n name: 'DialogTrigger',\n})\n\nconst AlertDialogTrigger = React.forwardRef<TamaguiElement, AlertDialogTriggerProps>(\n (props: ScopedProps<AlertDialogTriggerProps>, forwardedRef) => {\n if (props['__native']) {\n const { __native, onPress, __onPress, ...rest } = props as any\n return (\n <NativeAlertDialogTriggerFrame\n {...rest}\n onPress={composeEventHandlers(onPress, __onPress)}\n />\n )\n }\n\n const { __scopeAlertDialog, ...triggerProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTrigger {...dialogScope} {...triggerProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'AlertDialogPortal'\n\ninterface AlertDialogPortalProps extends DialogPortalProps {}\n\nconst AlertDialogPortal: React.FC<AlertDialogPortalProps> = (\n props: ScopedProps<AlertDialogPortalProps>\n) => {\n const { __scopeAlertDialog, ...portalProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogPortal {...dialogScope} {...portalProps} />\n}\n\nAlertDialogPortal.displayName = PORTAL_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'AlertDialogOverlay'\n\ninterface AlertDialogOverlayProps extends DialogOverlayProps {}\n\nconst AlertDialogOverlay = React.forwardRef<TamaguiElement, AlertDialogOverlayProps>(\n (props: ScopedProps<AlertDialogOverlayProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...overlayProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogOverlay {...dialogScope} {...overlayProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogOverlay.displayName = OVERLAY_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'AlertDialogContent'\n\ntype AlertDialogContentContextValue = {\n cancelRef: React.MutableRefObject<TamaguiElement | null>\n}\n\nconst [AlertDialogContentProvider, useAlertDialogContentContext] =\n createAlertDialogContext<AlertDialogContentContextValue>(CONTENT_NAME)\n\ninterface AlertDialogContentProps\n extends Omit<DialogContentProps, 'onPointerDownOutside' | 'onInteractOutside'> {}\n\nconst AlertDialogContent = React.forwardRef<TamaguiElement, AlertDialogContentProps>(\n (props: ScopedProps<AlertDialogContentProps>, forwardedRef) => {\n const { __scopeAlertDialog, children, ...contentProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const contentRef = React.useRef<TamaguiElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const cancelRef = React.useRef<TamaguiElement | null>(null)\n\n return (\n <DialogWarningProvider\n contentName={CONTENT_NAME}\n titleName={TITLE_NAME}\n docsSlug=\"alert-dialog\"\n >\n <AlertDialogContentProvider scope={__scopeAlertDialog} cancelRef={cancelRef}>\n <DialogContent\n // @ts-ignore\n role=\"alertdialog\"\n {...dialogScope}\n {...contentProps}\n ref={composedRefs}\n onOpenAutoFocus={composeEventHandlers(contentProps.onOpenAutoFocus, (event) => {\n event.preventDefault()\n if (isWeb) {\n // @ts-ignore\n cancelRef.current?.focus({ preventScroll: true })\n }\n })}\n onPointerDownOutside={(event) => event.preventDefault()}\n onInteractOutside={(event) => event.preventDefault()}\n >\n {/**\n * We have to use `Slottable` here as we cannot wrap the `AlertDialogContentProvider`\n * around everything, otherwise the `DescriptionWarning` would be rendered straight away.\n * This is because we want the accessibility checks to run only once the content is actually\n * open and that behaviour is already encapsulated in `DialogContent`.\n */}\n <Slottable>{children}</Slottable>\n {process.env.NODE_ENV === 'development' && (\n <DescriptionWarning contentRef={contentRef} />\n )}\n </DialogContent>\n </AlertDialogContentProvider>\n </DialogWarningProvider>\n )\n }\n)\n\nAlertDialogContent.displayName = CONTENT_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'AlertDialogTitle'\n\ntype AlertDialogTitleProps = DialogTitleProps\n\nconst AlertDialogTitle = React.forwardRef<TamaguiElement, AlertDialogTitleProps>(\n (props: ScopedProps<AlertDialogTitleProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...titleProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTitle {...dialogScope} {...titleProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'AlertDialogDescription'\n\ntype AlertDialogDescriptionProps = DialogDescriptionProps\n\nconst AlertDialogDescription = React.forwardRef<TamaguiElement, AlertDialogDescriptionProps>(\n (props: ScopedProps<AlertDialogDescriptionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...descriptionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogDescription {...dialogScope} {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'AlertDialogAction'\n\ntype AlertDialogActionProps = DialogCloseProps\n\nconst AlertDialogAction = React.forwardRef<TamaguiElement, AlertDialogActionProps>(\n (props: ScopedProps<AlertDialogActionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...actionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogClose {...dialogScope} {...actionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogCancel\n * -----------------------------------------------------------------------------------------------*/\n\nconst CANCEL_NAME = 'AlertDialogCancel'\n\ninterface AlertDialogCancelProps extends DialogCloseProps {}\n\nconst AlertDialogCancel = React.forwardRef<TamaguiElement, AlertDialogCancelProps>(\n (props: ScopedProps<AlertDialogCancelProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...cancelProps } = props\n const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog)\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const ref = useComposedRefs(forwardedRef, cancelRef)\n return <DialogClose {...dialogScope} {...cancelProps} ref={ref} />\n }\n)\n\nAlertDialogCancel.displayName = CANCEL_NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype DescriptionWarningProps = {\n contentRef: React.RefObject<TamaguiElement>\n}\n\nconst DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef }) => {\n const MESSAGE = `\\`${CONTENT_NAME}\\` requires a description for the component to be accessible for screen reader users.\n\nYou 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.\n\nAlternatively, 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.\n\nFor more information, see https://tamagui.dev/docs/components/alert-dialog`\n\n React.useEffect(() => {\n if (!isWeb) return\n const hasDescription = document.getElementById(\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n contentRef.current?.getAttribute('aria-describedby')!\n )\n if (!hasDescription) console.warn(MESSAGE)\n }, [MESSAGE, contentRef])\n\n return null\n}\n\nconst AlertDialogInner: React.FC<AlertDialogProps> = (props: ScopedProps<AlertDialogProps>) => {\n const { __scopeAlertDialog, native, ...alertDialogProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n const [open, setOpen] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen || false,\n onChange: props.onOpenChange,\n })\n\n let triggerElement: any = null\n let title = ''\n let description = ''\n const buttons: {\n text: string\n onPress: (value?: string | undefined) => void\n style?: 'default' | 'cancel' | 'destructive'\n }[] = []\n\n forEachChildDeep(React.Children.toArray(props.children), (child) => {\n if (!React.isValidElement(child)) return false\n const name = isTamaguiElement(child)\n ? child.type.staticConfig.componentName\n : (child.type['displayName'] as string | undefined)\n switch (name) {\n case TRIGGER_NAME: {\n triggerElement = React.cloneElement(child as any, {\n __native: true,\n })\n return false\n }\n case TITLE_NAME: {\n title = getStringChildren(child)\n return false\n }\n case DESCRIPTION_NAME: {\n description = getStringChildren(child)\n return false\n }\n case ACTION_NAME:\n case CANCEL_NAME: {\n const style = name === ACTION_NAME ? 'default' : 'cancel'\n const text = getStringChildren(child)\n const onPress = () => {\n ;(child.props as any)?.onPress?.({ native: true })\n setOpen(false)\n }\n buttons.push({\n style,\n text,\n // @ts-ignore\n onPress,\n })\n return false\n }\n default: {\n return true\n }\n }\n })\n\n React.useLayoutEffect(() => {\n if (!open || !native) return\n if (title || description) {\n Alert.alert(title, description, buttons)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [native, open])\n\n if (native) {\n return React.cloneElement(triggerElement, {\n __onPress: () => {\n setOpen(true)\n },\n })\n }\n }\n\n return <Dialog {...dialogScope} {...alertDialogProps} modal />\n}\n\nfunction forEachChildDeep(\n children: React.ReactNode[],\n onChild: (el: React.ReactElement) => boolean\n) {\n for (const child of children) {\n if (!React.isValidElement(child)) continue\n if (!onChild(child)) continue\n if (child.props.children) {\n forEachChildDeep(React.Children.toArray(child.props.children), onChild)\n }\n }\n}\n\nfunction getStringChildren(child: React.ReactElement) {\n let string = ''\n forEachChildDeep(React.Children.toArray(child), (child) => {\n if (typeof child.props.children === 'string') {\n string = child.props.children\n return false\n }\n return true\n })\n return string\n}\n\nconst AlertDialog = withStaticProperties(AlertDialogInner, {\n Trigger: AlertDialogTrigger,\n Portal: AlertDialogPortal,\n Overlay: AlertDialogOverlay,\n Content: AlertDialogContent,\n Action: AlertDialogAction,\n Cancel: AlertDialogCancel,\n Title: AlertDialogTitle,\n Description: AlertDialogDescription,\n})\n\nAlertDialog.displayName = ROOT_NAME\n\nexport {\n createAlertDialogScope,\n //\n AlertDialog,\n AlertDialogTrigger,\n AlertDialogPortal,\n AlertDialogOverlay,\n AlertDialogContent,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogTitle,\n AlertDialogDescription,\n}\nexport type {\n AlertDialogProps,\n AlertDialogTriggerProps,\n AlertDialogPortalProps,\n AlertDialogOverlayProps,\n AlertDialogContentProps,\n AlertDialogActionProps,\n AlertDialogCancelProps,\n AlertDialogTitleProps,\n AlertDialogDescriptionProps,\n}\n"],
|
|
5
|
-
"mappings": "AAGA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA;AACA;AACA;AACA;AAMA,MAAM,YAAY;AAGlB,MAAM,CAAC,0BAA0B,0BAA0B,mBAAmB,WAAW;AAAA,EACvF;AACF,CAAC;AAED,MAAM,iBAAiB,kBAAkB;AAUzC,MAAM,eAAe;AAIrB,MAAM,gCAAgC,OAAO,QAAQ;AAAA,EACnD,MAAM;AACR,CAAC;AAED,MAAM,qBAAqB,MAAM,WAC/B,CAAC,OAA6C,iBAAiB;AAC7D,MAAI,MAAM,aAAa;AACrB,UAAM,EAAE,UAAU,SAAS,cAAc,SAAS;AAClD,WACE,oCAAC;AAAA,MACE,GAAG;AAAA,MACJ,SAAS,qBAAqB,SAAS,SAAS;AAAA,KAClD;AAAA,EAEJ;AAEA,QAAM,EAAE,uBAAuB,iBAAiB;AAChD,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAe,GAAG;AAAA,IAAc,GAAG;AAAA,IAAc,KAAK;AAAA,GAAc;AAC9E,CACF;AAEA,mBAAmB,cAAc;AAMjC,MAAM,cAAc;AAIpB,MAAM,oBAAsD,CAC1D,UACG;AACH,QAAM,EAAE,uBAAuB,gBAAgB;AAC/C,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAc,GAAG;AAAA,IAAc,GAAG;AAAA,GAAa;AACzD;AAEA,kBAAkB,cAAc;AAMhC,MAAM,eAAe;AAIrB,MAAM,qBAAqB,MAAM,WAC/B,CAAC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,EAAE,uBAAuB,eAAe;AAC9C,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAa,GAAG;AAAA,IAAc,GAAG;AAAA,IAAY,KAAK;AAAA,GAAc;AAC1E,CACF;AAEA,iBAAiB,cAAc;AAM/B,MAAM,mBAAmB;AAIzB,MAAM,yBAAyB,MAAM,WACnC,CAAC,OAAiD,iBAAiB;AACjE,QAAM,EAAE,uBAAuB,qBAAqB;AACpD,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAmB,GAAG;AAAA,IAAc,GAAG;AAAA,IAAkB,KAAK;AAAA,GAAc;AACtF,CACF;AAEA,uBAAuB,cAAc;AAMrC,MAAM,cAAc;AAIpB,MAAM,oBAAoB,MAAM,WAC9B,CAAC,OAA4C,iBAAiB;AAC5D,QAAM,EAAE,uBAAuB,gBAAgB;AAC/C,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAa,GAAG;AAAA,IAAc,GAAG;AAAA,IAAa,KAAK;AAAA,GAAc;AAC3E,CACF;AAEA,kBAAkB,cAAc;AAMhC,MAAM,cAAc;AAIpB,MAAM,oBAAoB,MAAM,WAC9B,CAAC,OAA4C,iBAAiB;AAC5D,QAAM,EAAE,uBAAuB,gBAAgB;AAC/C,QAAM,EAAE,cAAc,6BAA6B,aAAa,kBAAkB;AAClF,QAAM,cAAc,eAAe,kBAAkB;AACrD,QAAM,MAAM,gBAAgB,cAAc,SAAS;AACnD,SAAO,oCAAC;AAAA,IAAa,GAAG;AAAA,IAAc,GAAG;AAAA,IAAa;AAAA,GAAU;AAClE,CACF;AAEA,kBAAkB,cAAc;AAQhC,MAAM,qBAAwD,CAAC,EAAE,iBAAiB;AAChF,
|
|
4
|
+
"sourcesContent": ["// forked from radix-ui\n// https://github.com/radix-ui/primitives/blob/main/packages/react/alert-dialog/src/AlertDialog.tsx\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Slottable,\n TamaguiElement,\n composeEventHandlers,\n isTamaguiElement,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport {\n Dialog,\n DialogClose,\n DialogCloseProps,\n DialogContent,\n DialogContentProps,\n DialogDescription,\n DialogDescriptionProps,\n DialogOverlay,\n DialogOverlayProps,\n DialogPortal,\n DialogPortalProps,\n DialogProps,\n DialogTitle,\n DialogTitleProps,\n DialogTrigger,\n DialogTriggerProps,\n DialogWarningProvider,\n createDialogScope,\n} from '@tamagui/dialog'\nimport { YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { Alert } from 'react-native'\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst ROOT_NAME = 'AlertDialog'\n\ntype ScopedProps<P> = P & { __scopeAlertDialog?: Scope }\nconst [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [\n createDialogScope,\n])\n\nconst useDialogScope = createDialogScope()\n\ntype AlertDialogProps = DialogProps & {\n native?: boolean\n}\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'AlertDialogTrigger'\n\ninterface AlertDialogTriggerProps extends DialogTriggerProps {}\n\nconst NativeAlertDialogTriggerFrame = styled(YStack, {\n name: 'DialogTrigger',\n})\n\nconst AlertDialogTrigger = React.forwardRef<TamaguiElement, AlertDialogTriggerProps>(\n (props: ScopedProps<AlertDialogTriggerProps>, forwardedRef) => {\n if (props['__native']) {\n const { __native, onPress, __onPress, ...rest } = props as any\n return (\n <NativeAlertDialogTriggerFrame\n {...rest}\n onPress={composeEventHandlers(onPress, __onPress)}\n />\n )\n }\n\n const { __scopeAlertDialog, ...triggerProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTrigger {...dialogScope} {...triggerProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'AlertDialogPortal'\n\ninterface AlertDialogPortalProps extends DialogPortalProps {}\n\nconst AlertDialogPortal: React.FC<AlertDialogPortalProps> = (\n props: ScopedProps<AlertDialogPortalProps>\n) => {\n const { __scopeAlertDialog, ...portalProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogPortal {...dialogScope} {...portalProps} />\n}\n\nAlertDialogPortal.displayName = PORTAL_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'AlertDialogOverlay'\n\ninterface AlertDialogOverlayProps extends DialogOverlayProps {}\n\nconst AlertDialogOverlay = React.forwardRef<TamaguiElement, AlertDialogOverlayProps>(\n (props: ScopedProps<AlertDialogOverlayProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...overlayProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogOverlay {...dialogScope} {...overlayProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogOverlay.displayName = OVERLAY_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'AlertDialogContent'\n\ntype AlertDialogContentContextValue = {\n cancelRef: React.MutableRefObject<TamaguiElement | null>\n}\n\nconst [AlertDialogContentProvider, useAlertDialogContentContext] =\n createAlertDialogContext<AlertDialogContentContextValue>(CONTENT_NAME)\n\ninterface AlertDialogContentProps\n extends Omit<DialogContentProps, 'onPointerDownOutside' | 'onInteractOutside'> {}\n\nconst AlertDialogContent = React.forwardRef<TamaguiElement, AlertDialogContentProps>(\n (props: ScopedProps<AlertDialogContentProps>, forwardedRef) => {\n const { __scopeAlertDialog, children, ...contentProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const contentRef = React.useRef<TamaguiElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const cancelRef = React.useRef<TamaguiElement | null>(null)\n\n return (\n <DialogWarningProvider\n contentName={CONTENT_NAME}\n titleName={TITLE_NAME}\n docsSlug=\"alert-dialog\"\n >\n <AlertDialogContentProvider scope={__scopeAlertDialog} cancelRef={cancelRef}>\n <DialogContent\n // @ts-ignore\n role=\"alertdialog\"\n {...dialogScope}\n {...contentProps}\n ref={composedRefs}\n onOpenAutoFocus={composeEventHandlers(contentProps.onOpenAutoFocus, (event) => {\n event.preventDefault()\n if (isWeb) {\n // @ts-ignore\n cancelRef.current?.focus({ preventScroll: true })\n }\n })}\n onPointerDownOutside={(event) => event.preventDefault()}\n onInteractOutside={(event) => event.preventDefault()}\n >\n {/**\n * We have to use `Slottable` here as we cannot wrap the `AlertDialogContentProvider`\n * around everything, otherwise the `DescriptionWarning` would be rendered straight away.\n * This is because we want the accessibility checks to run only once the content is actually\n * open and that behaviour is already encapsulated in `DialogContent`.\n */}\n <Slottable>{children}</Slottable>\n {process.env.NODE_ENV === 'development' && (\n <DescriptionWarning contentRef={contentRef} />\n )}\n </DialogContent>\n </AlertDialogContentProvider>\n </DialogWarningProvider>\n )\n }\n)\n\nAlertDialogContent.displayName = CONTENT_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'AlertDialogTitle'\n\ntype AlertDialogTitleProps = DialogTitleProps\n\nconst AlertDialogTitle = React.forwardRef<TamaguiElement, AlertDialogTitleProps>(\n (props: ScopedProps<AlertDialogTitleProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...titleProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTitle {...dialogScope} {...titleProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'AlertDialogDescription'\n\ntype AlertDialogDescriptionProps = DialogDescriptionProps\n\nconst AlertDialogDescription = React.forwardRef<TamaguiElement, AlertDialogDescriptionProps>(\n (props: ScopedProps<AlertDialogDescriptionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...descriptionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogDescription {...dialogScope} {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'AlertDialogAction'\n\ntype AlertDialogActionProps = DialogCloseProps\n\nconst AlertDialogAction = React.forwardRef<TamaguiElement, AlertDialogActionProps>(\n (props: ScopedProps<AlertDialogActionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...actionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogClose {...dialogScope} {...actionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogCancel\n * -----------------------------------------------------------------------------------------------*/\n\nconst CANCEL_NAME = 'AlertDialogCancel'\n\ninterface AlertDialogCancelProps extends DialogCloseProps {}\n\nconst AlertDialogCancel = React.forwardRef<TamaguiElement, AlertDialogCancelProps>(\n (props: ScopedProps<AlertDialogCancelProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...cancelProps } = props\n const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog)\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const ref = useComposedRefs(forwardedRef, cancelRef)\n return <DialogClose {...dialogScope} {...cancelProps} ref={ref} />\n }\n)\n\nAlertDialogCancel.displayName = CANCEL_NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype DescriptionWarningProps = {\n contentRef: React.RefObject<TamaguiElement>\n}\n\nconst DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef }) => {\n if (process.env.NODE_ENV === 'development') {\n React.useEffect(() => {\n if (!isWeb) return\n const hasDescription = document.getElementById(\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n contentRef.current?.getAttribute('aria-describedby')!\n )\n if (!hasDescription) {\n // eslint-disable-next-line no-console\n console.warn(`\\`${CONTENT_NAME}\\` requires a description for the component to be accessible for screen reader users.\n \n 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.\n \n 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.\n \n For more information, see https://tamagui.dev/docs/components/alert-dialog`)\n }\n }, [contentRef])\n }\n\n return null\n}\n\nconst AlertDialogInner: React.FC<AlertDialogProps> = (props: ScopedProps<AlertDialogProps>) => {\n const { __scopeAlertDialog, native, ...alertDialogProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n const [open, setOpen] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen || false,\n onChange: props.onOpenChange,\n })\n\n let triggerElement: any = null\n let title = ''\n let description = ''\n const buttons: {\n text: string\n onPress: (value?: string | undefined) => void\n style?: 'default' | 'cancel' | 'destructive'\n }[] = []\n\n forEachChildDeep(React.Children.toArray(props.children), (child) => {\n if (!React.isValidElement(child)) return false\n const name = isTamaguiElement(child)\n ? child.type.staticConfig.componentName\n : (child.type['displayName'] as string | undefined)\n switch (name) {\n case TRIGGER_NAME: {\n triggerElement = React.cloneElement(child as any, {\n __native: true,\n })\n return false\n }\n case TITLE_NAME: {\n title = getStringChildren(child)\n return false\n }\n case DESCRIPTION_NAME: {\n description = getStringChildren(child)\n return false\n }\n case ACTION_NAME:\n case CANCEL_NAME: {\n const style = name === ACTION_NAME ? 'default' : 'cancel'\n const text = getStringChildren(child)\n const onPress = () => {\n const childProps = child.props as any\n childProps?.onPress?.({ native: true })\n setOpen(false)\n }\n buttons.push({\n style,\n text,\n // @ts-ignore\n onPress,\n })\n return false\n }\n default: {\n return true\n }\n }\n })\n\n React.useLayoutEffect(() => {\n if (!open || !native) return\n if (title || description) {\n Alert.alert(title, description, buttons)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [native, open])\n\n if (native) {\n return React.cloneElement(triggerElement, {\n __onPress: () => {\n setOpen(true)\n },\n })\n }\n }\n\n return <Dialog {...dialogScope} {...alertDialogProps} modal />\n}\n\nfunction forEachChildDeep(\n children: React.ReactNode[],\n onChild: (el: React.ReactElement) => boolean\n) {\n for (const child of children) {\n if (!React.isValidElement(child)) continue\n if (!onChild(child)) continue\n if (child.props.children) {\n forEachChildDeep(React.Children.toArray(child.props.children), onChild)\n }\n }\n}\n\nfunction getStringChildren(child: React.ReactElement) {\n let string = ''\n forEachChildDeep(React.Children.toArray(child), (child) => {\n if (typeof child.props.children === 'string') {\n string = child.props.children\n return false\n }\n return true\n })\n return string\n}\n\nconst AlertDialog = withStaticProperties(AlertDialogInner, {\n Trigger: AlertDialogTrigger,\n Portal: AlertDialogPortal,\n Overlay: AlertDialogOverlay,\n Content: AlertDialogContent,\n Action: AlertDialogAction,\n Cancel: AlertDialogCancel,\n Title: AlertDialogTitle,\n Description: AlertDialogDescription,\n})\n\nAlertDialog.displayName = ROOT_NAME\n\nexport {\n createAlertDialogScope,\n //\n AlertDialog,\n AlertDialogTrigger,\n AlertDialogPortal,\n AlertDialogOverlay,\n AlertDialogContent,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogTitle,\n AlertDialogDescription,\n}\nexport type {\n AlertDialogProps,\n AlertDialogTriggerProps,\n AlertDialogPortalProps,\n AlertDialogOverlayProps,\n AlertDialogContentProps,\n AlertDialogActionProps,\n AlertDialogCancelProps,\n AlertDialogTitleProps,\n AlertDialogDescriptionProps,\n}\n"],
|
|
5
|
+
"mappings": "AAGA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA;AACA;AACA;AACA;AAMA,MAAM,YAAY;AAGlB,MAAM,CAAC,0BAA0B,0BAA0B,mBAAmB,WAAW;AAAA,EACvF;AACF,CAAC;AAED,MAAM,iBAAiB,kBAAkB;AAUzC,MAAM,eAAe;AAIrB,MAAM,gCAAgC,OAAO,QAAQ;AAAA,EACnD,MAAM;AACR,CAAC;AAED,MAAM,qBAAqB,MAAM,WAC/B,CAAC,OAA6C,iBAAiB;AAC7D,MAAI,MAAM,aAAa;AACrB,UAAM,EAAE,UAAU,SAAS,cAAc,SAAS;AAClD,WACE,oCAAC;AAAA,MACE,GAAG;AAAA,MACJ,SAAS,qBAAqB,SAAS,SAAS;AAAA,KAClD;AAAA,EAEJ;AAEA,QAAM,EAAE,uBAAuB,iBAAiB;AAChD,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAe,GAAG;AAAA,IAAc,GAAG;AAAA,IAAc,KAAK;AAAA,GAAc;AAC9E,CACF;AAEA,mBAAmB,cAAc;AAMjC,MAAM,cAAc;AAIpB,MAAM,oBAAsD,CAC1D,UACG;AACH,QAAM,EAAE,uBAAuB,gBAAgB;AAC/C,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,oCAAC;AAAA,IAAc,GAAG;AAAA,IAAc,GAAG;AAAA,GAAa;AACzD;AAEA,kBAAkB,cAAc;AAMhC,MAAM,eAAe;AAIrB,MAAM,qBAAqB,MAAM,WAC/B,CAAC,OAA6C,iBAAiB;AAC7D,QAAM,EAAE,uBAAuB,iBAAiB;AAChD,QAAM,cAAc,eAA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6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/AlertDialog.js
CHANGED
|
@@ -108,21 +108,23 @@ const AlertDialogCancel = React.forwardRef((props, forwardedRef) => {
|
|
|
108
108
|
});
|
|
109
109
|
AlertDialogCancel.displayName = CANCEL_NAME;
|
|
110
110
|
const DescriptionWarning = ({ contentRef }) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
if (process.env.NODE_ENV === "development") {
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
var _a;
|
|
114
|
+
if (!isWeb)
|
|
115
|
+
return;
|
|
116
|
+
const hasDescription = document.getElementById((_a = contentRef.current) == null ? void 0 : _a.getAttribute("aria-describedby"));
|
|
117
|
+
if (!hasDescription) {
|
|
118
|
+
console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
|
|
119
|
+
|
|
120
|
+
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.
|
|
121
|
+
|
|
122
|
+
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.
|
|
123
|
+
|
|
124
|
+
For more information, see https://tamagui.dev/docs/components/alert-dialog`);
|
|
125
|
+
}
|
|
126
|
+
}, [contentRef]);
|
|
127
|
+
}
|
|
126
128
|
return null;
|
|
127
129
|
};
|
|
128
130
|
const AlertDialogInner = (props) => {
|
|
@@ -162,9 +164,9 @@ const AlertDialogInner = (props) => {
|
|
|
162
164
|
const style = name === ACTION_NAME ? "default" : "cancel";
|
|
163
165
|
const text = getStringChildren(child);
|
|
164
166
|
const onPress = () => {
|
|
165
|
-
var _a
|
|
166
|
-
;
|
|
167
|
-
(
|
|
167
|
+
var _a;
|
|
168
|
+
const childProps = child.props;
|
|
169
|
+
(_a = childProps == null ? void 0 : childProps.onPress) == null ? void 0 : _a.call(childProps, { native: true });
|
|
168
170
|
setOpen(false);
|
|
169
171
|
};
|
|
170
172
|
buttons.push({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AlertDialog.tsx"],
|
|
4
|
-
"sourcesContent": ["// forked from radix-ui\n// https://github.com/radix-ui/primitives/blob/main/packages/react/alert-dialog/src/AlertDialog.tsx\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Slottable,\n TamaguiElement,\n composeEventHandlers,\n isTamaguiElement,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport {\n Dialog,\n DialogClose,\n DialogCloseProps,\n DialogContent,\n DialogContentProps,\n DialogDescription,\n DialogDescriptionProps,\n DialogOverlay,\n DialogOverlayProps,\n DialogPortal,\n DialogPortalProps,\n DialogProps,\n DialogTitle,\n DialogTitleProps,\n DialogTrigger,\n DialogTriggerProps,\n DialogWarningProvider,\n createDialogScope,\n} from '@tamagui/dialog'\nimport { YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { Alert } from 'react-native'\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst ROOT_NAME = 'AlertDialog'\n\ntype ScopedProps<P> = P & { __scopeAlertDialog?: Scope }\nconst [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [\n createDialogScope,\n])\n\nconst useDialogScope = createDialogScope()\n\ntype AlertDialogProps = DialogProps & {\n native?: boolean\n}\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'AlertDialogTrigger'\n\ninterface AlertDialogTriggerProps extends DialogTriggerProps {}\n\nconst NativeAlertDialogTriggerFrame = styled(YStack, {\n name: 'DialogTrigger',\n})\n\nconst AlertDialogTrigger = React.forwardRef<TamaguiElement, AlertDialogTriggerProps>(\n (props: ScopedProps<AlertDialogTriggerProps>, forwardedRef) => {\n if (props['__native']) {\n const { __native, onPress, __onPress, ...rest } = props as any\n return (\n <NativeAlertDialogTriggerFrame\n {...rest}\n onPress={composeEventHandlers(onPress, __onPress)}\n />\n )\n }\n\n const { __scopeAlertDialog, ...triggerProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTrigger {...dialogScope} {...triggerProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'AlertDialogPortal'\n\ninterface AlertDialogPortalProps extends DialogPortalProps {}\n\nconst AlertDialogPortal: React.FC<AlertDialogPortalProps> = (\n props: ScopedProps<AlertDialogPortalProps>\n) => {\n const { __scopeAlertDialog, ...portalProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogPortal {...dialogScope} {...portalProps} />\n}\n\nAlertDialogPortal.displayName = PORTAL_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'AlertDialogOverlay'\n\ninterface AlertDialogOverlayProps extends DialogOverlayProps {}\n\nconst AlertDialogOverlay = React.forwardRef<TamaguiElement, AlertDialogOverlayProps>(\n (props: ScopedProps<AlertDialogOverlayProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...overlayProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogOverlay {...dialogScope} {...overlayProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogOverlay.displayName = OVERLAY_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'AlertDialogContent'\n\ntype AlertDialogContentContextValue = {\n cancelRef: React.MutableRefObject<TamaguiElement | null>\n}\n\nconst [AlertDialogContentProvider, useAlertDialogContentContext] =\n createAlertDialogContext<AlertDialogContentContextValue>(CONTENT_NAME)\n\ninterface AlertDialogContentProps\n extends Omit<DialogContentProps, 'onPointerDownOutside' | 'onInteractOutside'> {}\n\nconst AlertDialogContent = React.forwardRef<TamaguiElement, AlertDialogContentProps>(\n (props: ScopedProps<AlertDialogContentProps>, forwardedRef) => {\n const { __scopeAlertDialog, children, ...contentProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const contentRef = React.useRef<TamaguiElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const cancelRef = React.useRef<TamaguiElement | null>(null)\n\n return (\n <DialogWarningProvider\n contentName={CONTENT_NAME}\n titleName={TITLE_NAME}\n docsSlug=\"alert-dialog\"\n >\n <AlertDialogContentProvider scope={__scopeAlertDialog} cancelRef={cancelRef}>\n <DialogContent\n // @ts-ignore\n role=\"alertdialog\"\n {...dialogScope}\n {...contentProps}\n ref={composedRefs}\n onOpenAutoFocus={composeEventHandlers(contentProps.onOpenAutoFocus, (event) => {\n event.preventDefault()\n if (isWeb) {\n // @ts-ignore\n cancelRef.current?.focus({ preventScroll: true })\n }\n })}\n onPointerDownOutside={(event) => event.preventDefault()}\n onInteractOutside={(event) => event.preventDefault()}\n >\n {/**\n * We have to use `Slottable` here as we cannot wrap the `AlertDialogContentProvider`\n * around everything, otherwise the `DescriptionWarning` would be rendered straight away.\n * This is because we want the accessibility checks to run only once the content is actually\n * open and that behaviour is already encapsulated in `DialogContent`.\n */}\n <Slottable>{children}</Slottable>\n {process.env.NODE_ENV === 'development' && (\n <DescriptionWarning contentRef={contentRef} />\n )}\n </DialogContent>\n </AlertDialogContentProvider>\n </DialogWarningProvider>\n )\n }\n)\n\nAlertDialogContent.displayName = CONTENT_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'AlertDialogTitle'\n\ntype AlertDialogTitleProps = DialogTitleProps\n\nconst AlertDialogTitle = React.forwardRef<TamaguiElement, AlertDialogTitleProps>(\n (props: ScopedProps<AlertDialogTitleProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...titleProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTitle {...dialogScope} {...titleProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'AlertDialogDescription'\n\ntype AlertDialogDescriptionProps = DialogDescriptionProps\n\nconst AlertDialogDescription = React.forwardRef<TamaguiElement, AlertDialogDescriptionProps>(\n (props: ScopedProps<AlertDialogDescriptionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...descriptionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogDescription {...dialogScope} {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'AlertDialogAction'\n\ntype AlertDialogActionProps = DialogCloseProps\n\nconst AlertDialogAction = React.forwardRef<TamaguiElement, AlertDialogActionProps>(\n (props: ScopedProps<AlertDialogActionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...actionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogClose {...dialogScope} {...actionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogCancel\n * -----------------------------------------------------------------------------------------------*/\n\nconst CANCEL_NAME = 'AlertDialogCancel'\n\ninterface AlertDialogCancelProps extends DialogCloseProps {}\n\nconst AlertDialogCancel = React.forwardRef<TamaguiElement, AlertDialogCancelProps>(\n (props: ScopedProps<AlertDialogCancelProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...cancelProps } = props\n const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog)\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const ref = useComposedRefs(forwardedRef, cancelRef)\n return <DialogClose {...dialogScope} {...cancelProps} ref={ref} />\n }\n)\n\nAlertDialogCancel.displayName = CANCEL_NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype DescriptionWarningProps = {\n contentRef: React.RefObject<TamaguiElement>\n}\n\nconst DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef }) => {\n const MESSAGE = `\\`${CONTENT_NAME}\\` requires a description for the component to be accessible for screen reader users.\n\nYou 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.\n\nAlternatively, 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.\n\nFor more information, see https://tamagui.dev/docs/components/alert-dialog`\n\n React.useEffect(() => {\n if (!isWeb) return\n const hasDescription = document.getElementById(\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n contentRef.current?.getAttribute('aria-describedby')!\n )\n if (!hasDescription) console.warn(MESSAGE)\n }, [MESSAGE, contentRef])\n\n return null\n}\n\nconst AlertDialogInner: React.FC<AlertDialogProps> = (props: ScopedProps<AlertDialogProps>) => {\n const { __scopeAlertDialog, native, ...alertDialogProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n const [open, setOpen] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen || false,\n onChange: props.onOpenChange,\n })\n\n let triggerElement: any = null\n let title = ''\n let description = ''\n const buttons: {\n text: string\n onPress: (value?: string | undefined) => void\n style?: 'default' | 'cancel' | 'destructive'\n }[] = []\n\n forEachChildDeep(React.Children.toArray(props.children), (child) => {\n if (!React.isValidElement(child)) return false\n const name = isTamaguiElement(child)\n ? child.type.staticConfig.componentName\n : (child.type['displayName'] as string | undefined)\n switch (name) {\n case TRIGGER_NAME: {\n triggerElement = React.cloneElement(child as any, {\n __native: true,\n })\n return false\n }\n case TITLE_NAME: {\n title = getStringChildren(child)\n return false\n }\n case DESCRIPTION_NAME: {\n description = getStringChildren(child)\n return false\n }\n case ACTION_NAME:\n case CANCEL_NAME: {\n const style = name === ACTION_NAME ? 'default' : 'cancel'\n const text = getStringChildren(child)\n const onPress = () => {\n ;(child.props as any)?.onPress?.({ native: true })\n setOpen(false)\n }\n buttons.push({\n style,\n text,\n // @ts-ignore\n onPress,\n })\n return false\n }\n default: {\n return true\n }\n }\n })\n\n React.useLayoutEffect(() => {\n if (!open || !native) return\n if (title || description) {\n Alert.alert(title, description, buttons)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [native, open])\n\n if (native) {\n return React.cloneElement(triggerElement, {\n __onPress: () => {\n setOpen(true)\n },\n })\n }\n }\n\n return <Dialog {...dialogScope} {...alertDialogProps} modal />\n}\n\nfunction forEachChildDeep(\n children: React.ReactNode[],\n onChild: (el: React.ReactElement) => boolean\n) {\n for (const child of children) {\n if (!React.isValidElement(child)) continue\n if (!onChild(child)) continue\n if (child.props.children) {\n forEachChildDeep(React.Children.toArray(child.props.children), onChild)\n }\n }\n}\n\nfunction getStringChildren(child: React.ReactElement) {\n let string = ''\n forEachChildDeep(React.Children.toArray(child), (child) => {\n if (typeof child.props.children === 'string') {\n string = child.props.children\n return false\n }\n return true\n })\n return string\n}\n\nconst AlertDialog = withStaticProperties(AlertDialogInner, {\n Trigger: AlertDialogTrigger,\n Portal: AlertDialogPortal,\n Overlay: AlertDialogOverlay,\n Content: AlertDialogContent,\n Action: AlertDialogAction,\n Cancel: AlertDialogCancel,\n Title: AlertDialogTitle,\n Description: AlertDialogDescription,\n})\n\nAlertDialog.displayName = ROOT_NAME\n\nexport {\n createAlertDialogScope,\n //\n AlertDialog,\n AlertDialogTrigger,\n AlertDialogPortal,\n AlertDialogOverlay,\n AlertDialogContent,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogTitle,\n AlertDialogDescription,\n}\nexport type {\n AlertDialogProps,\n AlertDialogTriggerProps,\n AlertDialogPortalProps,\n AlertDialogOverlayProps,\n AlertDialogContentProps,\n AlertDialogActionProps,\n AlertDialogCancelProps,\n AlertDialogTitleProps,\n AlertDialogDescriptionProps,\n}\n"],
|
|
5
|
-
"mappings": "AAGA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA;AACA;AACA;AACA;AAMA,MAAM,YAAY;AAGlB,MAAM,CAAC,0BAA0B,0BAA0B,mBAAmB,WAAW;AAAA,EACvF;AACF,CAAC;AAED,MAAM,iBAAiB,kBAAkB;AAUzC,MAAM,eAAe;AAIrB,MAAM,gCAAgC,OAAO,QAAQ;AAAA,EACnD,MAAM;AACR,CAAC;AAED,MAAM,qBAAqB,MAAM,WAC/B,CAAC,OAA6C,iBAAiB;AAC7D,MAAI,MAAM,aAAa;AACrB,UAAM,EAAE,UAAU,SAAS,cAAc,SAAS;AAClD,WACE,CAAC,kCACK,MACJ,SAAS,qBAAqB,SAAS,SAAS,GAClD;AAAA,EAEJ;AAEA,QAAM,EAAE,uBAAuB,iBAAiB;AAChD,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,CAAC,kBAAkB,iBAAiB,c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ives/blob/main/packages/react/alert-dialog/src/AlertDialog.tsx\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Slottable,\n TamaguiElement,\n composeEventHandlers,\n isTamaguiElement,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport {\n Dialog,\n DialogClose,\n DialogCloseProps,\n DialogContent,\n DialogContentProps,\n DialogDescription,\n DialogDescriptionProps,\n DialogOverlay,\n DialogOverlayProps,\n DialogPortal,\n DialogPortalProps,\n DialogProps,\n DialogTitle,\n DialogTitleProps,\n DialogTrigger,\n DialogTriggerProps,\n DialogWarningProvider,\n createDialogScope,\n} from '@tamagui/dialog'\nimport { YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { Alert } from 'react-native'\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialog\n * -----------------------------------------------------------------------------------------------*/\n\nconst ROOT_NAME = 'AlertDialog'\n\ntype ScopedProps<P> = P & { __scopeAlertDialog?: Scope }\nconst [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [\n createDialogScope,\n])\n\nconst useDialogScope = createDialogScope()\n\ntype AlertDialogProps = DialogProps & {\n native?: boolean\n}\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'AlertDialogTrigger'\n\ninterface AlertDialogTriggerProps extends DialogTriggerProps {}\n\nconst NativeAlertDialogTriggerFrame = styled(YStack, {\n name: 'DialogTrigger',\n})\n\nconst AlertDialogTrigger = React.forwardRef<TamaguiElement, AlertDialogTriggerProps>(\n (props: ScopedProps<AlertDialogTriggerProps>, forwardedRef) => {\n if (props['__native']) {\n const { __native, onPress, __onPress, ...rest } = props as any\n return (\n <NativeAlertDialogTriggerFrame\n {...rest}\n onPress={composeEventHandlers(onPress, __onPress)}\n />\n )\n }\n\n const { __scopeAlertDialog, ...triggerProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTrigger {...dialogScope} {...triggerProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogPortal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'AlertDialogPortal'\n\ninterface AlertDialogPortalProps extends DialogPortalProps {}\n\nconst AlertDialogPortal: React.FC<AlertDialogPortalProps> = (\n props: ScopedProps<AlertDialogPortalProps>\n) => {\n const { __scopeAlertDialog, ...portalProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogPortal {...dialogScope} {...portalProps} />\n}\n\nAlertDialogPortal.displayName = PORTAL_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogOverlay\n * -----------------------------------------------------------------------------------------------*/\n\nconst OVERLAY_NAME = 'AlertDialogOverlay'\n\ninterface AlertDialogOverlayProps extends DialogOverlayProps {}\n\nconst AlertDialogOverlay = React.forwardRef<TamaguiElement, AlertDialogOverlayProps>(\n (props: ScopedProps<AlertDialogOverlayProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...overlayProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogOverlay {...dialogScope} {...overlayProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogOverlay.displayName = OVERLAY_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'AlertDialogContent'\n\ntype AlertDialogContentContextValue = {\n cancelRef: React.MutableRefObject<TamaguiElement | null>\n}\n\nconst [AlertDialogContentProvider, useAlertDialogContentContext] =\n createAlertDialogContext<AlertDialogContentContextValue>(CONTENT_NAME)\n\ninterface AlertDialogContentProps\n extends Omit<DialogContentProps, 'onPointerDownOutside' | 'onInteractOutside'> {}\n\nconst AlertDialogContent = React.forwardRef<TamaguiElement, AlertDialogContentProps>(\n (props: ScopedProps<AlertDialogContentProps>, forwardedRef) => {\n const { __scopeAlertDialog, children, ...contentProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const contentRef = React.useRef<TamaguiElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const cancelRef = React.useRef<TamaguiElement | null>(null)\n\n return (\n <DialogWarningProvider\n contentName={CONTENT_NAME}\n titleName={TITLE_NAME}\n docsSlug=\"alert-dialog\"\n >\n <AlertDialogContentProvider scope={__scopeAlertDialog} cancelRef={cancelRef}>\n <DialogContent\n // @ts-ignore\n role=\"alertdialog\"\n {...dialogScope}\n {...contentProps}\n ref={composedRefs}\n onOpenAutoFocus={composeEventHandlers(contentProps.onOpenAutoFocus, (event) => {\n event.preventDefault()\n if (isWeb) {\n // @ts-ignore\n cancelRef.current?.focus({ preventScroll: true })\n }\n })}\n onPointerDownOutside={(event) => event.preventDefault()}\n onInteractOutside={(event) => event.preventDefault()}\n >\n {/**\n * We have to use `Slottable` here as we cannot wrap the `AlertDialogContentProvider`\n * around everything, otherwise the `DescriptionWarning` would be rendered straight away.\n * This is because we want the accessibility checks to run only once the content is actually\n * open and that behaviour is already encapsulated in `DialogContent`.\n */}\n <Slottable>{children}</Slottable>\n {process.env.NODE_ENV === 'development' && (\n <DescriptionWarning contentRef={contentRef} />\n )}\n </DialogContent>\n </AlertDialogContentProvider>\n </DialogWarningProvider>\n )\n }\n)\n\nAlertDialogContent.displayName = CONTENT_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'AlertDialogTitle'\n\ntype AlertDialogTitleProps = DialogTitleProps\n\nconst AlertDialogTitle = React.forwardRef<TamaguiElement, AlertDialogTitleProps>(\n (props: ScopedProps<AlertDialogTitleProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...titleProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogTitle {...dialogScope} {...titleProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'AlertDialogDescription'\n\ntype AlertDialogDescriptionProps = DialogDescriptionProps\n\nconst AlertDialogDescription = React.forwardRef<TamaguiElement, AlertDialogDescriptionProps>(\n (props: ScopedProps<AlertDialogDescriptionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...descriptionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogDescription {...dialogScope} {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'AlertDialogAction'\n\ntype AlertDialogActionProps = DialogCloseProps\n\nconst AlertDialogAction = React.forwardRef<TamaguiElement, AlertDialogActionProps>(\n (props: ScopedProps<AlertDialogActionProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...actionProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n return <DialogClose {...dialogScope} {...actionProps} ref={forwardedRef} />\n }\n)\n\nAlertDialogAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AlertDialogCancel\n * -----------------------------------------------------------------------------------------------*/\n\nconst CANCEL_NAME = 'AlertDialogCancel'\n\ninterface AlertDialogCancelProps extends DialogCloseProps {}\n\nconst AlertDialogCancel = React.forwardRef<TamaguiElement, AlertDialogCancelProps>(\n (props: ScopedProps<AlertDialogCancelProps>, forwardedRef) => {\n const { __scopeAlertDialog, ...cancelProps } = props\n const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog)\n const dialogScope = useDialogScope(__scopeAlertDialog)\n const ref = useComposedRefs(forwardedRef, cancelRef)\n return <DialogClose {...dialogScope} {...cancelProps} ref={ref} />\n }\n)\n\nAlertDialogCancel.displayName = CANCEL_NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype DescriptionWarningProps = {\n contentRef: React.RefObject<TamaguiElement>\n}\n\nconst DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef }) => {\n if (process.env.NODE_ENV === 'development') {\n React.useEffect(() => {\n if (!isWeb) return\n const hasDescription = document.getElementById(\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n contentRef.current?.getAttribute('aria-describedby')!\n )\n if (!hasDescription) {\n // eslint-disable-next-line no-console\n console.warn(`\\`${CONTENT_NAME}\\` requires a description for the component to be accessible for screen reader users.\n \n 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.\n \n 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.\n \n For more information, see https://tamagui.dev/docs/components/alert-dialog`)\n }\n }, [contentRef])\n }\n\n return null\n}\n\nconst AlertDialogInner: React.FC<AlertDialogProps> = (props: ScopedProps<AlertDialogProps>) => {\n const { __scopeAlertDialog, native, ...alertDialogProps } = props\n const dialogScope = useDialogScope(__scopeAlertDialog)\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n const [open, setOpen] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen || false,\n onChange: props.onOpenChange,\n })\n\n let triggerElement: any = null\n let title = ''\n let description = ''\n const buttons: {\n text: string\n onPress: (value?: string | undefined) => void\n style?: 'default' | 'cancel' | 'destructive'\n }[] = []\n\n forEachChildDeep(React.Children.toArray(props.children), (child) => {\n if (!React.isValidElement(child)) return false\n const name = isTamaguiElement(child)\n ? child.type.staticConfig.componentName\n : (child.type['displayName'] as string | undefined)\n switch (name) {\n case TRIGGER_NAME: {\n triggerElement = React.cloneElement(child as any, {\n __native: true,\n })\n return false\n }\n case TITLE_NAME: {\n title = getStringChildren(child)\n return false\n }\n case DESCRIPTION_NAME: {\n description = getStringChildren(child)\n return false\n }\n case ACTION_NAME:\n case CANCEL_NAME: {\n const style = name === ACTION_NAME ? 'default' : 'cancel'\n const text = getStringChildren(child)\n const onPress = () => {\n const childProps = child.props as any\n childProps?.onPress?.({ native: true })\n setOpen(false)\n }\n buttons.push({\n style,\n text,\n // @ts-ignore\n onPress,\n })\n return false\n }\n default: {\n return true\n }\n }\n })\n\n React.useLayoutEffect(() => {\n if (!open || !native) return\n if (title || description) {\n Alert.alert(title, description, buttons)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [native, open])\n\n if (native) {\n return React.cloneElement(triggerElement, {\n __onPress: () => {\n setOpen(true)\n },\n })\n }\n }\n\n return <Dialog {...dialogScope} {...alertDialogProps} modal />\n}\n\nfunction forEachChildDeep(\n children: React.ReactNode[],\n onChild: (el: React.ReactElement) => boolean\n) {\n for (const child of children) {\n if (!React.isValidElement(child)) continue\n if (!onChild(child)) continue\n if (child.props.children) {\n forEachChildDeep(React.Children.toArray(child.props.children), onChild)\n }\n }\n}\n\nfunction getStringChildren(child: React.ReactElement) {\n let string = ''\n forEachChildDeep(React.Children.toArray(child), (child) => {\n if (typeof child.props.children === 'string') {\n string = child.props.children\n return false\n }\n return true\n })\n return string\n}\n\nconst AlertDialog = withStaticProperties(AlertDialogInner, {\n Trigger: AlertDialogTrigger,\n Portal: AlertDialogPortal,\n Overlay: AlertDialogOverlay,\n Content: AlertDialogContent,\n Action: AlertDialogAction,\n Cancel: AlertDialogCancel,\n Title: AlertDialogTitle,\n Description: AlertDialogDescription,\n})\n\nAlertDialog.displayName = ROOT_NAME\n\nexport {\n createAlertDialogScope,\n //\n AlertDialog,\n AlertDialogTrigger,\n AlertDialogPortal,\n AlertDialogOverlay,\n AlertDialogContent,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogTitle,\n AlertDialogDescription,\n}\nexport type {\n AlertDialogProps,\n AlertDialogTriggerProps,\n AlertDialogPortalProps,\n AlertDialogOverlayProps,\n AlertDialogContentProps,\n AlertDialogActionProps,\n AlertDialogCancelProps,\n AlertDialogTitleProps,\n AlertDialogDescriptionProps,\n}\n"],
|
|
5
|
+
"mappings": "AAGA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA;AACA;AACA;AACA;AAMA,MAAM,YAAY;AAGlB,MAAM,CAAC,0BAA0B,0BAA0B,mBAAmB,WAAW;AAAA,EACvF;AACF,CAAC;AAED,MAAM,iBAAiB,kBAAkB;AAUzC,MAAM,eAAe;AAIrB,MAAM,gCAAgC,OAAO,QAAQ;AAAA,EACnD,MAAM;AACR,CAAC;AAED,MAAM,qBAAqB,MAAM,WAC/B,CAAC,OAA6C,iBAAiB;AAC7D,MAAI,MAAM,aAAa;AACrB,UAAM,EAAE,UAAU,SAAS,cAAc,SAAS;AAClD,WACE,CAAC,kCACK,MACJ,SAAS,qBAAqB,SAAS,SAAS,GAClD;AAAA,EAEJ;AAEA,QAAM,EAAE,uBAAuB,iBAAiB;AAChD,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,CAAC,kBAAkB,iBAAiB,cAAc,KAAK,cAAc;AAC9E,CACF;AAEA,mBAAmB,cAAc;AAMjC,MAAM,cAAc;AAIpB,MAAM,oBAAsD,CAC1D,UACG;AACH,QAAM,EAAE,uBAAuB,gBAAgB;AAC/C,QAAM,cAAc,eAAe,kBAAkB;AACrD,SAAO,CAAC,iBAAiB,iBAAiB,aAAa;AACzD;AAEA,kBAAkB,cAAc;AAMhC,MAAM,eAAe;AAIrB,MAAM,qBAAqB,MAAM,WAC/B,CAAC,OAA6C,iBAAiB;AAC7D,QAAM,EAAE,uBAAuB,iBAAiB;AAChD,QAAM,cAAc,e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Aa;AACxB,cAAM,MAAM,OAAO,aAAa,OAAO;AAAA,MACzC;AAAA,IAEF,GAAG,CAAC,QAAQ,IAAI,CAAC;AAEjB,QAAI,QAAQ;AACV,aAAO,MAAM,aAAa,gBAAgB;AAAA,QACxC,WAAW,MAAM;AACf,kBAAQ,IAAI;AAAA,QACd;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,CAAC,WAAW,iBAAiB,kBAAkB,MAAM;AAC9D;AAEA,0BACE,UACA,SACA;AACA,aAAW,SAAS,UAAU;AAC5B,QAAI,CAAC,MAAM,eAAe,KAAK;AAAG;AAClC,QAAI,CAAC,QAAQ,KAAK;AAAG;AACrB,QAAI,MAAM,MAAM,UAAU;AACxB,uBAAiB,MAAM,SAAS,QAAQ,MAAM,MAAM,QAAQ,GAAG,OAAO;AAAA,IACxE;AAAA,EACF;AACF;AAEA,2BAA2B,OAA2B;AACpD,MAAI,SAAS;AACb,mBAAiB,MAAM,SAAS,QAAQ,KAAK,GAAG,CAAC,WAAU;AACzD,QAAI,OAAO,OAAM,MAAM,aAAa,UAAU;AAC5C,eAAS,OAAM,MAAM;AACrB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AACD,SAAO;AACT;AAEA,MAAM,cAAc,qBAAqB,kBAAkB;AAAA,EACzD,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,aAAa;AACf,CAAC;AAED,YAAY,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/alert-dialog",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.139",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -21,21 +21,21 @@
|
|
|
21
21
|
"clean:build": "tamagui-build clean:build"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tamagui/animate-presence": "^1.0.1-beta.
|
|
25
|
-
"@tamagui/aria-hidden": "^1.0.1-beta.
|
|
26
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
28
|
-
"@tamagui/create-context": "^1.0.1-beta.
|
|
29
|
-
"@tamagui/dialog": "^1.0.1-beta.
|
|
30
|
-
"@tamagui/dismissable": "^1.0.1-beta.
|
|
31
|
-
"@tamagui/focus-scope": "^1.0.1-beta.
|
|
32
|
-
"@tamagui/polyfill-dev": "^1.0.1-beta.
|
|
33
|
-
"@tamagui/popper": "^1.0.1-beta.
|
|
34
|
-
"@tamagui/portal": "^1.0.1-beta.
|
|
35
|
-
"@tamagui/remove-scroll": "^1.0.1-beta.
|
|
36
|
-
"@tamagui/stacks": "^1.0.1-beta.
|
|
37
|
-
"@tamagui/text": "^1.0.1-beta.
|
|
38
|
-
"@tamagui/use-controllable-state": "^1.0.1-beta.
|
|
24
|
+
"@tamagui/animate-presence": "^1.0.1-beta.139",
|
|
25
|
+
"@tamagui/aria-hidden": "^1.0.1-beta.139",
|
|
26
|
+
"@tamagui/compose-refs": "^1.0.1-beta.139",
|
|
27
|
+
"@tamagui/core": "^1.0.1-beta.139",
|
|
28
|
+
"@tamagui/create-context": "^1.0.1-beta.139",
|
|
29
|
+
"@tamagui/dialog": "^1.0.1-beta.139",
|
|
30
|
+
"@tamagui/dismissable": "^1.0.1-beta.139",
|
|
31
|
+
"@tamagui/focus-scope": "^1.0.1-beta.139",
|
|
32
|
+
"@tamagui/polyfill-dev": "^1.0.1-beta.139",
|
|
33
|
+
"@tamagui/popper": "^1.0.1-beta.139",
|
|
34
|
+
"@tamagui/portal": "^1.0.1-beta.139",
|
|
35
|
+
"@tamagui/remove-scroll": "^1.0.1-beta.139",
|
|
36
|
+
"@tamagui/stacks": "^1.0.1-beta.139",
|
|
37
|
+
"@tamagui/text": "^1.0.1-beta.139",
|
|
38
|
+
"@tamagui/use-controllable-state": "^1.0.1-beta.139"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "*",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"react-native": "*"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
46
|
+
"@tamagui/build": "^1.0.1-beta.139",
|
|
47
47
|
"@types/react-dom": "^18.0.3",
|
|
48
48
|
"@types/react-native": "^0.69.2",
|
|
49
49
|
"react": "*",
|
package/src/AlertDialog.tsx
CHANGED
|
@@ -269,23 +269,26 @@ type DescriptionWarningProps = {
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
const DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef }) => {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
272
|
+
if (process.env.NODE_ENV === 'development') {
|
|
273
|
+
React.useEffect(() => {
|
|
274
|
+
if (!isWeb) return
|
|
275
|
+
const hasDescription = document.getElementById(
|
|
276
|
+
// @ts-ignore
|
|
277
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
|
278
|
+
contentRef.current?.getAttribute('aria-describedby')!
|
|
279
|
+
)
|
|
280
|
+
if (!hasDescription) {
|
|
281
|
+
// eslint-disable-next-line no-console
|
|
282
|
+
console.warn(`\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users.
|
|
283
|
+
|
|
284
|
+
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.
|
|
285
|
+
|
|
286
|
+
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.
|
|
287
|
+
|
|
288
|
+
For more information, see https://tamagui.dev/docs/components/alert-dialog`)
|
|
289
|
+
}
|
|
290
|
+
}, [contentRef])
|
|
291
|
+
}
|
|
289
292
|
|
|
290
293
|
return null
|
|
291
294
|
}
|
|
@@ -335,7 +338,8 @@ const AlertDialogInner: React.FC<AlertDialogProps> = (props: ScopedProps<AlertDi
|
|
|
335
338
|
const style = name === ACTION_NAME ? 'default' : 'cancel'
|
|
336
339
|
const text = getStringChildren(child)
|
|
337
340
|
const onPress = () => {
|
|
338
|
-
|
|
341
|
+
const childProps = child.props as any
|
|
342
|
+
childProps?.onPress?.({ native: true })
|
|
339
343
|
setOpen(false)
|
|
340
344
|
}
|
|
341
345
|
buttons.push({
|