nalarx-ui
Components

App dialog

In-app alert, confirm, type-to-confirm and prompt that resolve as promises.

bunx shadcn@latest add @nalarx/app-dialog

Usage

Mount the provider once near the root, then call the hook anywhere below it. confirm and prompt resolve to false and null on cancel, like the browser's own functions.

<AppDialogProvider renderDebug={(debug) => <ErrorDebugDetails debug={debug as ErrorDebugInfo} />}>
  {children}
</AppDialogProvider>

const dialog = useAppDialog();
if (await dialog.confirm({ title: "Leave without saving?", okLabel: "Leave" })) router.back();
const name = await dialog.prompt({ title: "Rename view", initial: view.name });

Every kind, plus an alert carrying debug details. Each preview has its own provider; the result of the last call shows under the buttons.

No dialog yet
No dialog yet

States

  • alert: one OK button, alertdialog role, focus on OK.
  • confirm: Cancel and an accent OK (Confirm by default). variant: "danger" makes OK destructive.
  • confirmTyped / confirmName: OK stays disabled until the name is typed exactly; the field turns red once it matches. Focus starts in the field.
  • prompt: a 40px field with initial selected on open; focus starts there.
  • Two at once: a second call settles the open one as cancelled, so no caller waits forever.

Keyboard

Key
Enter in the prompt or type-to-confirm fieldSubmits (only once the name matches).
Enter / Space on OK or CancelActivates it.
EscapeCancels and returns focus to where it was.
TabCycles inside the dialog.

API

MethodResolves to
alert({ title, message?, okLabel?, debug? })void
confirm({ title, message?, okLabel?, cancelLabel?, variant?, confirmName?, debug? })boolean
confirmTyped({ …confirm, confirmName })the typed string, or null
prompt({ title, message?, initial?, placeholder?, okLabel?, cancelLabel? })string, or null

AppDialogProvider takes renderDebug?: (debug: unknown) => ReactNode. Labels default to the ok, cancel, confirm, close and typeToConfirm* UI strings.

Replaces

AppDialog.tsx in both apps (web's base/Dialog.tsx and AppDialog.legacy.tsx, the Platform's own implementation) and the zustand dialogStore.

On this page