pixelrobin / php-feather
PHP 库用于 feather 图标
v2.0.0
2022-04-06 13:33 UTC
Requires
- php: >=7.4
Requires (Dev)
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-simplexml: *
- npm-asset/feather-icons: >=4.28
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-08-26 18:24:05 UTC
README
PHP 库用于 Feather 图标。
有关 Feather 本身的更多信息,请参阅他们的 README。
安装
使用 Composer 安装 php-feather
。
composer require pixelrobin/php-feather
用法
图标
图标
通过 IconManager
获取。
<?php $icons = new \Feather\IconManager(); ?> <!-- Display the 'anchor' icon --> <?php echo $icons->getIcon('anchor'); ?> <!-- Get creative! --> <button class="icon-button"> Learn More <?= $icons->getIcon('arrow-right'); ?> </button>
Feather\IconManager::getIcon()
返回一个 Icon
对象。要渲染图标本身的 HTML,可以将 Icon
强制转换为字符串或调用其 render()
函数。
$icons->getIcon('anchor'); // Returns an Icon object $html = $icons->getIcon('anchor')->render(); // Returns the icon's html echo $icons->getIcon('anchor'); // Outputs the icon's html, since it is cast as a string
属性
可以在 IconManager
和 Icon
对象上修改属性。可以使用 setAttribute(s)
函数或使用辅助函数直接修改属性。
在 IconManager
上的属性更改将影响由 IconManager
创建的所有 Icon
对象。对 Icon
对象的更改将仅影响单个图标。
// Use on the IconManager instance to set default attributes for all icons $icons->setAttributes(['stroke' => '#fff', 'stroke-width' => 2]); $icons->setAttribute('stroke', '#fff'); $icons->setSize(24); $icons->setColor('#fff'); $icons->setWeight(2); $icons->addCssClass('foo'); // Or use on a single icon to only affect that one echo $icons->getIcon('alert-triangle')->setColor('red')->setAttribute('data-alert', 'true');
可访问性
获取 Icon
时,可以将 alt 文本作为参数传递,也可以在稍后设置 Icon
上的 alt 文本。
$icons->getIcon('anchor', [], 'Icon of an anchor'); $icon->setAltText('Icon of an anchor');
别名
可以设置别名以使主题中的大型更改更容易,例如替换特定用例中使用的实际图标。例如,如果您想将关闭按钮图标从使用 x
图标更改为 x-circle
,而不是将图标名称硬编码,您可以使用用例的别名并更新一个地方的价值。别名在 IconManager
上设置。
$icons->addAlias('close-button', 'x');
贡献
请随时打开问题并提交 PR 以提出建议。
许可协议
根据 MIT 许可协议 许可。