307

Confirmer

Imperative confirm dialog implementation.

"use client";

import { toast } from "sonner";

About

The <Confirmer /> component is built on top of react-call.

Installation

Run the following command:

pnpm dlx shadcn@latest add junwen-k/ui-x/confirmer

Add the <Confirmer /> component.

app/layout.tsx
import { Confirmer } from "@/components/ui/confirmer";
 
export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head />
      <body>
        <main>{children}</main>
        <Confirmer />
      </body>
    </html>
  );
}

Usage

import { confirm } from "@/components/ui/confirmer";
confirm({
  title: "Are you absolutely sure?",
  description:
    "This action cannot be undone. This will permanently delete your account and remove your data from our servers.",
}).then((confirmed) => {
  // ...
});

Examples

Default

"use client";

import { toast } from "sonner";

API Reference

Confirmer

The dialog host. Render it once near the root of your app; it renders nothing until confirm is called. Takes no props.

confirm

Opens the confirm dialog imperatively and resolves with the user's choice — true for the action button, false for cancel or dismissing the dialog.

function confirm(options?: ConfirmOptions): Promise<boolean>;
OptionTypeDefaultDescription
titleReactNode"Are you sure?"The dialog title.
descriptionReactNode-The dialog description.
cancelTextReactNode"Cancel"The cancel button label.
actionTextReactNode"Continue"The action button label.
CancelPropsReact.ComponentProps<typeof AlertDialogCancel>-Props spread to the cancel button.
ActionPropsReact.ComponentProps<typeof AlertDialogAction>-Props spread to the action button, e.g. { variant: "destructive" } for destructive confirmations.