import { forwardRef } from 'react'; import { View } from 'react-native'; import { Slot, useDialog } from '@cdx-ui/primitives'; import { composeEventHandlers } from '@cdx-ui/utils'; import { Button, type ButtonProps } from '../Button'; import { Dialog, type DialogRootProps, type DialogPopupProps } from '../Dialog'; // ============================================================================= // ALERT DIALOG ROOT (Dialog with non-dismissible defaults + alertdialog role) // ============================================================================= export interface AlertDialogRootProps extends DialogRootProps {} const AlertDialogRoot = forwardRef( ( { closeOnBackdropPress = false, closeOnEscKey = false, role = 'alertdialog', children, ...props }, ref, ) => ( {children} ), ); AlertDialogRoot.displayName = 'AlertDialog'; // ============================================================================= // ALERT DIALOG POPUP (swipe disabled by default) // ============================================================================= export interface AlertDialogPopupProps extends DialogPopupProps {} const AlertDialogPopup = forwardRef( ({ isSwipeable = false, ...props }, ref) => ( ), ); AlertDialogPopup.displayName = 'AlertDialog.Popup'; // ============================================================================= // ALERT DIALOG ACTION // ============================================================================= export interface AlertDialogActionProps extends Omit { readonly asChild?: boolean; } const AlertDialogAction = forwardRef( ({ asChild = false, children, color = 'action', className, ...props }, ref) => { if (asChild) { return ( {children} ); } return ( ); }, ); AlertDialogAction.displayName = 'AlertDialog.Action'; // ============================================================================= // ALERT DIALOG CANCEL // ============================================================================= export interface AlertDialogCancelProps extends Omit { readonly asChild?: boolean; } const AlertDialogCancel = forwardRef( ({ asChild = false, children, onPress, className, ...props }, ref) => { const { onOpenChange } = useDialog(); const handlePress = composeEventHandlers(onPress, () => onOpenChange(false)); if (asChild) { return ( {children} ); } return ( ); }, ); AlertDialogCancel.displayName = 'AlertDialog.Cancel'; // ============================================================================= // COMPOUND EXPORT // ============================================================================= type AlertDialogCompoundComponent = typeof AlertDialogRoot & { Trigger: typeof Dialog.Trigger; Popup: typeof AlertDialogPopup; Header: typeof Dialog.Header; Title: typeof Dialog.Title; Description: typeof Dialog.Description; Content: typeof Dialog.Content; Text: typeof Dialog.Text; Footer: typeof Dialog.Footer; Close: typeof Dialog.Close; Action: typeof AlertDialogAction; Cancel: typeof AlertDialogCancel; }; export const AlertDialog = Object.assign(AlertDialogRoot, { Trigger: Dialog.Trigger, Popup: AlertDialogPopup, Header: Dialog.Header, Title: Dialog.Title, Description: Dialog.Description, Content: Dialog.Content, Text: Dialog.Text, Footer: Dialog.Footer, Close: Dialog.Close, Action: AlertDialogAction, Cancel: AlertDialogCancel, }) as AlertDialogCompoundComponent;