npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@razmisoft/react-confirm

v1.4.1

Published

A beautiful, flexible, and fully-featured confirmation dialog component for React applications. Built with TypeScript, Tailwind CSS, and Radix UI for maximum flexibility and accessibility.

Readme

@razmisoft/react-confirm

A beautiful, flexible, and fully-featured confirmation dialog component for React applications. Built with TypeScript, Tailwind CSS, and Radix UI for maximum flexibility and accessibility.

GitHub npm npm bundle size GitHub stars

React Confirm Dialog

Table of Contents

Installation

Using npm:

npm install @razmisoft/react-confirm

Using yarn:

yarn add @razmisoft/react-confirm

Using pnpm:

pnpm add @razmisoft/react-confirm

Usage

Import CSS for @razmisoft/react-confirm at the root of your application:

import "@razmisoft/react-confirm/styles.css";

Using Global Provider

Wrap your app with ConfirmProvider:

import { ConfirmProvider } from "@razmisoft/react-confirm";

function App() {
  return (
    <ConfirmProvider>
      <YourApp />
    </ConfirmProvider>
  );
}

Use the useConfirm hook anywhere in your app:

import { useConfirm } from "@razmisoft/react-confirm";

function DeleteButton() {
  const { confirm } = useConfirm();

  return (
    <button
      onClick={() =>
        confirm({
          title: "Delete Item",
          description: "Are you sure you want to delete this item?",
          onConfirm: () => {
            // Delete the item
          },
        })
      }
    >
      Delete
    </button>
  );
}

Using Dialog Component

You can create and manage your own dialog component:

import {
  Dialog,
  DialogContent,
  DialogHeader,
  DialogTitle,
  DialogDescription,
  DialogFooter,
  type ConfirmDialogProps,
} from "@razmisoft/react-confirm";

function CustomDialog({
  open,
  onOpenChange,
  onConfirm,
  onCancel,
  title = "Confirm Action",
  description,
  confirmText = "Confirm",
  cancelText = "Cancel",
  icon,
  variant = "default",
}: ConfirmDialogProps) {
  const [isLoading, setIsLoading] = useState(false);
  const [error, setError] = useState<string>();
  const [success, setSuccess] = useState<string>();

  // Reset state when dialog opens/closes
  useEffect(() => {
    if (!open) {
      setIsLoading(false);
      setError(undefined);
      setSuccess(undefined);
    }
  }, [open]);

  const handleConfirm = async () => {
    setIsLoading(true);
    setError(undefined);
    setSuccess(undefined);

    try {
      await onConfirm();
      setSuccess("Operation completed successfully");
      setTimeout(() => onOpenChange(false), 1500);
    } catch (err) {
      setError(err instanceof Error ? err.message : "An error occurred");
    } finally {
      setIsLoading(false);
    }
  };

  const getStatusIcon = () => {
    if (isLoading)
      return (
        <LoaderIcon className="animate-spin text-blue-600" aria-hidden="true" />
      );
    if (error) return <XIcon className="text-red-600" aria-hidden="true" />;
    if (success)
      return <CheckIcon className="text-green-600" aria-hidden="true" />;
    return (
      icon || (
        <AlertTriangleIcon className="text-yellow-600" aria-hidden="true" />
      )
    );
  };

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent>
        <DialogHeader>
          <div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-slate-100">
            {getStatusIcon()}
          </div>
          <DialogTitle className="text-center">{title}</DialogTitle>
          {description && !error && !success && (
            <DialogDescription className="text-center">
              {description}
            </DialogDescription>
          )}
          {error && (
            <DialogDescription className="text-center text-red-600">
              {error}
            </DialogDescription>
          )}
          {success && (
            <DialogDescription className="text-center text-green-600">
              {success}
            </DialogDescription>
          )}
        </DialogHeader>
        <DialogFooter className="sm:justify-center">
          <Button variant="outline" onClick={onCancel} disabled={isLoading}>
            {cancelText}
          </Button>
          <Button
            variant={variant}
            onClick={handleConfirm}
            loading={isLoading}
            loadingText="Loading..."
            disabled={isLoading}
          >
            {confirmText}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}

API Reference

ConfirmProvider

The ConfirmProvider component provides wraps your app with a context provider and adds a ConfirmDialog component to the root of the app. It accepts the following props:

interface ConfirmProviderProps {
  children: React.ReactNode;
}

useConfirm

The useConfirm hook provides is used to show a confirmation dialog. It returns an object with the following functions:

  • confirm: A function that shows a confirmation dialog. It accepts the following props:

    interface ConfirmOptions {
      title?: string;
      description?: string;
      confirmText?: string;
      cancelText?: string;
      onConfirm: () => Promise<void>;
      onCancel?: () => void;
    }
  • updateDialog: A function that updates the dialog content. It accepts the following props:

    interface UpdateDialogOptions {
      title?: string;
      description?: string;
      confirmText?: string;
      cancelText?: string;
    }
  • closeDialog: A function that closes the dialog.

confirm and updateDialog functions accept DialogOptions object with the following properties:

interface DialogOptions {
  title?: string;
  description?: string;
  confirmText?: string;
  cancelText?: string;
  icon?: React.ReactNode;
  variant?: "default" | "destructive";
  onConfirm?: () => Promise<void>;
}

Async Operations

The onConfirm function passed to the confirm function should return a promise. The dialog will show a loading spinner until the promise is resolved or rejected.

ConfirmDialog

A fully customizable dialog component that can be used to show confirmation dialogs. It accepts the following props:

interface ConfirmDialogProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  onConfirm: () => Promise<void>;
  onCancel: () => void;
  title?: string;
  description?: string;
  confirmText?: string;
  cancelText?: string;
  icon?: React.ReactNode;
  variant?: "default" | "destructive";
}

When you wrap your app with ConfirmProvider, a ConfirmDialog component is added to the root of the app. You don't need to use this component directly unless you want to create a custom dialog component.

useConfirmation

The useConfirmation hook is used to show a confirmation dialog. It returns an object with the following functions:

  • confirm: A function that shows a confirmation dialog. It accepts the following props:

      interface ConfirmOptions IUseConfirmation {
          isOpen: boolean;
          options: DialogOptions;
          confirm: (options?: ConfirmationOptions) => Promise<boolean>;
          updateDialog: (options: Partial<DialogOptions>) => void;
          handleConfirm: () => Promise<void>;
          handleCancel: () => void;
      }

    If you are using a custom dialog component and want to manage the dialog state yourself, you can use this hook since it extracts the dialog state management logic.

Best Practices

  1. Global vs Local Dialogs
  • Use useConfirm for app-wide confirmations
  • Use useConfirmation with custom UI for localized dialogs
  1. Error Handling
  • Always handle async operations in onConfirm
  • Use try/catch blocks for error states
  1. Accessibility
  • Provide descriptive titles and descriptions
  • Use appropriate ARIA labels
  • Ensure keyboard navigation works
  1. UI/UX Guidelines
  • Use appropriate variants for different actions
  • Keep descriptions clear and concise
  • Show loading states during async operations

License

MIT © sadamkhan7679

Author

sadamkhan7679 (https://github.com/sadamkhan7679)

Contributors

Want to contribute? Check out our Contributing Guide.