Chandra
view release on metacpan or search on metacpan
examples/modal.pl view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use lib 'blib/lib', 'blib/arch', 'lib';
use Chandra::App;
use Chandra::Modal;
use Chandra::Toast;
my $app = Chandra::App->new(
title => 'Modal Demo',
width => 600,
height => 400,
debug => 1
);
$app->theme('dark');
# ââ Confirm dialog ââââââââââââââââââââââââââââââââââââââââ
$app->bind('show_confirm', sub {
Chandra::Modal->confirm($app,
title => 'Delete Project',
message => 'This will permanently delete the project and all its files. This action cannot be undone.',
on_ok => sub {
$app->toast('Project deleted', type => 'success');
},
);
});
# ââ Prompt dialog âââââââââââââââââââââââââââââââââââââââââ
$app->bind('show_prompt', sub {
Chandra::Modal->prompt($app,
title => 'Rename File',
label => 'New filename:',
value => 'document.txt',
on_submit => sub {
my ($value) = @_;
$app->toast("Renamed to: $value", type => 'info');
},
);
});
# ââ Custom modal ââââââââââââââââââââââââââââââââââââââââââ
$app->bind('show_custom', sub {
Chandra::Modal->show($app,
title => 'About This App',
width => 450,
content => '<div style="text-align:center;">'
. '<h2 style="margin:0 0 8px;">Modal Demo</h2>'
. '<p style="color:var(--chandra-text-muted);">Version 1.0.0</p>'
. '<p>Built with <strong>Chandra</strong> — '
. 'a Perl desktop GUI framework.</p>'
. '<hr>'
. '<p style="font-size:0.85em;color:var(--chandra-text-muted);">'
. 'Modals, toasts, themes, tables, and components — all in XS.</p>'
. '</div>',
buttons => [
{ label => 'Close', class => 'primary', action => 'close' },
],
);
});
# ââ Multi-button modal ââââââââââââââââââââââââââââââââââââ
$app->bind('show_multi', sub {
Chandra::Modal->show($app,
title => 'Save Changes?',
message => 'You have unsaved changes. What would you like to do?',
width => 420,
buttons => [
{ label => 'Discard', class => 'danger', action => sub {
$app->toast('Changes discarded', type => 'warning');
}},
{ label => 'Cancel', class => 'secondary', action => 'close' },
{ label => 'Save', class => 'primary', action => sub {
$app->toast('Changes saved', type => 'success');
}},
],
);
});
# ââ Layout ââââââââââââââââââââââââââââââââââââââââââââââââ
$app->set_content(<<'HTML');
<div style="padding:40px; text-align:center;">
<h1>Modal Dialogs</h1>
<p style="color:var(--chandra-text-muted); margin-bottom:32px;">
Click a button to see each modal type.
</p>
<div style="display:flex; flex-direction:column; gap:12px; max-width:300px; margin:0 auto;">
<button class="chandra-btn-primary" onclick="window.chandra.invoke('show_confirm', [])">
Confirm Dialog
</button>
<button class="chandra-btn-primary" onclick="window.chandra.invoke('show_prompt', [])">
Prompt Dialog
</button>
<button class="chandra-btn" onclick="window.chandra.invoke('show_custom', [])">
Custom Modal
</button>
<button class="chandra-btn" onclick="window.chandra.invoke('show_multi', [])">
Multi-Button Modal
</button>
</div>
</div>
HTML
$app->run;
( run in 0.710 second using v1.01-cache-2.11-cpan-df04353d9ac )