// // Copyright 2023 DXOS.org // import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog'; import { createContext } from '@radix-ui/react-context'; import React, { type ForwardRefExoticComponent, type FunctionComponent, forwardRef } from 'react'; import { useThemeContext } from '../../hooks'; import { ElevationProvider } from '../../primitives'; import { type DialogSize } from '../../theme'; import { type ThemedClassName } from '../../util'; import { Column } from '../Column'; import { Dialog, type DialogActionBarProps, type DialogActionIconButtonProps, type DialogBodyProps, type DialogHeaderProps, } from './Dialog'; // // Root // type AlertDialogRootProps = AlertDialogPrimitive.AlertDialogProps; const AlertDialogRoot: FunctionComponent = (props) => ( ); // // Trigger // type AlertDialogTriggerProps = AlertDialogPrimitive.AlertDialogTriggerProps; const AlertDialogTrigger = AlertDialogPrimitive.Trigger; // // Portal // type AlertDialogPortalProps = AlertDialogPrimitive.AlertDialogPortalProps; const AlertDialogPortal = AlertDialogPrimitive.Portal; // // Cancel // type AlertDialogCancelProps = AlertDialogPrimitive.AlertDialogCancelProps; const AlertDialogCancel = AlertDialogPrimitive.Cancel; // // Action // type AlertDialogActionProps = AlertDialogPrimitive.AlertDialogActionProps; const AlertDialogAction = AlertDialogPrimitive.Action; // // Context // type OverlayLayoutContextValue = { inOverlayLayout?: boolean }; const ALERT_DIALOG_OVERLAY_NAME = 'AlertDialog.Overlay'; const ALERT_DIALOG_CONTENT_NAME = 'AlertDialog.Content'; const [OverlayLayoutProvider, useOverlayLayoutContext] = createContext( ALERT_DIALOG_OVERLAY_NAME, { inOverlayLayout: false }, ); // // Overlay // type AlertDialogOverlayProps = ThemedClassName< AlertDialogPrimitive.AlertDialogOverlayProps & { blockAlign?: 'center' | 'start' | 'end' } >; const AlertDialogOverlay: ForwardRefExoticComponent = forwardRef< HTMLDivElement, AlertDialogOverlayProps >(({ classNames, children, blockAlign, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }); AlertDialogOverlay.displayName = ALERT_DIALOG_OVERLAY_NAME; // // Content // type AlertDialogContentProps = ThemedClassName & { size?: DialogSize }; const AlertDialogContent: ForwardRefExoticComponent = forwardRef< HTMLDivElement, AlertDialogContentProps >(({ classNames, children, size = 'md', ...props }, forwardedRef) => { const { tx } = useThemeContext(); const { inOverlayLayout } = useOverlayLayoutContext(ALERT_DIALOG_CONTENT_NAME); return ( {children} ); }); AlertDialogContent.displayName = ALERT_DIALOG_CONTENT_NAME; // // Title // type AlertDialogTitleProps = ThemedClassName & { srOnly?: boolean }; const AlertDialogTitle: ForwardRefExoticComponent = forwardRef< HTMLHeadingElement, AlertDialogTitleProps >(({ classNames, srOnly, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }); // // Description // type AlertDialogDescriptionProps = ThemedClassName & { srOnly?: boolean; }; const AlertDialogDescription: ForwardRefExoticComponent = forwardRef< HTMLParagraphElement, AlertDialogDescriptionProps >(({ classNames, srOnly, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }); // // AlertDialog // export const AlertDialog = { Root: AlertDialogRoot, Trigger: AlertDialogTrigger, Portal: AlertDialogPortal, Overlay: AlertDialogOverlay, Content: AlertDialogContent, // Shared with Dialog. Header: Dialog.Header, Body: Dialog.Body, Title: AlertDialogTitle, Description: AlertDialogDescription, ActionBar: Dialog.ActionBar, ActionIconButton: Dialog.ActionIconButton, // AlertDialog-specific dismissal. Cancel: AlertDialogCancel, Action: AlertDialogAction, }; export type { DialogActionBarProps as AlertDialogActionBarProps, DialogActionIconButtonProps as AlertDialogActionIconButtonProps, AlertDialogActionProps, DialogBodyProps as AlertDialogBodyProps, AlertDialogCancelProps, AlertDialogContentProps, AlertDialogDescriptionProps, // Re-export shared types. DialogHeaderProps as AlertDialogHeaderProps, AlertDialogOverlayProps, AlertDialogPortalProps, AlertDialogRootProps, AlertDialogTitleProps, AlertDialogTriggerProps, };