A package to render Heroicons in your PHP application.

Overview

PHP Heroicons

A package to render Heroicons in your PHP application.

Preview the icons at heroicons.com, developed by Steve Schoger and Adam Wathan.

If you want to render Heroicons in your Laravel Blade views, use Blade Heroicons package.

Installation

Composer

composer require roelmagdaleno/php-heroicons

Usage

You can render a Heroicon using multiple ways:

Helper

Return the SVG by using the heroicon() helper function:

$text = heroicon('check-circle', ['width' => 60]);
echo "<p>My icon is: $text</p>";

Print the SVG directly:

echo heroicon('check-circle', ['width' => 60]);

Constructor

Instantiate an Icon class with parameters and print it directly:

use PHPHeroIcons\Icon;

echo new Icon('check-circle', ['width' => 60]);

Instantiate an Icon class with parameters and call the render() method.

use PHPHeroIcons\Icon;

$icon = new Icon('academic-cap', ['width' => 60]);
$icon->render();

Instantiate an Icon class with parameters and call the return() method.

use PHPHeroIcons\Icon;

$icon = new Icon('academic-cap', ['width' => 60]);
$text = $icon->return();

echo "<p>My icon is: $text</p>";

Render Method

If you want to render multiples icons and only use one Icon instance:

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:

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
  • $type

Example:

heroicon($icon, $attributes, $type);

The $icon accepts any Heroicon 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:

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.

You might also like...
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.

📢 Yell PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects. Requirement

Quick package/plugin/component (repo) lookup for your favourite package managers
Quick package/plugin/component (repo) lookup for your favourite package managers

Package Managers (Download latest release) Package Repo Search Quick package/plugin/component (repo) lookup for your favourite package managers.

Sanitize and escape every values in your PHP Application

PHP Sanitizer Sanitize and escape every values in your PHP Application. This solution will make PHP developer life easy, very easy and developers woul

Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people home in decoration positions and others.

Iran-Decoration Platform Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people

A PHP CLI application that helps you organize your aliases.
A PHP CLI application that helps you organize your aliases.

Alias CLI A PHP CLI application that helps you organize your aliases. Installation composer require --dev alexgaal/alias After installing Alias CLI we

The package contains a bootstrap for running Yii3 console application.
The package contains a bootstrap for running Yii3 console application.

Yii Console Runner The package contains a bootstrap for running Yii3 console application. Requirements PHP 8.0 or higher. Installation The package cou

Package to send customer specific prices to Magento from a Laravel application using a configurable source.

Laravel Magento Customer Prices This package provides a way to add customer specific prices to Magento from a Laravel app. By default, it uses the Mag

Package to send prices to Magento from a Laravel application using a configurable source.

Laravel Magento Prices Package to send prices to Magento from a Laravel application using a configurable source. Features The idea is that we want to

churn-php is a package that helps you identify php files in your project that could be good candidates for refactoring
churn-php is a package that helps you identify php files in your project that could be good candidates for refactoring

churn-php Helps discover good candidates for refactoring. Table of Contents What Is it? Compatibility How to Install? How to Use? How to Configure? Si

Releases(v1.0.0)
Owner
Roel Magdaleno
Computer Engineer. WordPress Developer. Using PHP, Laravel, JS & Vue.js. Currently working at @wpbullet
Roel Magdaleno
A package to render form fields in WordPress settings pages.

WP Settings Page Fields A package to render form fields in WordPress settings pages. You might need a settings page with a form and its fields and you

Roel Magdaleno 5 Jul 22, 2022
PDF API. JSON to PDF. PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data

PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data PDF ENGINE VERSION: development: This is a prerelease version

Ajous Solutions 2 Dec 30, 2022
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Ry-Zen 7 Aug 21, 2022
salah eddine bendyab 18 Aug 17, 2021
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Give our package a Star to support us ⭐ ?? Inst

Binshops 279 Dec 28, 2022
Integrate your PHP application with your HTTP caching proxy

FOSHttpCache Introduction This library integrates your PHP applications with HTTP caching proxies such as Varnish. Use this library to send invalidati

FriendsOfSymfony 338 Dec 8, 2022
This package makes it easy to add early access mode to your existing application.

This package makes it easy to add early access mode to your existing application. This is useful for when you want to launch a product and need to gat

Neo 174 Nov 26, 2022
The Workflow Package add Drag & Drop Workflows to your Laravel Application.

Workflows add Drag & Drop automation's to your Laravel application. The Workflow Package adds Drag & Drop Workflows to your Laravel Application. A Wor

42coders 196 Dec 29, 2022
This plugin can be embedded in PHP application to give the web application specific routes/href

Routes Plugin PHP This plugin can be embedded in PHP application to give the web application specific routes/href location and for entering specific/l

Ifechukwudeni Oweh 7 Jul 17, 2022