summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--resources/views/toolbar/button.blade.php3
-rw-r--r--src/Toolbar/Button.php51
-rw-r--r--workbench/app/Livewire/ProductsTable.php15
3 files changed, 68 insertions, 1 deletions
diff --git a/resources/views/toolbar/button.blade.php b/resources/views/toolbar/button.blade.php
new file mode 100644
index 0000000..2786888
--- /dev/null
+++ b/resources/views/toolbar/button.blade.php
@@ -0,0 +1,3 @@
+<button {{ $attributes }}>
+ {{ $slot }}
+</button>
diff --git a/src/Toolbar/Button.php b/src/Toolbar/Button.php
new file mode 100644
index 0000000..92b041f
--- /dev/null
+++ b/src/Toolbar/Button.php
@@ -0,0 +1,51 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\LaralightTables\Toolbar;
+
+use Illuminate\View\ComponentAttributeBag;
+use Illuminate\View\View;
+use Lightscale\LaralightTables\Concerns\WithAttributes;
+
+class Button extends Item
+{
+ use WithAttributes;
+
+ private ?string $action = null;
+
+ private string $slot = '';
+
+ public function action(string $action): static
+ {
+ $this->action = $action;
+
+ return $this;
+ }
+
+ public function slot(string $slot): static
+ {
+ $this->slot = $slot;
+
+ return $this;
+ }
+
+ private function makeAttributes(): ComponentAttributeBag
+ {
+ return $this->getAttributes()->merge([
+ 'wire:click' => $this->action,
+ ]);
+ }
+
+ public function render(): View
+ {
+ return view(
+ 'laralight-tables::toolbar.button',
+ [
+ 'action' => $this->action,
+ 'attributes' => $this->makeAttributes(),
+ 'slot' => $this->slot,
+ ]
+ );
+ }
+}
diff --git a/workbench/app/Livewire/ProductsTable.php b/workbench/app/Livewire/ProductsTable.php
index c3e29a5..5469c7d 100644
--- a/workbench/app/Livewire/ProductsTable.php
+++ b/workbench/app/Livewire/ProductsTable.php
@@ -5,6 +5,7 @@ namespace Workbench\App\Livewire;
use Illuminate\Database\Eloquent\Builder;
use Lightscale\LaralightTables\Columns\Column;
use Lightscale\LaralightTables\Toolbar;
+use Lightscale\LaralightTables\Toolbar\Button;
use Lightscale\LaralightTables\Toolbar\ColumnSelect;
use Lightscale\LaralightTables\Toolbar\PageSize;
use Lightscale\LaralightTables\Toolbar\Search;
@@ -38,10 +39,22 @@ class ProductsTable extends Table
->appendStart(Search::make())
->appendStart($categoryFilter)
->appendEnd(PageSize::make())
- ->appendEnd(ColumnSelect::make()),
+ ->appendEnd(ColumnSelect::make())
+ ->appendEnd( Button::make()
+ ->attributes([
+ 'class'=> 'btn btn-primary'
+ ])
+ ->slot('HELLO')
+ ->action('sayHello()')
+ ),
];
}
+ public function sayHello(): void
+ {
+ $this->js("alert('HELLO')");
+ }
+
public function query(): Builder
{
return parent::query()