natewiebe13/php-lucide

PHP库,用于Lucide图标


README

PHP库,用于Lucide

有关Lucide本身的更多信息,请参阅他们的README

安装

使用Composer安装php-lucide

composer require natewiebe13/php-lucide

版本控制

此库使用语义版本控制作为版本控制策略。这涵盖了公共API,但不保证与Lucide(例如,图标名称更改)所做的破坏性更改的向后兼容性。Lucide可能做出的任何大型向后兼容性中断可能会导致此库的新主要版本,但将根据具体情况确定。如果发生图标名称更改,可以使用别名功能来协助迁移到新的图标名称。

使用方法

图标

图标IconManager获取。

<?php
$icons = new \Lucide\IconManager();
?>

<!-- Display the 'anchor' icon -->
<?php echo $icons->getIcon('anchor'); ?>

<!-- Get creative! -->
<button class="icon-button">
    Learn More <?= $icons->getIcon('arrow-right'); ?>
</button>

Lucide\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

属性

可以在IconManagerIcon对象上修改属性。可以使用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上。

$icons->getIcon('anchor', [], 'Icon of an anchor');

$icon->setAltText('Icon of an anchor');

别名

可以设置别名,以便在主题中更容易进行较大范围的更改,例如替换特定用例实际使用的图标。例如,如果想要将关闭按钮图标从使用x图标切换到x-circle图标,而不是将图标名称硬编码,可以使用用例的别名并在一个地方更新值。别名在IconManager上设置。

$icons->addAlias('close-button', 'x');

贡献

请随意提出问题和PR建议。

许可证

MIT许可证下授权。

此代码中的图标来自Lucide。它根据ISC许可证授权。