codeat3/blade-iconpark
Laravel package providing IconPark SVGs as Blade components via Blade Icons. Use icons like with custom classes/styles, optional outline variants (-o), configurable defaults, and support for icon caching for better production performance.
Installation:
composer require codeat3/blade-iconpark
Publish the config (if needed):
php artisan vendor:publish --provider="Codeat3\BladeIconpark\BladeIconparkServiceProvider"
First Use Case: Add an icon to a Blade view:
<x-iconpark name="home" />
Or with custom classes:
<x-iconpark name="settings" class="text-blue-500" />
Where to Look First:
config/iconpark.php (customize icon set, default classes, etc.).php artisan iconpark:docs (if available) or check the GitHub README for supported icon names.resources/views/vendor/iconpark/ for default templates.Dynamic Icons via Variables:
@php
$iconName = $user->role === 'admin' ? 'admin' : 'user';
@endphp
<x-iconpark name="{{ $iconName }}" />
Reusable Icon Components:
Create a custom Blade component (e.g., resources/views/components/icon-button.blade.php):
<button type="button" class="p-2 rounded hover:bg-gray-100">
<x-iconpark name="{{ $icon }}" class="w-5 h-5" />
</button>
Usage:
<x-icon-button icon="search" />
Icon Sets and Theming:
Override the default icon set in config/iconpark.php:
'icon_set' => 'outline', // Options: 'outline', 'filled', 'round'
Or pass it dynamically:
<x-iconpark name="star" set="filled" />
Integration with Tailwind CSS: Use Tailwind’s arbitrary values for dynamic sizing:
<x-iconpark name="menu" class="w-[1.25rem] h-[1.25rem]" />
Lazy Loading Icons: Load icons only when needed (e.g., in a modal or dropdown):
@if (request()->wantsJson())
<x-iconpark name="spinner" class="animate-spin" />
@endif
Custom Icon Registration: Extend the package to register custom icons:
// In a service provider
BladeIconpark::registerIcon('custom-icon', 'path/to/icon.svg');
Icon-Based Navigation: Dynamically generate a sidebar menu:
@foreach ($menuItems as $item)
<a href="{{ route($item['route']) }}" class="flex items-center p-2">
<x-iconpark name="{{ $item['icon'] }}" class="mr-2" />
<span>{{ $item['label'] }}</span>
</a>
@endforeach
Dark Mode Support: Toggle icon variants based on theme:
<x-iconpark
name="moon"
class="{{ config('theme.dark') ? 'text-yellow-300' : 'text-gray-500' }}"
/>
Icon Name Typos:
php artisan iconpark:list (if available) or check the Icon Park docs for valid names.@error to catch missing icons:
@error
<span class="text-red-500">Icon "{{ $iconName }}" not found</span>
@enderror
Caching Issues:
php artisan view:clear
SVG Optimization:
inline option to optimize:
<x-iconpark name="graph" inline="true" />
Conflicting Class Names:
<x-iconpark name="alert" class="[--iconpark-color:theme('colors.red.500')]" />
Inspect Rendered HTML:
Check the <svg> output in the browser’s dev tools to verify attributes (e.g., fill, width, height).
Log Missing Icons: Add a fallback in your Blade component:
@php
$icon = BladeIconpark::getIcon($name) ?: 'help-circle';
@endphp
<x-iconpark name="{{ $icon }}" />
Check Config Overrides:
Ensure no other packages are modifying config/iconpark.php after your changes.
Custom Icon Sets:
Override the default set by publishing the config and extending the IconSet class:
// app/Providers/BladeIconparkServiceProvider.php
use Codeat3\BladeIconpark\Contracts\IconSet;
class CustomIconSet implements IconSet {
public function getIcons(): array {
return [
'custom-icon' => 'M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z',
];
}
}
Dynamic Icon Loading: Fetch icons from an API or database:
@foreach ($dynamicIcons as $icon)
<x-iconpark name="{{ $icon['name'] }}" set="{{ $icon['set'] }}" />
@endforeach
Accessibility (a11y): Add ARIA labels or titles:
<x-iconpark name="search" aria-label="Search" title="Click to search" />
Animation Support: Animate icons with Tailwind or CSS:
<x-iconpark name="spinner" class="animate-spin" />
Or use the inline option for custom animations:
<x-iconpark name="heart" inline="true" class="transition-colors duration-300" />
How can I help you explore Laravel packages today?