Skip to content
πŸ•Š PHP Library for https://feathericons.com/
Branch: master
Clone or download
Pixelrobin Merge pull request #4 from KubqoA/master
Remove the dot in require statement.
Latest commit 54fe84a Jan 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Remove extraneous line in build.js Oct 29, 2018
icons
src Remove the dot in require statement. Dec 25, 2018
tests Update Feather icons to 4.9.0 Dec 21, 2018
.gitattributes Ignore some files on export Oct 28, 2018
.gitignore
LICENSE Add a LICENSE Oct 28, 2018
README.md v1.0 Oct 31, 2018
composer.json Change name to 'php-feather' Oct 28, 2018
composer.lock Add Composer support Oct 28, 2018
package-lock.json Update Feather icons to 4.9.0 Dec 21, 2018
package.json Update Feather icons to 4.9.0 Dec 21, 2018

README.md

php-feather

PHP Library for Feather.

For more information on Feather itself, please refer to their README.

This project is still pretty young, and I'm still a little new to PHP. Suggestions are welcome!

Installing

php-feather uses Composer. Run the following to install it.

composer require pixelrobin/php-feather

If you want to install composer without all the tests and nodejs stuff, use --prefer-dist.

composer require pixelrobin/php-feather --prefer-dist

Then, don't forget to autoload your Composer packages!

require 'vendor/autoload.php';

Usage

Get an icon

Icons echo by default.

<?php
require 'vendor/autoload.php';
$icons = new Feather\Icons;
?>

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

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

Get an icon with modified properties

Simply pass an array with the attributes you want. This will be merged over the Icons class default attributes, except for class, which gets concatenated to the default classes.

$icons->get('feather', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-label' => 'Battery icon'));
// <svg ... class="feather feather-feather fooclass", stroke-width="1", aria-label="Battery icon" ... >...</svg>

You can also change the default attributes in the Icons class if you want some attributes consistent across multiple get calls. The passed attributes are merged over the current default attributes in the class by default.

$icons->setAttributes(array(
    'color' => 'red',
    'stroke-width' => 3
));

$icons->get('mail');
// <svg ... color="red" stroke-width="3" ... >...</svg>

Get an icon as a string

Set the third argument to false to get a string instead of echoing the icon.

$icon_string = $icons->get('activity', array(), false);
// Then do whatever with $icon_string

API

Feather\Icons

Usage:

$icons = new Feather\Icons;

Feather\Icons->get($name, $attributes = array(), $echo = true)

Gets an icon as svg. Can be echoed (default) or returned as a string. Attributes passed will be merged over the class defaults.

$icons = new Feather\Icons;

// Echo an icon
$icons->get('anchor');
// <svg ... >...</svg>

// Echo an icon with modified properties
$icons->get('battery', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-label' => 'Battery icon'));
// <svg ... class="feather feather-battery fooclass", stroke-width="1", aria-label="Battery icon" ... >...</svg>

// Get an icon as a string without echoing it
$cloud_icon = $icons->get('cloud', array(), false);
doStuffWith($cloud_icon);

Arguments

Argument Type Description
$name string The name of the icon. A full list can be found here.
$attributes? array Attributes to modify/add (see 'Usage' above for example)
$echo? boolean Whether to echo the icon svg (true) or not (false)

Feather\Icons->setAttributes($attributes, $merge = true)

Sets default attributes of the class. These are used as default attributes for the get method. By default, the $attributes argument is merged over the current default attributes in the class. You can disable this by setting the $merge argument to false, but only do it if you know what you are doing.

$icons = new Feather\Icons;

// Set some default attributes (this will be merged with the current defaults in the class)
$icons->setAttributes(array('color' => 'red', 'stroke-width' => 3));

// Now they will be included with every icon
$icons->get('delete');
// <svg ... color="red" stroke-width="1" ... >...</svg>

Arguments

Argument Type Description
$attributes array Attributes to add
$merge? boolean Whether to merge with the current attributes (true) or replace them (false)

Feather\Icons->getAttributes()

Get the current default attributes for the class. To set it, use the setAttributes() method;

$icons = new Feather\Icons;

$attrs = $icons->getAttributes();

Feather\DEFAULT_ATTRIBUTES

Constant array of default attributes. They are applied to every new Icons class. You can use this to reset the attributes of an Icons class.

$icons = new Feather\Icons;

// Add/modify some default attributes
$icons->setAttributes( ... );

// ... do some stuff ...

// Now say you want to reset the attributes you modified to the default...
// Set merge to false to overwrite instead of merge the arrays
$icons->setAttributes(Feather\DEFAULT_ATTRIBUTES, false);

Contributing

Feel free to open up issues and PRs for suggesstions.

Developing requires both nodejs and composer. The icons are included as a node module and built for use in php.

Better contributing docs are coming soon!

License

Licensed under the MIT License.

The icons in this code are from Feather. It is also licensed under the MIT License.

You can’t perform that action at this time.