blade-ui-kit/blade-heroicons
Use Heroicons in Laravel Blade via simple SVG components. Supports passing classes/styles, Blade Icons features (defaults, caching), and optional config publishing. Requires PHP 8+ and Laravel 9+.
Installation:
composer require blade-ui-kit/blade-heroicons
Ensure your project meets the requirements: PHP 8.0+ and Laravel 9+.
First Use Case: Use a Heroicon directly in a Blade view:
<x-heroicon-o-arrow-left class="w-6 h-6 text-gray-500" />
Replace o-arrow-left with any Heroicons name.
Explore Icons:
Browse the Heroicons website or check the resources/svg directory in the package for available icons.
Component-Based Icons: Use Blade components for icons with customizable classes and attributes:
<!-- Outline icon -->
<x-heroicon-o-check-circle class="w-5 h-5 text-green-500" />
<!-- Solid icon -->
<x-heroicon-s-check-circle class="w-5 h-5 text-green-500" />
<!-- Mini icon -->
<x-heroicon-m-check-circle class="w-4 h-4 text-green-500" />
<!-- Micro icon -->
<x-heroicon-c-check-circle class="w-3 h-3 text-green-500" />
Dynamic Icons with @svg Directive:
Use the @svg directive for dynamic icon selection:
@svg($iconName, 'w-6 h-6', ['class' => 'text-blue-500'])
Pass $iconName dynamically from your controller or logic.
Global Configuration: Publish the config file for default classes/attributes:
php artisan vendor:publish --tag=blade-heroicons-config
Customize defaults in config/blade-heroicons.php:
'default_classes' => 'w-5 h-5',
'default_attributes' => ['fill' => 'currentColor'],
Raw SVG Assets: Publish SVG files for direct use in assets:
php artisan vendor:publish --tag=blade-heroicons --force
Use in Blade:
<img src="{{ asset('vendor/blade-heroicons/o-arrow-left.svg') }}" width="20" height="20" />
Icon Selection Workflow:
o-, s-, m-, c-) in Blade.w-6 h-6) for sizing and styling.Dynamic Icon Rendering:
@svg directive:
@svg($dynamicIconName, 'w-5 h-5', ['class' => 'text-' . $color])
Component Integration: Create reusable components that include Heroicons:
@component('components.button')
<x-heroicon-o-arrow-left class="mr-2" />
Back
@endcomponent
Dark Mode Support: Use Tailwind’s dark mode classes with icons:
<x-heroicon-o-moon class="w-6 h-6 dark:text-yellow-300" />
Tailwind CSS: Leverage Tailwind’s utility classes for consistent icon styling:
<x-heroicon-o-bell class="w-6 h-6 text-gray-500 hover:text-blue-500" />
Accessibility:
Add aria-hidden="true" for decorative icons:
<x-heroicon-o-arrow-right aria-hidden="true" class="w-5 h-5" />
Icon Caching: Enable Blade Icons caching for performance:
php artisan config:cache
php artisan view:cache
Testing: Test icons in isolation using Laravel’s Blade testing helpers:
$this->blade('<x-heroicon-o-check-circle />')->assertSeeText('check-circle');
Icon Naming:
arrow-left), but some older versions may use underscores (e.g., arrow_left). Always refer to the Heroicons website for the latest naming conventions.@svg directive with dynamic names to avoid hardcoding:
@svg('heroicon-o-arrow-left', 'w-5 h-5')
Caching Issues:
php artisan view:clear
--force when publishing to overwrite existing files.Laravel Version Mismatch:
SVG Asset Paths:
public/vendor/blade-heroicons/. Hardcoding paths may break if the directory structure changes.asset() helper:
<img src="{{ asset('vendor/blade-heroicons/o-arrow-left.svg') }}" />
Dynamic @svg Directive:
@svg directive requires the full icon name (e.g., heroicon-o-arrow-left), not just the suffix (e.g., o-arrow-left).heroicon- to dynamic icon names:
@svg('heroicon-' . $iconSuffix, 'w-5 h-5')
Missing Icons:
resources/svg directory in the package or the Heroicons website.storage/framework/views/).Styling Not Applying:
w-6 h-6) are valid.<x-heroicon-o-arrow-left style="width: 24px; height: 24px; color: red;" />
Performance Issues:
php artisan config:clear
php artisan view:clear
Icon Organization:
<!-- resources/views/components/icons/navigation.blade.php -->
<x-heroicon-o-arrow-left class="w-5 h-5" />
Dark Mode Icons:
<x-heroicon-o-sun class="w-6 h-6 dark:hidden" />
<x-heroicon-o-moon class="w-6 h-6 hidden dark:block" />
Custom Icon Sets:
public/vendor/blade-heroicons/.Accessibility:
aria-label for interactive icons:
<button aria-label="Notifications">
<x-heroicon-o-bell class="w-6 h-6" />
</button>
Version Upgrades:
Performance Optimization:
php artisan config:cache
php artisan view:cache
c-) or mini (m-) icons for smaller UI elements to reduce file size.How can I help you explore Laravel packages today?