From 536fa6c917d63b14feeb8f876e6a1d62acb577fc Mon Sep 17 00:00:00 2001 From: Sam Light Date: Thu, 12 Feb 2026 00:23:02 +0000 Subject: Created new dropdown toolbar item --- src/Toolbar/Concerns/WithAction.php | 33 ++++++++++++++++++++++++++++++ src/Toolbar/Concerns/WithAttributes.php | 36 +++++++++++++++++++++++++++++++++ src/Toolbar/Concerns/WithHref.php | 17 ++++++++++++++++ src/Toolbar/Concerns/WithSlot.php | 17 ++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 src/Toolbar/Concerns/WithAction.php create mode 100644 src/Toolbar/Concerns/WithAttributes.php create mode 100644 src/Toolbar/Concerns/WithHref.php create mode 100644 src/Toolbar/Concerns/WithSlot.php (limited to 'src/Toolbar/Concerns') 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 @@ +} $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 @@ + + */ + protected ?array $attributes = null; + + /** + * @param array $attributes + */ + public function attributes(array $attributes): static + { + $this->attributes = $attributes; + + return $this; + } + + /** + * @param array $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 @@ +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 @@ +slot = $slot; + + return $this; + } +} -- cgit v1.2.3