bugo / moonshine-heroicons-field
Heroicons selection field for MoonShine
Package info
github.com/dragomano/moonshine-heroicons-field
pkg:composer/bugo/moonshine-heroicons-field
Requires
- php: ^8.4
- blade-ui-kit/blade-heroicons: ^2.7
Requires (Dev)
- laravel/pint: ^1.32
- moonshine/moonshine: ^5.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.7|^5.3
- pestphp/pest-plugin-laravel: ^4.0|^5.0
- rector/rector: ^2.8
Suggests
None
Provides
None
Conflicts
- moonshine/moonshine: <5.0
Replaces
None
README
Convenient Heroicons selection field for MoonShine
Support MoonShine versions
| MoonShine | This package |
|---|---|
| 2.0+ | 0.x |
| 3.0+ | 1.x |
| 4.0+ | 2.x |
| 5.0+ | 3.x |
Requirements
MoonShine 5 requires PHP 8.4+ and Laravel 11, 12 or 13.
Laravel 11 is out of upstream security support and still has an unpatched advisory, so Composer blocks it by default. Use Laravel 12 or 13 for new projects.
Installation
composer require bugo/moonshine-heroicons-field
Configuration
You can specify desired default style for icons:
.env:
HEROICONS_STYLE=outline
config/heroicons-field.php:
php artisan vendor:publish --tag=heroicons-field
/* * Possible values: * 's', 'solid' - Solid 24x24, Solid fill * 'o', 'outline' - Outline 24x24, 1.5px stroke * 'm', 'mini' - Mini 20x20, Solid fill * 'c', 'micro' - Micro 16x16, Solid fill */ return [ 'style' => env('HEROICONS_STYLE', 'solid'), ];
Usage
You can use IconSelect field in your resources:
<?php declare(strict_types=1); namespace App\MoonShine\Resources; use Bugo\MoonShine\Heroicons\Fields\IconSelect; use MoonShine\Laravel\Resources\ModelResource; use MoonShine\Contracts\UI\FieldContract; use MoonShine\Contracts\UI\ComponentContract; /** * @extends ModelResource<Custom> */ class CustomResource extends ModelResource { /** * @return list<ComponentContract|FieldContract> */ protected function formFields(): iterable { return [ IconSelect::make('Icon') ->searchable() ->useStyle('mini'), ]; } }
All use cases of Blade Heroicons are also available for you.
Escaping
Since MoonShine 5 labels, hints and prefixes are escaped by default. If you need raw HTML in them, disable escaping for the specific element:
IconSelect::make('<strong>Icon</strong>') ->unescapeLabel();
Caching
When using icons in Blade templates, be sure to enable Caching.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.