https://github.com/roelmagdaleno/php-heroicons
A package to render Heroicons in your PHP application.
https://github.com/roelmagdaleno/php-heroicons
heroicons php
Last synced: about 1 month ago
JSON representation
A package to render Heroicons in your PHP application.
- Host: GitHub
- URL: https://github.com/roelmagdaleno/php-heroicons
- Owner: roelmagdaleno
- Created: 2021-07-28T02:55:05.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-13T22:17:32.000Z (5 months ago)
- Last Synced: 2025-04-12T07:11:56.447Z (about 1 month ago)
- Topics: heroicons, php
- Language: PHP
- Homepage:
- Size: 282 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP Heroicons
A package to render [Heroicons](https://github.com/tailwindlabs/heroicons) in your PHP application.
Preview the icons at [heroicons.com](https://heroicons.com), developed by [Steve Schoger](https://twitter.com/steveschoger) and [Adam Wathan](https://twitter.com/adamwathan).
If you want to render Heroicons in your Laravel Blade views, use [Blade Heroicons](https://github.com/blade-ui-kit/blade-heroicons) package.
## Installation
### Composer
```shell
composer require roelmagdaleno/php-heroicons
```## Usage
You can render a Heroicon using multiple ways:
### Helper
Return the SVG by using the `heroicon()` helper function:
```php
$text = heroicon('check-circle', ['width' => 60]);
echo "My icon is: $text
";
```Print the SVG directly:
```php
echo heroicon('check-circle', ['width' => 60]);
```### Constructor
Instantiate an `Icon` class with parameters and print it directly:
```php
use PHPHeroIcons\Icon;echo new Icon('check-circle', ['width' => 60]);
```Instantiate an `Icon` class with parameters and call the `render()` method.
```php
use PHPHeroIcons\Icon;$icon = new Icon('academic-cap', ['width' => 60]);
$icon->render();
```Instantiate an `Icon` class with parameters and call the `return()` method.
```php
use PHPHeroIcons\Icon;$icon = new Icon('academic-cap', ['width' => 60]);
$text = $icon->return();echo "
My icon is: $text
";
```### Render Method
If you want to render multiples icons and only use one `Icon` instance:
```php
use PHPHeroIcons\Icon;$icon = new Icon();
$icon->render('check-circle', ['width' => 60]);
$icon->render('academic-cap', ['width' => 60]);
$icon->render('library', ['width' => 60]);
```### Return Method
If you want to return multiples icons and only use one `Icon` instance:
```php
use PHPHeroIcons\Icon;$icon = new Icon();
$first = $icon->return('check-circle', ['width' => 60]);
$second = $icon->return('academic-cap', ['width' => 60]);
$third = $icon->return('library', ['width' => 60]);echo "My first icon is: $first then use the $second and $third";
```## Parameters
The `Icon` constructor, `heroicon()`, `render()` and `return()` methods accepts these attributes in this order:
- $icon
- $attributes
- $typeExample:
```php
heroicon($icon, $attributes, $type);
```The `$icon` accepts any [Heroicon](https://heroicons.com) slug and if you insert an icon that doesn't exist it won't return anything.
For `$attributes` (optional) you can pass only these attributes as array key/value format:
- `width`
- `height`
- `class`
- `id`If you pass an attribute that is not listed previously it won't be attached to the SVG HTML.
And last, but not least, you can specify the Heroicon `$type`:
- `solid`
- `outline`By default the icons will be printed in `solid` type.
Example:
```php
heroicon(
'library',
[
'width' => 60,
'height' => 60,
'class' => 'my-custom-css-class',
'id' => 'my-custom-id',
]
); // Print solid icon with multiple attributes.heroicon(
'check-circle',
[
'width' => 60,
'height' => 60,
'class' => 'my-custom-css-class',
'id' => 'my-custom-id',
],
'outline'
); // Print outline icon with multiple attributes.
```## Examples
For more usage examples visit the `examples/index.php` file or visit the [PHPSandbox.io](https://phpsandbox.io/e/x/8qt7v?layout=EditorPreview&iframeId=z2x1jnoxen&theme=dark&defaultPath=%2F&showExplorer=no#index.php) to play with the code.