Skip to content

Commit

Permalink
Add link modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 authored Dec 5, 2024
1 parent f812095 commit 29979cc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Support/Html/Mixins/LinkElementMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

namespace Foxws\WireUse\Support\Html\Mixins;

use Illuminate\Support\Stringable;
use Spatie\Html\Elements\A;
use stdClass;

class LinkElementMixin extends stdClass
{
public function link(): mixed
public function link(?string $modifiers = null): mixed
{
return function (string $route, ...$parameters) {
return function (string $route, array $parameters = [], ?string $modifiers = null) {
/** @var A $this */
$href = route($route, ...$parameters);
$href = route($route, $parameters);

$current = str('wire:current')
->when($modifiers, fn (Stringable $str) => $str->append(".{$modifiers}"))
->squish();

return $this
->attributes([
'wire:navigate',
'wire:current' => 'link-active',
])
->attribute('wire:navigate')
->attribute($current->value(), 'link-active')
->class('link')
->href($href);
};
Expand Down

0 comments on commit 29979cc

Please sign in to comment.