diff options
Diffstat (limited to 'src/Toolbar/Button.php')
| -rw-r--r-- | src/Toolbar/Button.php | 51 |
1 files changed, 51 insertions, 0 deletions
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, + ] + ); + } +} |
