UI
ConfirmDialog
ConfirmDialog asks for confirmation before running an action and lets the user cancel instead.
Import
import { ConfirmDialog } from '@tallyui/components';Usage
import { Button, Text } from '@tallyui/components';
function DiscardDraft({ discard }: { discard: () => void }) {
return (
<ConfirmDialog title="Discard this draft?" confirmLabel="Discard" testID="discard-draft"
trigger={<Button><Text>Discard draft</Text></Button>} onConfirm={discard} />
);
}Confirm calls onConfirm and closes the dialog. Cancel closes without calling onConfirm. There is no busy state or wait for an asynchronous result.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | Required | Dialog heading |
description | string | — | Explanatory text below the heading |
cancelLabel | string | 'Cancel' | Cancel button text |
confirmLabel | string | Required | Confirm button text |
tone | 'destructive' | 'default' | 'destructive' | Styles the confirm button |
onConfirm | () => void | Required | Runs when the user confirms |
testID | string | Required | Identifies the dialog content and supplies the default button ID prefix |
cancelTestID | string | testID + -cancel | Overrides the cancel button ID |
confirmTestID | string | testID + -confirm | Overrides the confirm button ID |
trigger | React.ReactElement | — | Element that opens the dialog; omit it when controlling open externally |
open | boolean | Uncontrolled | Controls whether the dialog is open |
onOpenChange | (open: boolean) => void | — | Receives open and close requests; update open here in controlled usage |
Tones
| Tone | Confirm button variant | Cancel button variant |
|---|---|---|
destructive | destructive | outline |
default | default | outline |