Skip to content

PromptDialog ​

A dialog that asks one question: a name to type, or a warning to accept. Use it for every confirm and rename.

tsx
import { PromptDialog } from '@adecore/ui';
tsx
import { Button, PromptDialog } from '@adecore/ui';
import { GitBranch } from 'lucide-react';
import { useState } from 'react';

function wait(ms: number): Promise<void> {
    return new Promise((resolve) => window.setTimeout(resolve, ms));
}

export default function PromptDialogDemo() {
    const [open, setOpen] = useState(false);
    const [name, setName] = useState('main');

    return (
        <div className="flex items-center gap-3">
            <Button variant="secondary" onClick={() => setOpen(true)}>
                Rename {name}
            </Button>
            <PromptDialog
                open={open}
                onOpenChange={setOpen}
                title="Rename the branch"
                titleIcon={GitBranch}
                description="Pushes under the new name the next time you push."
                field={{ label: 'New name', initial: name, mono: true, maxLength: 60 }}
                confirmLabel="Rename"
                confirmBusyLabel="Renaming..."
                onConfirm={async (value) => {
                    await wait(800);

                    if (value === 'HEAD') {
                        throw new Error('HEAD is not a valid branch name.');
                    }

                    setName(value);
                    setOpen(false);
                }}
            />
        </div>
    );
}

Try HEAD as the name to see a failure. While a promise from onConfirm runs, the confirm button is disabled. A rejection shows its message and the dialog stays open; the message is the error's, or fallbackMessage for a non-Error (messageOf). The confirm button is also disabled while the field is empty, unless allowEmpty is set.

It never closes itself ​

onOpenChange(false) fires only on Cancel, Escape or a click outside. After a confirm, you close the dialog, so a follow-up question can reuse it.

The fields reset to field.initial and area.initial each time open turns true.

A confirm ​

Without field the dialog is a plain confirm. danger turns the confirm button red. ConfirmDialog wraps this for a destructive step over another dialog.

Props ​

PropTypeDefault
openbooleanRequired.
onOpenChange(open: boolean) => voidRequired.
titlestringRequired.
confirmLabelstringRequired.
onConfirm(value: string, body: string) => void | Promise<unknown>Required. Told the trimmed field and area.
titleIconLucideIcon
descriptionReactNode
field{ label?, ariaLabel?, initial?, placeholder?, mono?, maxLength? }A one-line field. Enter confirms.
area{ label, initial?, placeholder? }A taller field under it.
confirmBusyLabelstringWhat the button says while the step runs.
confirmIconLucideIcon
dangerbooleanfalse
busybooleanfalseFor a step the caller runs elsewhere.
allowEmptybooleanfalseLets the field be confirmed empty.
confirmDisabledbooleanfalseDisables the confirm for another reason than an empty field.
secondary{ label, onClick }A second way out next to the confirm.
nestedbooleanfalseOver another dialog.
childrenReactNodeAnything between the description and the buttons.
fallbackMessagestringThe failure line when a rejection is not an Error.
classNamestringOn the popup.
refRef<HTMLDivElement>

PromptDialogProps is an exported type.

Licenses and third-party notices are listed in each package.