Utilities
"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.
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>;| Option | Type | Default | Description |
|---|---|---|---|
title | ReactNode | "Are you sure?" | The dialog title. |
description | ReactNode | - | The dialog description. |
cancelText | ReactNode | "Cancel" | The cancel button label. |
actionText | ReactNode | "Continue" | The action button label. |
CancelProps | React.ComponentProps<typeof AlertDialogCancel> | - | Props spread to the cancel button. |
ActionProps | React.ComponentProps<typeof AlertDialogAction> | - | Props spread to the action button, e.g. { variant: "destructive" } for destructive confirmations. |