Skip to content

Commit

Permalink
feat: evaluate closure
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanalhattami committed Apr 18, 2024
1 parent 3af1f74 commit fd267b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
12 changes: 6 additions & 6 deletions resources/views/components/context-menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class="h-6 w-6 ml-auto text-xs tracking-widest text-neutral-400 group-hover:text
/>
</span>
<span>{{ $item->getTitle() }}</span>
<span>
<x-filament::icon
:icon="$item->getIcon()"
class="h-6 w-6 ml-auto text-xs tracking-widest text-neutral-400 group-hover:text-neutral-600"
/>
</span>
{{-- <span>--}}
{{-- <x-filament::icon--}}
{{-- :icon="$item->getIcon()"--}}
{{-- class="h-6 w-6 ml-auto text-xs tracking-widest text-neutral-400 group-hover:text-neutral-600"--}}
{{-- />--}}
{{-- </span>--}}
</a>
@endforeach
</div>
Expand Down
20 changes: 16 additions & 4 deletions src/ContentMenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace AymanAlhattami\FilamentContextMenu;

use Closure;
use Filament\Support\Concerns\EvaluatesClosures;

class ContentMenuItem
{
use EvaluatesClosures;

private Closure | string | null $title = null;

private Closure | string | null $url = null;
Expand All @@ -20,7 +25,7 @@ public static function make(): static

public function getTitle(): ?string
{
return $this->title;
return $this->evaluate($this->title);
}

public function title(Closure | string | null $title): static
Expand All @@ -30,9 +35,16 @@ public function title(Closure | string | null $title): static
return $this;
}

public function translateTitle(): static
{
$this->title = __($this->getTitle());

return $this;
}

public function getUrl(): ?string
{
return $this->url;
return $this->evaluate($this->url);
}

public function url(Closure | string | null $url): static
Expand All @@ -44,7 +56,7 @@ public function url(Closure | string | null $url): static

public function getIcon(): ?string
{
return $this->icon;
return $this->evaluate($this->icon);
}

public function icon(Closure | string | null $icon): static
Expand All @@ -56,7 +68,7 @@ public function icon(Closure | string | null $icon): static

public function getTarget(): ?string
{
return $this->target;
return $this->evaluate($this->target);
}

public function target(Closure | string | null $target): static
Expand Down

0 comments on commit fd267b8

Please sign in to comment.