Skip to content

Commit

Permalink
add confirmation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bebo925 committed Oct 5, 2022
1 parent 7172968 commit 61ac33e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ php artisan vendor:publish --tag="tall-views"
</x-tall::table.row>
</x-slot>
</x-tall::table>

$emit('openDialog', 'tall-confirmation-dialog', [
'message' => 'Are you sure you want to delete?',
'title' => 'Warning',
'data' => $someId,
'confirmText' => 'Delete',
'style' => 'danger',
'event' = 'someEventToListenFor'
]);
```

## Credits
Expand Down
12 changes: 12 additions & 0 deletions resources/views/confirmation-dialog.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<x-tall::modal :showClose="false">
<x-slot name="title">{!! $title !!}</x-slot>

<div class="">
{!! $message !!}
</div>

<x-slot name="actions">
<x-tall::button.flat style="secondary" wire:click="cancel()" class="mr-2">{{$cancelText}}</x-tall::button.flat>
<x-tall::button style="{{$style}}" wire:click="confirm()">{{$confirmText}}</x-tall::button>
</x-slot>
</x-tall::modal>
49 changes: 49 additions & 0 deletions src/ConfirmationDialog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Tall;

use LivewireUI\Modal\ModalComponent;

class ConfirmationDialog extends ModalComponent
{
public $message;
public $title;
public $confirmText = 'OK';
public $cancelText = 'Cancel';
public $event = 'confirmed';
public $data;
public $style = 'primary';

public function confirm()
{
$this->closeModalWithEvents([
[$this->event, [true, $this->data]]
]);
}

public function cancel()
{
$this->closeModalWithEvents([
[$this->event, [false, $this->data]]
]);
}

public static function closeModalOnEscape(): bool
{
return false;
}

public static function closeModalOnClickAway(): bool
{
return false;
}

public function mount()
{
}

public function render()
{
return view('tall::confirmation-dialog');
}
}
9 changes: 8 additions & 1 deletion src/TallServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Tall;

use Livewire\Livewire;
use Tall\ConfirmationDialog;
use Tall\Commands\TallCommand;
use Tall\Commands\PublishTallStubs;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Tall\Commands\PublishTallStubs;

class TallServiceProvider extends PackageServiceProvider
{
Expand All @@ -24,4 +26,9 @@ public function configurePackage(Package $package): void

\Illuminate\Support\Facades\Blade::anonymousComponentNamespace('components', 'tall');
}

public function bootingPackage(): void
{
Livewire::component('tall-confirmation-dialog', ConfirmationDialog::class);
}
}

0 comments on commit 61ac33e

Please sign in to comment.