vael-ui v0.5.7

Overlays & confirmation

confirmAction

A confirm step, shown as a centered dialog or a popover anchored to a trigger, that waits for your async handler before it closes. Use it before an action that’s hard to undo.

Opens a confirm flow with one function call. It shows a centered dialog by default (surface: 'dialog'), or a popover anchored to triggerEl with surface: 'popover'. TypeScript offers only the options that fit the surface you pick. The confirm button shows its loading state while onConfirm runs, and the surface closes only when it succeeds. If onConfirm rejects, the surface stays open and onError fires. confirmAction wraps openDialog and openPopover; use those for anything it doesn't cover.

Install

import { confirmAction } from 'vael-ui'

Examples

Parameters

NameTypeDescription
titlestringThe heading. Required on both surfaces.
descriptionstring
confirmLabel / cancelLabelstringThe button labels. Default 'Confirm' and 'Cancel'.
variantButtonVariantThe confirm button's style. Default 'primary'. Use 'danger' for destructive actions.
onConfirm() => unknown | Promise<unknown>Runs on confirm. The surface waits for it and closes when it succeeds.
onCancel() => void
onError(error: unknown) => voidFires when onConfirm rejects.
confirmButtonProps / cancelButtonPropsPartial<ButtonProps>Sets any Button prop, beyond the label and variant shortcuts.
body / bodyPropsComponent / Record<string, unknown>Adds content between the description and the buttons, such as a "type DELETE" input.
surface'dialog' | 'popover'Where the confirm opens: centered, or anchored to triggerEl. Default 'dialog'.
position / sizeDialogPosition / DialogSizeDialog's own position and size props. Only with surface: 'dialog'.
triggerElTriggerRefThe element the popover anchors to, as in openPopover. Required with surface: 'popover'.
side / align / sideOffset / …PopoverPropsPasses any other Popover prop through. Only with surface: 'popover'.

Returns

NameTypeDescription
resultPromise<boolean | undefined>Settles with the outcome: true on confirm, false on cancel, undefined when dismissed with Escape or an outside click.
close(result?: boolean) => voidCloses the surface from the opener's side.
panelEl{ readonly value: HTMLElement | null }The surface panel, null until it mounts. Use it to animate the panel yourself.