docs menu
ConfirmDialog
A modal that asks before something destructive, optionally making you type a phrase or your password.
import { ConfirmDialog } from "@meowerse/ui"; · source packages/ui/src/components/ConfirmDialog.tsx
try it
working: loading the demo…
demo source
import { useState } from "react";
import { Button, ConfirmDialog } from "@meowerse/ui";
// The phrase has capitals and an ampersand: it must be shown and matched exactly (U-31, B14).
export default function Demo() {
const [open, setOpen] = useState<"phrase" | "password" | null>(null);
const [done, setDone] = useState<string | null>(null);
return (
<div className="demo">
<div className="btn-row">
<Button variant="danger" onClick={() => setOpen("phrase")}>delete “Cats & Co”</Button>
<Button onClick={() => setOpen("password")}>sign out everywhere</Button>
</div>
{done && <p role="status" className="demo__out">{done}</p>}
<ConfirmDialog
open={open === "phrase"} onCancel={() => setOpen(null)}
onConfirm={() => { setOpen(null); setDone("deleted (not really: this is a demo)."); }}
title="delete this group?" description="Everyone loses the chat history. This can't be undone."
confirmLabel="delete group" confirmPhrase="Cats & Co"
/>
<ConfirmDialog
open={open === "password"} variant="primary" requirePassword onCancel={() => setOpen(null)}
onConfirm={() => { setOpen(null); setDone("signed out everywhere (not really: this is a demo)."); }}
title="sign out everywhere?" description="Every device signs out, this one included." confirmLabel="sign out"
/>
</div>
);
}
props
| prop | type | default | required |
|---|---|---|---|
open | boolean whether the dialog is open. | — | yes |
onCancel | () => void called when the dialog is cancelled (Escape, backdrop or the cancel button). | — | yes |
onConfirm | (r: ConfirmResult) => void called with the typed password (if requirePassword) once the confirm button is pressed and enabled. | — | yes |
title | string the dialog's title. | — | yes |
description | string explains what is about to happen. | — | yes |
confirmLabel | string the confirm button's label; name it after the action, e.g. "delete chat". | — | yes |
variant | "danger" | "primary" the confirm button's tone. | "danger" | no |
confirmPhrase | string a phrase the person must type exactly before the confirm button enables. | — | no |
requirePassword | boolean asks for the current password before the confirm button enables. | false | no |
loading | boolean disables the confirm button and shows it as busy while the action runs. | false | no |
css custom properties
| variable | dark | light |
|---|---|---|
--c-bg-elev | #111113 | #f1f0ec |
--c-danger | #ff6b63 | #b42318 |
--c-fg | #ededeb | #1a1a1c |
--c-fg-muted | #b3b3af | #46464a |
--c-fg-subtle | #8c8c88 | #5e5e5b |
--c-focus | #00ff82 | #0a6e3c |
--c-line | #232326 | #cfcec8 |
--c-line-input | #6a6a70 | #7a7973 |
--c-surface | #151517 | #dfded9 |
--control-height | 44px | same |
--d-fast | 120ms | same |
--disabled-opacity | 0.5 | same |
--ease | cubic-bezier(.16,1,.3,1) | same |
--font-mono | "JetBrains Mono", "JetBrains Mono Fallback", ui-monospace, "SFMono-Regular", Menlo, monospace | same |
--fs-2 | 0.8125rem | same |
--fs-3 | 0.875rem | same |
--fs-4 | 1rem | same |
--leading-normal | 1.5 | same |
--r-m | 4px | same |
--r-s | 2px | same |
--sp-1 | 4px | same |
--sp-2 | 8px | same |
--sp-3 | 12px | same |
--sp-4 | 16px | same |
Classes: .mw-confirm, .mw-field. Set any of these variables on an ancestor (or wrap a subtree in .mw-theme--dark / .mw-theme--light) to restyle just that part of a page.
accessibility
- Opens as a modal dialog with focus inside; Escape and "cancel" close it.
- With confirmPhrase, the phrase is shown exactly in <code>, and the field says "doesn't match yet" while it doesn't.
- The confirm button stays disabled until the phrase or password is there, and the reason is on screen.
| key | does |
|---|---|
| Tab / Shift+Tab | cycles inside the dialog |
| Escape | cancels |
do and don't
do
- Use it only for actions that are hard to undo.
- Name the confirm button after the action: "delete chat".
don't
- Don't lowercase or trim the phrase people must type.
- Don't ask for confirmation of harmless actions.