@omit/react-confirm-dialog
Version:
A simple confirm dialog for React
80 lines (75 loc) • 4.59 kB
TypeScript
import * as React from 'react';
import React__default, { ReactNode, ComponentPropsWithRef } from 'react';
import * as react_jsx_runtime from 'react/jsx-runtime';
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
import * as class_variance_authority_types from 'class-variance-authority/types';
import { VariantProps } from 'class-variance-authority';
declare const buttonVariants: (props?: ({
variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined;
size?: "default" | "sm" | "lg" | "icon" | null | undefined;
} & class_variance_authority_types.ClassProp) | undefined) => string;
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
asChild?: boolean;
}
declare const AlertDialogOverlay: React.ForwardRefExoticComponent<Omit<AlertDialogPrimitive.AlertDialogOverlayProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
declare const AlertDialogContent: React.ForwardRefExoticComponent<Omit<AlertDialogPrimitive.AlertDialogContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
declare const AlertDialogHeader: {
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): react_jsx_runtime.JSX.Element;
displayName: string;
};
declare const AlertDialogFooter: {
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): react_jsx_runtime.JSX.Element;
displayName: string;
};
declare const AlertDialogTitle: React.ForwardRefExoticComponent<Omit<AlertDialogPrimitive.AlertDialogTitleProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
declare const AlertDialogDescription: React.ForwardRefExoticComponent<Omit<AlertDialogPrimitive.AlertDialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>, "ref"> & React.RefAttributes<HTMLParagraphElement>>;
declare const AlertDialogAction: React.ForwardRefExoticComponent<Omit<AlertDialogPrimitive.AlertDialogActionProps & React.RefAttributes<HTMLButtonElement>, "ref"> & Partial<Pick<ButtonProps, "variant" | "size">> & React.RefAttributes<HTMLButtonElement>>;
declare const AlertDialogCancel: React.ForwardRefExoticComponent<Omit<AlertDialogPrimitive.AlertDialogCancelProps & React.RefAttributes<HTMLButtonElement>, "ref"> & Partial<Pick<ButtonProps, "variant" | "size">> & React.RefAttributes<HTMLButtonElement>>;
interface CustomActionsProps {
confirm: () => void;
cancel: () => void;
config: ConfirmOptions;
setConfig: ConfigUpdater;
}
type ConfigUpdater = (config: ConfirmOptions | ((prev: ConfirmOptions) => ConfirmOptions)) => void;
type LegacyCustomActions = (onConfirm: () => void, onCancel: () => void) => ReactNode;
type EnhancedCustomActions = (props: CustomActionsProps) => ReactNode;
interface ConfirmOptions {
title?: ReactNode;
description?: ReactNode;
contentSlot?: ReactNode;
confirmText?: string;
cancelText?: string;
icon?: ReactNode;
customActions?: LegacyCustomActions | EnhancedCustomActions;
confirmButton?: ComponentPropsWithRef<typeof AlertDialogAction>;
cancelButton?: ComponentPropsWithRef<typeof AlertDialogCancel> | null;
alertDialogOverlay?: ComponentPropsWithRef<typeof AlertDialogOverlay>;
alertDialogContent?: ComponentPropsWithRef<typeof AlertDialogContent>;
alertDialogHeader?: ComponentPropsWithRef<typeof AlertDialogHeader>;
alertDialogTitle?: ComponentPropsWithRef<typeof AlertDialogTitle>;
alertDialogDescription?: ComponentPropsWithRef<typeof AlertDialogDescription>;
alertDialogFooter?: ComponentPropsWithRef<typeof AlertDialogFooter>;
}
interface ConfirmDialogState {
isOpen: boolean;
config: ConfirmOptions;
resolver: ((value: boolean) => void) | null;
}
interface ConfirmContextValue {
confirm: ConfirmFunction;
updateConfig: ConfigUpdater;
}
interface ConfirmFunction {
(options: ConfirmOptions): Promise<boolean>;
updateConfig?: ConfigUpdater;
}
declare const ConfirmContext: React__default.Context<ConfirmContextValue | undefined>;
declare const ConfirmDialogProvider: React__default.FC<{
defaultOptions?: ConfirmOptions;
children: React__default.ReactNode;
}>;
declare const useConfirm: () => ConfirmFunction & {
updateConfig: ConfirmContextValue["updateConfig"];
};
export { ConfigUpdater, ConfirmContext, ConfirmContextValue, ConfirmDialogProvider, ConfirmDialogState, ConfirmFunction, ConfirmOptions, CustomActionsProps, EnhancedCustomActions, LegacyCustomActions, useConfirm };