summaryrefslogtreecommitdiff
path: root/src/Toolbar/Concerns
diff options
context:
space:
mode:
Diffstat (limited to 'src/Toolbar/Concerns')
-rw-r--r--src/Toolbar/Concerns/WithAction.php33
-rw-r--r--src/Toolbar/Concerns/WithAttributes.php36
-rw-r--r--src/Toolbar/Concerns/WithHref.php17
-rw-r--r--src/Toolbar/Concerns/WithSlot.php17
4 files changed, 103 insertions, 0 deletions
diff --git a/src/Toolbar/Concerns/WithAction.php b/src/Toolbar/Concerns/WithAction.php
new file mode 100644
index 0000000..a1c33f2
--- /dev/null
+++ b/src/Toolbar/Concerns/WithAction.php
@@ -0,0 +1,33 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\LaralightTables\Toolbar\Concerns;
+
+trait WithAction
+{
+ protected ?string $action = null;
+
+ /**
+ * @param string|array{0: string, ...<int, string|numeric|bool|null>} $action
+ */
+ public function action(string|array $action): static
+ {
+ if (is_array($action)) {
+ $fn = array_shift($action);
+ $params = collect($action)->map(
+ fn ($v) => match (strtolower(gettype($v))) {
+ 'string' => "'{$v}'",
+ 'boolean' => $v ? 'true' : 'false',
+ 'null' => 'null',
+ default => (string) $v,
+ }
+ )->join(', ');
+ $this->action = "{$fn}({$params})";
+ } else {
+ $this->action = $action;
+ }
+
+ return $this;
+ }
+}
diff --git a/src/Toolbar/Concerns/WithAttributes.php b/src/Toolbar/Concerns/WithAttributes.php
new file mode 100644
index 0000000..3a37282
--- /dev/null
+++ b/src/Toolbar/Concerns/WithAttributes.php
@@ -0,0 +1,36 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\LaralightTables\Toolbar\Concerns;
+
+use Illuminate\View\ComponentAttributeBag;
+
+trait WithAttributes
+{
+ /**
+ * @var array<string, string>
+ */
+ protected ?array $attributes = null;
+
+ /**
+ * @param array<string, string> $attributes
+ */
+ public function attributes(array $attributes): static
+ {
+ $this->attributes = $attributes;
+
+ return $this;
+ }
+
+ /**
+ * @param array<string, string|null> $merge
+ */
+ protected function getAttributes(array $merge = []): ComponentAttributeBag
+ {
+ return new ComponentAttributeBag([
+ ...$merge,
+ ...($this->attributes ?? []),
+ ]);
+ }
+}
diff --git a/src/Toolbar/Concerns/WithHref.php b/src/Toolbar/Concerns/WithHref.php
new file mode 100644
index 0000000..50d4c81
--- /dev/null
+++ b/src/Toolbar/Concerns/WithHref.php
@@ -0,0 +1,17 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\LaralightTables\Toolbar\Concerns;
+
+trait WithHref
+{
+ protected string $href;
+
+ public function href(string $href): static
+ {
+ $this->href = $href;
+
+ return $this;
+ }
+}
diff --git a/src/Toolbar/Concerns/WithSlot.php b/src/Toolbar/Concerns/WithSlot.php
new file mode 100644
index 0000000..2279f1d
--- /dev/null
+++ b/src/Toolbar/Concerns/WithSlot.php
@@ -0,0 +1,17 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\LaralightTables\Toolbar\Concerns;
+
+trait WithSlot
+{
+ protected string $slot = '';
+
+ public function slot(string $slot): static
+ {
+ $this->slot = $slot;
+
+ return $this;
+ }
+}