Icons
Overview
Icons are used throughout the entire Filament UI to visually communicate core parts of the user experience. To render icons, we use the Blade Icons package from Blade UI Kit.
They have a website where you can search all the available icons from various Blade Icons packages. Each package contains a different icon set that you can choose from.
Using custom SVGs as icons
The Blade Icons package allows you to register custom SVGs as icons. This is useful if you want to use your own custom icons in Filament.
To start with, publish the Blade Icons configuration file:
php artisan vendor:publish --tag=blade-icons
Now, open the config/blade-icons.php
file, and uncomment the default
set in the sets
array.
Now that the default set exists in the config file, you can simply put any icons you want inside the resources/svg
directory of your application. For example, if you put an SVG file named star.svg
inside the resources/svg
directory, you can reference it anywhere in Filament as icon-star
. The icon-
prefix is configurable in the config/blade-icons.php
file too. You can also render the custom icon in a Blade view using the @svg('icon-star')
directive.
Replacing the default icons
Filament includes an icon management system that allows you to replace any icons are used by default in the UI with your own. This happens in the boot()
method of any service provider, like AppServiceProvider
, or even a dedicated service provider for icons. If you wanted to build a plugin to replace Heroicons with a different set, you could absolutely do that by creating a Laravel package with a similar service provider.
To replace an icon, you can use the FilamentIcon
facade. It has a register()
method, which accepts an array of icons to replace. The key of the array is the unique icon alias that identifies the icon in the Filament UI, and the value is name of a Blade icon to replace it instead. Alternatively, you may use HTML instead of an icon name to render an icon from a Blade view for example:
use Filament\Support\Facades\FilamentIcon;
FilamentIcon::register([
'panels::topbar.global-search.field' => 'fas-magnifying-glass',
'panels::sidebar.group.collapse-button' => view('icons.chevron-up'),
]);
Allowing users to customize icons from your plugin
If you have built a Filament plugin, your users may want to be able to customize icons in the same way that they can with any core Filament package. This is possible if you replace any manual @svg()
usages with the <x-filament::icon>
Blade component. This component allows you to pass in an icon alias, the name of the SVG icon that should be used by default, and any classes or HTML attributes:
<x-filament::icon
alias="panels::topbar.global-search.field"
icon="heroicon-m-magnifying-glass"
wire:target="search"
class="h-5 w-5 text-gray-500 dark:text-gray-400"
/>
Alternatively, you may pass an SVG element into the component's slot instead of defining a default icon name:
<x-filament::icon
alias="panels::topbar.global-search.field"
wire:target="search"
class="h-5 w-5 text-gray-500 dark:text-gray-400"
>
<svg>
<!-- ... -->
</svg>
</x-filament::icon>