# Blade Icons
Blade Icons is a Laravel package that simplifies the usage of SVG icons in Blade views. Originally created as "Blade SVG" by Adam Wathan, it transforms raw SVG files into reusable Blade components, directives, and helper functions. The package supports multiple icon sets with unique prefixes, custom CSS classes, default attributes, fallback icons, and filesystem disk integration for external storage like AWS S3.
The core functionality revolves around registering icon sets with configurable paths and prefixes, then rendering those icons through three primary methods: Blade components (``), the `@svg` directive, or the `svg()` helper function. The package includes caching capabilities for production environments, accessibility features with title attributes, and a deferred rendering system to optimize DOM performance when the same icon appears multiple times on a page.
## Installation
Install the package via Composer and publish the configuration file.
```bash
# Install the package
composer require blade-ui-kit/blade-icons
# Publish the configuration file
php artisan vendor:publish --tag=blade-icons
```
## Configuration - Defining Icon Sets
Configure icon sets in `config/blade-icons.php` by specifying paths, prefixes, default classes, and attributes for each set.
```php
[
'default' => [
// Path to SVG icons relative to app root
'path' => 'resources/svg',
// Required unique prefix for this set
'prefix' => 'icon',
// Fallback icon when requested icon not found
'fallback' => 'placeholder',
// Default CSS classes for all icons in this set
'class' => 'icon icon-default',
// Default HTML attributes
'attributes' => [
'width' => 24,
'height' => 24,
],
],
'heroicons' => [
'path' => 'resources/icons/heroicons',
'prefix' => 'heroicon',
'class' => 'heroicon',
],
],
// Global default classes applied to all icons
'class' => '',
// Global default attributes
'attributes' => [],
// Global fallback icon (can reference any set)
'fallback' => 'icon-placeholder',
'components' => [
// Set to true to disable Blade components entirely
'disabled' => false,
// Name for the default component
'default' => 'icon',
],
];
```
## Configuration - Multiple Paths per Set
Define multiple directories for a single icon set using the `paths` option.
```php
[
'default' => [
'paths' => [
'resources/icons/solid',
'resources/icons/outline',
'resources/icons/custom',
],
'prefix' => 'icon',
],
],
];
```
## Configuration - Filesystem Disk
Load icons from external storage like AWS S3 by configuring a filesystem disk.
```php
[
'heroicons' => [
'path' => 'heroicons', // Path within the disk
'disk' => 's3-icons', // Disk name from filesystems.php
'prefix' => 'heroicon',
],
'zondicons' => [
'path' => 'zondicons',
'disk' => 's3-icons',
'prefix' => 'zondicon',
],
],
];
```
## Blade Components - Basic Usage
Use icons as Blade components with the format ``. Icons in subdirectories use dot notation.
```blade
{{-- Basic icon usage (from default set with 'icon' prefix) --}}
{{-- Icon from subdirectory resources/svg/solid/camera.svg --}}
{{-- Icon from heroicons set --}}
{{-- With CSS classes --}}
{{-- With additional attributes --}}
{{-- Output example --}}
{{--
--}}
```
## Blade Components - Default Icon Component
Use the `` component with a `name` attribute for dynamic icon selection.
```blade
{{-- Using the default Icon component --}}
{{-- With icon from another set (include prefix) --}}
{{-- With classes and attributes --}}
{{-- Dynamic icon name from variable --}}
{{-- Configure custom component name in config/blade-icons.php --}}
{{-- 'components' => ['default' => 'svg'] --}}
```
## Blade Components - Deferred Icons
Defer icon rendering to reduce DOM size when the same icon appears multiple times on a page.
```blade
{{-- Add defer attribute to defer icon rendering --}}
{{-- Custom hash for JavaScript reuse --}}
{{-- At the bottom of your layout, load the deferred icons --}}