pixelrobin / php-feather
PHP library for feather icons
Installs: 41 598
Dependents: 4
Suggesters: 0
Security: 0
Stars: 47
Watchers: 6
Forks: 8
Open Issues: 1
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-11-26 18:53:46 UTC
README
PHP Library for Feather.
For more information on Feather itself, please refer to their README.
Installation
Install php-feather
using Composer.
composer require pixelrobin/php-feather
Usage
Icons
Icons
are retrieved from an 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()
returns an Icon
object. To render the icon html itself, either cast the Icon
as a string or call its render()
function.
$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
Attributes
Attributes can be modified on both the IconManager
and on Icon
objects. Attributes can be modified directly using the setAttribute(s)
functions or by using the helper functions.
Attribute changes on the IconManager
will affect all Icon
objects created by the IconManager
. Changes on Icon
objects will only affect the individual icons.
// 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');
Accessibility
When getting an Icon
, alt text can be passed as an argument or can be set on the Icon
at a later time.
$icons->getIcon('anchor', [], 'Icon of an anchor'); $icon->setAltText('Icon of an anchor');
Aliases
Aliases can be set to make larger changes across a theme easier, such as replacing the actual icon used for a specific use case. For example, what if for the close button icon, you wanted to switch
from using the x
icon to x-circle
. Instead of having the icon name hardcoded, you could use an alias for the use case and update the value in one place. Aliases are set on the IconManager
.
$icons->addAlias('close-button', 'x');
Contributing
Feel free to open up issues and PRs for suggestions.
License
Licensed under the MIT License.
The icons in this code are from Feather. It is also licensed under the MIT License.