Selkie--Widget--ConfirmModal
NAME
Selkie::Widget::ConfirmModal - Pre-built yes/no confirmation dialog
SYNOPSIS
use Selkie::Widget::ConfirmModal;
my $cm = Selkie::Widget::ConfirmModal.new;
$cm.build(
title => 'Delete file?',
message => "Really delete 'report.pdf'?",
yes-label => 'Delete',
no-label => 'Cancel',
);
$cm.on-result.tap: -> Bool $confirmed {
$app.close-modal;
do-delete() if $confirmed;
};
$app.show-modal($cm.modal);
$app.focus($cm.no-button); # safe defaultDESCRIPTION
A wrapper around Selkie::Widget::Modal with a pre-built title + message + yes/no button row. Emits a Bool on on-result when the user picks a button or presses Esc (Esc = False = No).
Use $cm.no-button (or yes-button) when calling focus on the app so the default focus is on the safer button.
Build the modal with build(...) and pass the returned Modal to $app.show-modal. The .modal accessor returns the same Modal after construction.
A primary mouse click on either button activates it ā Selkie::App's coordinate dispatcher routes the click to the deepest hit (the Button widget itself), and Button's built-in click handler fires the same on-press path Enter / Space drive. The default dismiss-on-click-outside stays False (a Yes/No decision shouldn't be silently abandoned by a stray click).
EXAMPLES
Delete confirmation
sub confirm-delete($item) {
my $cm = Selkie::Widget::ConfirmModal.new;
$cm.build(
title => 'Delete',
message => "Delete '{$item.name}'?",
yes-label => 'Delete',
no-label => 'Cancel',
);
$cm.on-result.tap: -> Bool $confirmed {
$app.close-modal;
if $confirmed {
$app.store.dispatch('item/delete', id => $item.id);
$app.toast('Deleted');
}
};
$app.show-modal($cm.modal);
$app.focus($cm.no-button);
}SEE ALSO
Selkie::Widget::Modal ā underlying dialog
Selkie::Widget::FileBrowser ā similar wrapper pattern for file picking
method on-result
method on-result() returns SupplySupply that emits a Bool when the user picks a button or presses Esc. True for Yes, False for No or Esc. The dialog stays open after emit ā the caller is expected to close the modal in the tap (see SYNOPSIS).
method build
method build(
Str :$title = "Confirm",
Str :$message = "Are you sure?",
Str :$yes-label = "Yes",
Str :$no-label = "No",
Rat :$width-ratio = 0.4,
Rat :$height-ratio = 0.3
) returns Selkie::Widget::ModalBuild the dialog. Returns the underlying Modal so the caller can pass it directly to $app.show-modal. Re-callable to rebuild with new labels (e.g. for a series of similar prompts).
method yes-button
method yes-button() returns Selkie::Widget::ButtonThe Yes button widget. Pass to $app.focus to make Yes the default.
method no-button
method no-button() returns Selkie::Widget::ButtonThe No button widget. Pass to $app.focus to make No the default (the safer choice for destructive confirmations).