filafly/filament-phosphor-icons
composer require filafly/filament-phosphor-icons
PanelProvider:
use Filafly\Icons\Phosphor\PhosphorIcons;
public function panel(Panel $panel): Panel {
return $panel->plugin(PhosphorIcons::make());
}
Icon::make('heroicon-o-cog-6-tooth')->size(24)
Now uses Phosphor’s equivalent (e.g., Phosphor::Cog).config/filament-phosphor-icons.php for global defaults.PanelProvider:
PhosphorIcons::make()->bold()->duotone();
// Direct enum usage (recommended for clarity)
Icon::make(Phosphor::Cog)->size(20);
// Alias mapping (for legacy Filament icons)
Icon::make('heroicon-o-cog-6-tooth')->size(20); // Auto-mapped to Phosphor::Cog
// Conditional rendering with Phosphor
$icon = $record->isActive ? Phosphor::CheckCircle : Phosphor::XCircle;
Icon::make($icon)->color($record->isActive ? 'success' : 'danger');
// Group related icons (e.g., for a dashboard)
$dashboardIcons = [
Phosphor::House,
Phosphor::ChartBar,
Phosphor::Users,
];
use Filament\Widgets\Widget;
class StatsOverview extends Widget {
protected static string $view = 'widgets.stats-overview';
public function getIcon(): string {
return Phosphor::Gauge; // Uses Phosphor enum
}
}
// Table columns
Table::make()
->columns([
Tables\Columns\IconColumn::make('status')
->icon(fn ($record) => $record->isActive ? Phosphor::Check : Phosphor::X),
]);
// Form buttons
Buttons\Action::make('edit')
->icon(Phosphor::PencilSimple)
->color('primary');
PhosphorIcons::make()
->regular() // Global
->overrideStyleForAlias('heroicon-o-cog-6-tooth', PhosphorIcons::STYLE_BOLD);
// In a view
@php
$iconStyle = request()->get('icon_style', 'regular');
PhosphorIcons::setStyle($iconStyle);
@endphp
Alias Mismatches:
php artisan vendor:publish --tag="filament-phosphor-icons-config"
Then check config/filament-phosphor-icons.php for mappings.Style Inconsistencies:
duotone) may clash with Filament’s default colors. Test in isolation:
Icon::make(Phosphor::AlertCircle)->style(PhosphorIcons::STYLE_DUOTONE)->color('warning');
Caching Issues:
php artisan filament:cache-reset
data-icon attributes).PhosphorIcons service provider:
public function boot() {
\Log::info('Phosphor Alias Mappings:', [
'heroicon-o-cog-6-tooth' => PhosphorIcons::getAliasMap()['heroicon-o-cog-6-tooth'] ?? 'Not mapped',
]);
}
Custom Icon Sets:
Extend the PhosphorIcons class to add domain-specific icons:
class CustomPhosphorIcons extends PhosphorIcons {
public static function make(): static {
static::registerIcon('custom-icon', 'path/to/svg.svg');
return parent::make();
}
}
Dynamic SVG Injection:
Override the SVG rendering logic in app/Providers/AppServiceProvider:
public function boot() {
Icon::macro('customSvg', function ($icon, $attributes = []) {
return '<svg>'.file_get_contents(resource_path("views/svg/{$icon}.svg")).'</svg>';
});
}
Style Presets: Create a config file for reusable style presets:
// config/phosphor-presets.php
return [
'dashboard' => PhosphorIcons::STYLE_LIGHT,
'admin' => PhosphorIcons::STYLE_BOLD,
];
Then load them in your PanelProvider:
PhosphorIcons::make()->style(config('phosphor-presets.dashboard'));
document.addEventListener('DOMContentLoaded', () => {
if (window.location.pathname.includes('admin')) {
document.querySelectorAll('[data-icon]').forEach(el => {
el.style.setProperty('--icon-style', 'bold');
});
}
});
public function test_icon_renders_correctly() {
$icon = Icon::make(Phosphor::Cog)->size(24);
$this->assertStringContainsString('cog', $icon->getSvg());
}
public function test_style_override() {
PhosphorIcons::make()->overrideStyleForAlias('heroicon-o-cog-6-tooth', PhosphorIcons::STYLE_BOLD);
$icon = Icon::make('heroicon-o-cog-6-tooth');
$this->assertStringContainsString('bold', $icon->getSvg());
}
How can I help you explore Laravel packages today?