roelmagdaleno / php-heroicons
从PHP渲染Heroicons。
1.0.0
2021-07-28 03:41 UTC
Requires
- php: ^7.2
- meyfa/php-svg: ^0.11.2
README
一个用于在PHP应用程序中渲染Heroicons的包。
在heroicons.com预览图标,由Steve Schoger和Adam Wathan开发。
如果您想在Laravel Blade视图中渲染Heroicons,请使用Blade Heroicons包。
安装
Composer
composer require roelmagdaleno/php-heroicons
用法
您可以使用多种方式渲染Heroicon
助手
使用heroicon()
助手函数返回SVG
$text = heroicon('check-circle', ['width' => 60]); echo "<p>My icon is: $text</p>";
直接打印SVG
echo heroicon('check-circle', ['width' => 60]);
构造函数
使用参数实例化一个Icon
类并直接打印
use PHPHeroIcons\Icon; echo new Icon('check-circle', ['width' => 60]);
使用参数实例化一个Icon
类并调用render()
方法。
use PHPHeroIcons\Icon; $icon = new Icon('academic-cap', ['width' => 60]); $icon->render();
使用参数实例化一个Icon
类并调用return()
方法。
use PHPHeroIcons\Icon; $icon = new Icon('academic-cap', ['width' => 60]); $text = $icon->return(); echo "<p>My icon is: $text</p>";
渲染方法
如果您想渲染多个图标并只使用一个Icon
实例
use PHPHeroIcons\Icon; $icon = new Icon(); $icon->render('check-circle', ['width' => 60]); $icon->render('academic-cap', ['width' => 60]); $icon->render('library', ['width' => 60]);
返回方法
如果您想返回多个图标并只使用一个Icon
实例
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";
参数
Icon
构造函数、heroicon()
、render()
和return()
方法接受以下顺序的属性
- $icon
- $attributes
- $type
示例
heroicon($icon, $attributes, $type);
$icon
接受任何Heroicon缩写,如果您插入一个不存在的图标,它将不会返回任何内容。
对于$attributes
(可选),您可以以数组键/值格式传递以下属性
width
height
class
id
如果您传递的属性不在之前的列表中,它将不会附加到SVG HTML上。
最后,但同样重要的是,您可以指定Heroicon的$type
solid
outline
默认情况下,图标将以solid
类型打印。
示例
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/index.php
文件。