meowerse_
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

demo source
tsx
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 &amp; 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

proptypedefaultrequired
openboolean 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
titlestring the dialog's title.—yes
descriptionstring explains what is about to happen.—yes
confirmLabelstring 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
confirmPhrasestring a phrase the person must type exactly before the confirm button enables.—no
requirePasswordboolean asks for the current password before the confirm button enables.falseno
loadingboolean disables the confirm button and shows it as busy while the action runs.falseno

css custom properties

variabledarklight
--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-height44pxsame
--d-fast120mssame
--disabled-opacity0.5same
--easecubic-bezier(.16,1,.3,1)same
--font-mono"JetBrains Mono", "JetBrains Mono Fallback", ui-monospace, "SFMono-Regular", Menlo, monospacesame
--fs-20.8125remsame
--fs-30.875remsame
--fs-41remsame
--leading-normal1.5same
--r-m4pxsame
--r-s2pxsame
--sp-14pxsame
--sp-28pxsame
--sp-312pxsame
--sp-416pxsame

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.
keydoes
Tab / Shift+Tabcycles inside the dialog
Escapecancels

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.