Skip to content

Instantly share code, notes, and snippets.

@leek
Created October 1, 2025 15:07
Show Gist options
  • Select an option

  • Save leek/7f7dc87b66af48490f9a3598c7adbe24 to your computer and use it in GitHub Desktop.

Select an option

Save leek/7f7dc87b66af48490f9a3598c7adbe24 to your computer and use it in GitHub Desktop.
HasActiveIcon trait for Filament v4
<?php
namespace App\Concerns;
use Filament\Support\Icons\Heroicon;
use BackedEnum;
use Illuminate\Contracts\Support\Htmlable;
trait HasActiveIcon
{
public static function getActiveNavigationIcon(): string | BackedEnum | Htmlable | null
{
$icon = static::getNavigationIcon();
if (is_string($icon)) {
return str($icon)
->replace('heroicon-o', 'heroicon-s')
->replace('healthicons-o', 'healthicons-f')
->toString()
;
}
$name = str($icon->name)->replace('Outlined', '')->toString();
return Heroicon::{$name};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment