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 default

DESCRIPTION

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

method on-result

method on-result() returns Supply

Supply 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::Modal

Build 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::Button

The Yes button widget. Pass to $app.focus to make Yes the default.

method no-button

method no-button() returns Selkie::Widget::Button

The No button widget. Pass to $app.focus to make No the default (the safer choice for destructive confirmations).

Selkie v0.10.0

High-level TUI framework built on Notcurses

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

Notcurses::Native:ver<0.4.0+>:auth<zef:apogee>

Test Dependencies

Provides

  • Selkie
  • Selkie::App
  • Selkie::App::Internal::Dispatch
  • Selkie::App::Internal::ErrorLog
  • Selkie::App::Internal::FocusTree
  • Selkie::App::Internal::HitTest
  • Selkie::App::Internal::IdleBudget
  • Selkie::App::Internal::OverlayTree
  • Selkie::App::Internal::RenderLoop
  • Selkie::App::Internal::ScreenModalLifecycle
  • Selkie::App::Internal::Terminal
  • Selkie::App::Internal::TerminalSequences
  • Selkie::Container
  • Selkie::EffectiveBounds
  • Selkie::Event
  • Selkie::Layout::Allocate
  • Selkie::Layout::HBox
  • Selkie::Layout::Split
  • Selkie::Layout::VBox
  • Selkie::Plot::Palette
  • Selkie::Plot::Scaler
  • Selkie::Plot::Ticks
  • Selkie::ScreenManager
  • Selkie::Sizing
  • Selkie::Store
  • Selkie::Style
  • Selkie::Test::Focus
  • Selkie::Test::Keys
  • Selkie::Test::Snapshot
  • Selkie::Test::Snapshot::Harness
  • Selkie::Test::Store
  • Selkie::Test::Supply
  • Selkie::Test::Tree
  • Selkie::Theme
  • Selkie::Trace
  • Selkie::Tree
  • Selkie::Widget
  • Selkie::Widget::Axis
  • Selkie::Widget::BarChart
  • Selkie::Widget::Border
  • Selkie::Widget::Button
  • Selkie::Widget::CardList
  • Selkie::Widget::Checkbox
  • Selkie::Widget::CommandPalette
  • Selkie::Widget::ConfirmModal
  • Selkie::Widget::FileBrowser
  • Selkie::Widget::FocusableByDefault
  • Selkie::Widget::Heatmap
  • Selkie::Widget::HelpOverlay
  • Selkie::Widget::Histogram
  • Selkie::Widget::Image
  • Selkie::Widget::Legend
  • Selkie::Widget::LineChart
  • Selkie::Widget::ListView
  • Selkie::Widget::Modal
  • Selkie::Widget::MultiLineInput
  • Selkie::Widget::PasswordStrength
  • Selkie::Widget::Plot
  • Selkie::Widget::ProgressBar
  • Selkie::Widget::RadioGroup
  • Selkie::Widget::RichText
  • Selkie::Widget::RichText::Span
  • Selkie::Widget::ScatterPlot
  • Selkie::Widget::ScrollView
  • Selkie::Widget::Select
  • Selkie::Widget::Sparkline
  • Selkie::Widget::Spinner
  • Selkie::Widget::TabBar
  • Selkie::Widget::Table
  • Selkie::Widget::Text
  • Selkie::Widget::TextInput
  • Selkie::Widget::TextInput::HighlightSpan
  • Selkie::Widget::TextStream
  • Selkie::Widget::Toast
  • Selkie::Widget::ViewportedCardList

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.