From dc785e9de310a3bc152f5208f269620d597392e4 Mon Sep 17 00:00:00 2001 From: francoism90 Date: Tue, 23 Apr 2024 10:55:50 +0200 Subject: [PATCH] wip --- resources/views/actions/button.blade.php | 43 +++++++++++-------- resources/views/actions/link.blade.php | 6 +-- resources/views/navigation/group.blade.php | 49 ++++++++++++++++++++++ src/Actions/Components/Button.php | 24 ++++++++--- src/Actions/Components/Link.php | 5 ++- src/Actions/Concerns/HasComponent.php | 17 ++++++++ src/Actions/Concerns/HasView.php | 16 +++++++ src/Actions/Support/Action.php | 4 ++ src/Actions/Support/Group.php | 5 ++- src/Navigation/Components/Group.php | 24 +++++++++++ src/Navigation/Concerns/WithNavigation.php | 13 ++++++ src/Views/Concerns/WithLayout.php | 8 ++++ src/WireUseServiceProvider.php | 16 ++++--- 13 files changed, 194 insertions(+), 36 deletions(-) create mode 100644 resources/views/navigation/group.blade.php create mode 100644 src/Actions/Concerns/HasComponent.php create mode 100644 src/Actions/Concerns/HasView.php create mode 100644 src/Navigation/Components/Group.php create mode 100644 src/Navigation/Concerns/WithNavigation.php create mode 100644 src/Views/Concerns/WithLayout.php diff --git a/resources/views/actions/button.blade.php b/resources/views/actions/button.blade.php index 814e3d45..b5bad333 100644 --- a/resources/views/actions/button.blade.php +++ b/resources/views/actions/button.blade.php @@ -1,17 +1,26 @@ - +cssClass([ + 'layer' => 'inline-flex shrink-0 cursor-pointer items-center hover:text-primary-400', + 'active' => 'text-primary-400 hover:text-primary-300', + 'inactive' => 'text-secondary', + ]) + ->classMerge([ + 'layer', + 'active' => $active(), + 'inactive' => ! $active(), + ]) + ->merge([ + 'href' => $url(), + 'aria-label' => $action->getLabel(), + 'title' => $action->getLabel(), + ]) + }} +> + @if ($slot->isEmpty()) + {{ $action->getLabel() }} + @else + {{ $slot }} + @endif + diff --git a/resources/views/actions/link.blade.php b/resources/views/actions/link.blade.php index b5bad333..40c8a662 100644 --- a/resources/views/actions/link.blade.php +++ b/resources/views/actions/link.blade.php @@ -2,9 +2,9 @@ @if ($navigate()) wire:navigate @endif {{ $attributes ->cssClass([ - 'layer' => 'inline-flex shrink-0 cursor-pointer items-center hover:text-primary-400', + 'layer' => 'inline-flex shrink-0 cursor-pointer items-center', 'active' => 'text-primary-400 hover:text-primary-300', - 'inactive' => 'text-secondary', + 'inactive' => 'text-secondary hover:text-primary-400', ]) ->classMerge([ 'layer', @@ -12,7 +12,7 @@ 'inactive' => ! $active(), ]) ->merge([ - 'href' => $url(), + 'href' => $attributes->has('wire:click') ? false : $url(), 'aria-label' => $action->getLabel(), 'title' => $action->getLabel(), ]) diff --git a/resources/views/navigation/group.blade.php b/resources/views/navigation/group.blade.php new file mode 100644 index 00000000..59e1cb07 --- /dev/null +++ b/resources/views/navigation/group.blade.php @@ -0,0 +1,49 @@ + diff --git a/src/Actions/Components/Button.php b/src/Actions/Components/Button.php index 8c0878c1..6dc3565e 100644 --- a/src/Actions/Components/Button.php +++ b/src/Actions/Components/Button.php @@ -1,20 +1,34 @@ action->isActive(); + } + + public function icon(): ?string + { + return $this->when($this->active(), + fn () => $this->action->getActiveIcon(), + fn () => $this->action->getIcon(), + ); } } diff --git a/src/Actions/Components/Link.php b/src/Actions/Components/Link.php index be06d26c..d22fdae7 100644 --- a/src/Actions/Components/Link.php +++ b/src/Actions/Components/Link.php @@ -4,11 +4,14 @@ use Closure; use Foxws\WireUse\Actions\Support\Action; +use Foxws\WireUse\Views\Concerns\WithLayout; use Foxws\WireUse\Views\Support\Component; use Illuminate\View\View; class Link extends Component { + use WithLayout; + public function __construct( public Action $action, ) { @@ -25,7 +28,7 @@ public function url(): ?string return $this->action->getRoute(); } - return $this->action->getUrl() ?? '/'; + return $this->action->getUrl() ?? '#'; } public function active(): bool diff --git a/src/Actions/Concerns/HasComponent.php b/src/Actions/Concerns/HasComponent.php new file mode 100644 index 00000000..90450024 --- /dev/null +++ b/src/Actions/Concerns/HasComponent.php @@ -0,0 +1,17 @@ +component = $component; + + return $this; + } +} diff --git a/src/Actions/Concerns/HasView.php b/src/Actions/Concerns/HasView.php new file mode 100644 index 00000000..2a302144 --- /dev/null +++ b/src/Actions/Concerns/HasView.php @@ -0,0 +1,16 @@ +view = $view; + + return $this; + } +} diff --git a/src/Actions/Support/Action.php b/src/Actions/Support/Action.php index 075aade8..330ff2c8 100644 --- a/src/Actions/Support/Action.php +++ b/src/Actions/Support/Action.php @@ -2,20 +2,24 @@ namespace Foxws\WireUse\Actions\Support; +use Foxws\WireUse\Actions\Concerns\HasComponent; use Foxws\WireUse\Actions\Concerns\HasIcon; use Foxws\WireUse\Actions\Concerns\HasName; use Foxws\WireUse\Actions\Concerns\HasRequest; use Foxws\WireUse\Actions\Concerns\HasRoute; use Foxws\WireUse\Actions\Concerns\HasState; +use Foxws\WireUse\Actions\Concerns\HasView; use Foxws\WireUse\Support\Components\Component; class Action extends Component { + use HasComponent; use HasIcon; use HasName; use HasRequest; use HasRoute; use HasState; + use HasView; public static function make(): static { diff --git a/src/Actions/Support/Group.php b/src/Actions/Support/Group.php index f9e322d5..86acda6d 100644 --- a/src/Actions/Support/Group.php +++ b/src/Actions/Support/Group.php @@ -6,5 +6,8 @@ class Group extends Collection { - // + public function items(): array + { + return $this->all(); + } } diff --git a/src/Navigation/Components/Group.php b/src/Navigation/Components/Group.php new file mode 100644 index 00000000..6223324a --- /dev/null +++ b/src/Navigation/Components/Group.php @@ -0,0 +1,24 @@ + $value) { $key = app(Bladeable::class)::classKeys($key)->first(); @@ -69,6 +70,7 @@ protected function registerBladeMacros(): static ComponentAttributeBag::macro('classMerge', function (?array $values = null): ComponentAttributeBag { /** @var ComponentAttributeBag $this */ + $classes = app(Bladeable::class)::classMerged($this, $values) ->merge($this->get('class')) ->join(' '); @@ -82,6 +84,7 @@ protected function registerBladeMacros(): static ComponentAttributeBag::macro('classOnly', function (array $values): ComponentAttributeBag { /** @var ComponentAttributeBag $this */ + $classes = app(Bladeable::class)::classMerged($this, $values) ->join(' '); @@ -103,22 +106,17 @@ protected function registerBladeMacros(): static return $this; }); - ComponentAttributeBag::macro('classWithout', function (): ComponentAttributeBag { + ComponentAttributeBag::macro('classFor', function (string $key, ?string $default = null): string { /** @var ComponentAttributeBag $this */ - return $this - ->whereDoesntStartWith('class:'); + return $this->get(app(Bladeable::class)::classKeys($key)->first(), $default ?? ''); }); - ComponentAttributeBag::macro('classFor', function (string $key, ?string $default = null): ComponentAttributeBag { + ComponentAttributeBag::macro('classWithout', function (): ComponentAttributeBag { /** @var ComponentAttributeBag $this */ - $value = $this->get(app(Bladeable::class)::classKeys($key)->first(), $default ?? ''); - - $this->offsetSet('class', $value); return $this - ->classSort() - ->classWithout(); + ->whereDoesntStartWith('class:'); }); return $this;