// // Copyright 2023 DXOS.org // import { type AlertDialogProps as AlertDialogRootPrimitiveProps, Root as AlertDialogRootPrimitive, AlertDialogTrigger as AlertDialogTriggerPrimitive, type AlertDialogTriggerProps as AlertDialogTriggerPrimitiveProps, AlertDialogPortal as AlertDialogPortalPrimitive, type AlertDialogPortalProps as AlertDialogPortalPrimitiveProps, AlertDialogOverlay as AlertDialogOverlayPrimitive, type AlertDialogOverlayProps as AlertDialogOverlayPrimitiveProps, AlertDialogTitle as AlertDialogTitlePrimitive, type AlertDialogTitleProps as AlertDialogTitlePrimitiveProps, AlertDialogDescription as AlertDialogDescriptionPrimitive, type AlertDialogDescriptionProps as AlertDialogDescriptionPrimitiveProps, AlertDialogAction as AlertDialogActionPrimitive, type AlertDialogActionProps as AlertDialogActionPrimitiveProps, AlertDialogCancel as AlertDialogCancelPrimitive, type AlertDialogCancelProps as AlertDialogCancelPrimitiveProps, AlertDialogContent as AlertDialogContentPrimitive, type AlertDialogContentProps as AlertDialogContentPrimitiveProps, } from '@radix-ui/react-alert-dialog'; import { createContext } from '@radix-ui/react-context'; import React, { forwardRef, type ForwardRefExoticComponent, type FunctionComponent } from 'react'; import { useThemeContext } from '../../hooks'; import { type ThemedClassName } from '../../util'; import { ElevationProvider } from '../ElevationProvider'; type AlertDialogRootProps = AlertDialogRootPrimitiveProps; const AlertDialogRoot: FunctionComponent = (props) => ( ); type AlertDialogTriggerProps = AlertDialogTriggerPrimitiveProps; const AlertDialogTrigger: FunctionComponent = AlertDialogTriggerPrimitive; type AlertDialogPortalProps = AlertDialogPortalPrimitiveProps; const AlertDialogPortal: FunctionComponent = AlertDialogPortalPrimitive; type AlertDialogCancelProps = AlertDialogCancelPrimitiveProps; const AlertDialogCancel: FunctionComponent = AlertDialogCancelPrimitive; type AlertDialogActionProps = AlertDialogActionPrimitiveProps; const AlertDialogAction: FunctionComponent = AlertDialogActionPrimitive; type AlertDialogTitleProps = ThemedClassName & { srOnly?: boolean }; const AlertDialogTitle: ForwardRefExoticComponent = forwardRef< HTMLHeadingElement, AlertDialogTitleProps >(({ classNames, srOnly, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }); type AlertDialogDescriptionProps = ThemedClassName & { srOnly?: boolean }; const AlertDialogDescription: ForwardRefExoticComponent = forwardRef< HTMLParagraphElement, AlertDialogDescriptionProps >(({ classNames, srOnly, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }); type OverlayLayoutContextValue = { inOverlayLayout?: boolean }; const ALERT_DIALOG_OVERLAY_NAME = 'AlertDialogOverlay'; const ALERT_DIALOG_CONTENT_NAME = 'AlertDialogContent'; const [OverlayLayoutProvider, useOverlayLayoutContext] = createContext( ALERT_DIALOG_OVERLAY_NAME, { inOverlayLayout: false, }, ); type AlertDialogOverlayProps = ThemedClassName & { 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; type AlertDialogContentProps = ThemedClassName; const AlertDialogContent: ForwardRefExoticComponent = forwardRef< HTMLDivElement, AlertDialogContentProps >(({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); const { inOverlayLayout } = useOverlayLayoutContext(ALERT_DIALOG_CONTENT_NAME); return ( {children} ); }); AlertDialogContent.displayName = ALERT_DIALOG_CONTENT_NAME; export const AlertDialog = { Root: AlertDialogRoot, Trigger: AlertDialogTrigger, Portal: AlertDialogPortal, Overlay: AlertDialogOverlay, Content: AlertDialogContent, Title: AlertDialogTitle, Description: AlertDialogDescription, Cancel: AlertDialogCancel, Action: AlertDialogAction, }; export type { AlertDialogRootProps, AlertDialogTriggerProps, AlertDialogPortalProps, AlertDialogOverlayProps, AlertDialogContentProps, AlertDialogTitleProps, AlertDialogDescriptionProps, AlertDialogCancelProps, AlertDialogActionProps, };