import * as React from 'react';
import { createContextScope } from '@radix-ui/react-context';
import { useComposedRefs } from '@radix-ui/react-compose-refs';
import * as DialogPrimitive from '@radix-ui/react-dialog';
import { createDialogScope } from '@radix-ui/react-dialog';
import { composeEventHandlers } from '@radix-ui/primitive';
import type { Scope } from '@radix-ui/react-context';
/* -------------------------------------------------------------------------------------------------
* AlertDialog
* -----------------------------------------------------------------------------------------------*/
const ROOT_NAME = 'AlertDialog';
type ScopedProps
= P & { __scopeAlertDialog?: Scope | undefined };
const [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [
createDialogScope,
]);
const useDialogScope = createDialogScope();
type DialogProps = React.ComponentPropsWithoutRef;
interface AlertDialogProps extends Omit {}
const AlertDialog: React.FC = (props: ScopedProps) => {
const { __scopeAlertDialog, ...alertDialogProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
return ;
};
/* -------------------------------------------------------------------------------------------------
* AlertDialogTrigger
* -----------------------------------------------------------------------------------------------*/
type AlertDialogTriggerElement = React.ComponentRef;
type DialogTriggerProps = React.ComponentPropsWithoutRef;
interface AlertDialogTriggerProps extends DialogTriggerProps {}
const AlertDialogTrigger = React.forwardRef(
function AlertDialogTrigger(props: ScopedProps, forwardedRef) {
const { __scopeAlertDialog, ...triggerProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
return ;
},
);
/* -------------------------------------------------------------------------------------------------
* AlertDialogPortal
* -----------------------------------------------------------------------------------------------*/
type DialogPortalProps = React.ComponentPropsWithoutRef;
interface AlertDialogPortalProps extends DialogPortalProps {}
const AlertDialogPortal: React.FC = (
props: ScopedProps,
) => {
const { __scopeAlertDialog, ...portalProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
return ;
};
/* -------------------------------------------------------------------------------------------------
* AlertDialogOverlay
* -----------------------------------------------------------------------------------------------*/
type AlertDialogOverlayElement = React.ComponentRef;
type DialogOverlayProps = React.ComponentPropsWithoutRef;
interface AlertDialogOverlayProps extends DialogOverlayProps {}
const AlertDialogOverlay = React.forwardRef(
function AlertDialogOverlay(props: ScopedProps, forwardedRef) {
const { __scopeAlertDialog, ...overlayProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
return ;
},
);
/* -------------------------------------------------------------------------------------------------
* AlertDialogContent
* -----------------------------------------------------------------------------------------------*/
const CONTENT_NAME = 'AlertDialogContent';
type AlertDialogContentContextValue = {
cancelRef: React.MutableRefObject;
};
const [AlertDialogContentProvider, useAlertDialogContentContext] =
createAlertDialogContext(CONTENT_NAME);
type AlertDialogContentElement = React.ComponentRef;
type DialogContentProps = React.ComponentPropsWithoutRef;
interface AlertDialogContentProps extends Omit<
DialogContentProps,
'onPointerDownOutside' | 'onInteractOutside'
> {}
const AlertDialogContent = React.forwardRef(
function AlertDialogContent(props: ScopedProps, forwardedRef) {
const { __scopeAlertDialog, children, ...contentProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
const contentRef = React.useRef(null);
const composedRefs = useComposedRefs(forwardedRef, contentRef);
const cancelRef = React.useRef(null);
return (
{
event.preventDefault();
cancelRef.current?.focus({ preventScroll: true });
})}
onPointerDownOutside={(event) => event.preventDefault()}
onInteractOutside={(event) => event.preventDefault()}
>
{children}
);
},
);
/* -------------------------------------------------------------------------------------------------
* AlertDialogTitle
* -----------------------------------------------------------------------------------------------*/
type AlertDialogTitleElement = React.ComponentRef;
type DialogTitleProps = React.ComponentPropsWithoutRef;
interface AlertDialogTitleProps extends DialogTitleProps {}
const AlertDialogTitle = React.forwardRef(
function AlertDialogTitle(props: ScopedProps, forwardedRef) {
const { __scopeAlertDialog, ...titleProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
return ;
},
);
/* -------------------------------------------------------------------------------------------------
* AlertDialogDescription
* -----------------------------------------------------------------------------------------------*/
type AlertDialogDescriptionElement = React.ComponentRef;
type DialogDescriptionProps = React.ComponentPropsWithoutRef;
interface AlertDialogDescriptionProps extends DialogDescriptionProps {}
const AlertDialogDescription = React.forwardRef<
AlertDialogDescriptionElement,
AlertDialogDescriptionProps
>(function AlertDialogDescription(props: ScopedProps, forwardedRef) {
const { __scopeAlertDialog, ...descriptionProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
return ;
});
/* -------------------------------------------------------------------------------------------------
* AlertDialogAction
* -----------------------------------------------------------------------------------------------*/
type AlertDialogActionElement = React.ComponentRef;
type DialogCloseProps = React.ComponentPropsWithoutRef;
interface AlertDialogActionProps extends DialogCloseProps {}
const AlertDialogAction = React.forwardRef(
function AlertDialogAction(props: ScopedProps, forwardedRef) {
const { __scopeAlertDialog, ...actionProps } = props;
const dialogScope = useDialogScope(__scopeAlertDialog);
return ;
},
);
/* -------------------------------------------------------------------------------------------------
* AlertDialogCancel
* -----------------------------------------------------------------------------------------------*/
const CANCEL_NAME = 'AlertDialogCancel';
type AlertDialogCancelElement = React.ComponentRef;
interface AlertDialogCancelProps extends DialogCloseProps {}
const AlertDialogCancel = React.forwardRef(
function AlertDialogCancel(props: ScopedProps, forwardedRef) {
const { __scopeAlertDialog, ...cancelProps } = props;
const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog);
const dialogScope = useDialogScope(__scopeAlertDialog);
const ref = useComposedRefs(forwardedRef, cancelRef);
return ;
},
);
/* ---------------------------------------------------------------------------------------------- */
export {
createAlertDialogScope,
//
AlertDialog,
AlertDialogTrigger,
AlertDialogPortal,
AlertDialogOverlay,
AlertDialogContent,
AlertDialogAction,
AlertDialogCancel,
AlertDialogTitle,
AlertDialogDescription,
//
AlertDialog as Root,
AlertDialogTrigger as Trigger,
AlertDialogPortal as Portal,
AlertDialogOverlay as Overlay,
AlertDialogContent as Content,
AlertDialogAction as Action,
AlertDialogCancel as Cancel,
AlertDialogTitle as Title,
AlertDialogDescription as Description,
};
export type {
AlertDialogProps,
AlertDialogTriggerProps,
AlertDialogPortalProps,
AlertDialogOverlayProps,
AlertDialogContentProps,
AlertDialogActionProps,
AlertDialogCancelProps,
AlertDialogTitleProps,
AlertDialogDescriptionProps,
};