Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit bb4dd7a

Browse files
author
Nate Wiebe
authored
Merge pull request #47 from Pixelrobin/updated-docs
Updated docs
2 parents f1a3962 + e6a7d4f commit bb4dd7a

File tree

2 files changed

+52
-120
lines changed

2 files changed

+52
-120
lines changed

README.md

Lines changed: 38 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -4,165 +4,83 @@ PHP Library for [Feather](https://feathericons.com/).
44

55
For more information on Feather itself, please refer to their [README](https://github.com/feathericons/feather).
66

7-
This project is still pretty young, and I'm still a little new to PHP. Suggestions are welcome!
7+
## Installation
88

9-
## Installing
9+
Install `php-feather` using [Composer](https://getcomposer.org/).
1010

11-
php-feather uses [Composer](https://getcomposer.org/). Run the following to install it.
12-
13-
```
11+
```bash
1412
composer require pixelrobin/php-feather
1513
```
1614

17-
If you want to install composer without all the tests and nodejs stuff, use `--prefer-dist`.
18-
19-
```
20-
composer require pixelrobin/php-feather --prefer-dist
21-
```
22-
23-
Then, don't forget to autoload your Composer packages!
24-
25-
```php
26-
require 'vendor/autoload.php';
27-
```
28-
2915
## Usage
3016

31-
### Get an icon
17+
### Icons
18+
19+
`Icons` are retrieved from an `IconManager`.
3220

3321
```php
3422
<?php
35-
require 'vendor/autoload.php';
36-
$icons = new Feather\Icons();
23+
$icons = new \Feather\IconManager();
3724
?>
3825

39-
<!-- Display the 'anchor' icon !-->
40-
<?php echo $icons->get('feather'); ?>
26+
<!-- Display the 'anchor' icon -->
27+
<?php echo $icons->getIcon('anchor'); ?>
4128

42-
<!-- Get creative! !-->
43-
<button class="icon-button">Learn More <?php echo $icons->get('arrow-right'); ?></button>
29+
<!-- Get creative! -->
30+
<button class="icon-button">
31+
Learn More <?= $icons->getIcon('arrow-right'); ?>
32+
</button>
4433
```
4534

46-
### Get an icon with modified properties
47-
48-
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.
49-
50-
```php
51-
$icons->get('feather', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-label' => 'Battery icon'));
52-
// <svg ... class="feather feather-feather fooclass", stroke-width="1", aria-label="Battery icon" ... >...</svg>
53-
```
54-
55-
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 attributes in the
56-
class by default.
35+
`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.
5736

5837
```php
59-
$icons->setAttributes(array(
60-
'color' => 'red',
61-
'stroke-width' => 3
62-
));
63-
64-
$icons->get('mail');
65-
// <svg ... color="red" stroke-width="3" ... >...</svg>
38+
$icons->getIcon('anchor'); // Returns an Icon object
39+
$html = $icons->getIcon('anchor')->render(); // Returns the icon's html
40+
echo $icons->getIcon('anchor'); // Outputs the icon's html, since it is cast as a string
6641
```
42+
### Attributes
6743

68-
## API
44+
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.
6945

70-
### `Feather\Icons`
71-
72-
Usage:
46+
Attribute changes on the `IconManager` will affect all `Icon` objects created by the `IconManager`. Changes on `Icon` objects will only affect the individual icons.
7347

7448
```php
75-
$icons = new Feather\Icons();
76-
```
77-
78-
<br>
49+
// Use on the IconManager instance to set default attributes for all icons
50+
$icons->setAttributes(['stroke' => '#fff', 'stroke-width' => 2]);
51+
$icons->setAttribute('stroke', '#fff');
7952

80-
### `Feather\Icons->get($name, $attributes = array())`
53+
$icons->setSize(24);
54+
$icons->setColor('#fff');
55+
$icons->setWeight(2);
56+
$icons->addCssClass('foo');
8157

82-
Gets an icon as a string. Attributes passed will be merged over the class defaults.
83-
84-
```php
85-
$icons = new Feather\Icons();
86-
87-
// Get an icon
88-
echo $icons->get('anchor');
89-
// <svg ... >...</svg>
90-
91-
// Get an icon with modified properties
92-
echo $icons->get('battery', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-label' => 'Battery icon'));
93-
// <svg ... class="feather feather-battery fooclass", stroke-width="1", aria-label="Battery icon" ... >...</svg>
58+
// Or use on a single icon to only affect that one
59+
echo $icons->getIcon('alert-triangle')->setColor('red')->setAttribute('data-alert', 'true');
9460
```
9561

96-
#### Arguments
97-
98-
|Argument |Type |Description |
99-
|------------|-------|---------------------------------------------------------------------------------|
100-
|$name |string |The name of the icon. A full list can be found [here](https://feathericons.com/).|
101-
|$attributes?|array |Attributes to modify/add (see 'Usage' above for example) |
62+
### Accessibility
10263

103-
<br>
104-
105-
### `Feather\Icons->setAttributes($attributes, $merge = true)`
106-
107-
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 attributes in the class. You can
108-
disable this by setting the `$merge` argument to false, but only do it if you know what you are doing.
64+
When getting an `Icon`, alt text can be passed as an argument or can be set on the `Icon` at a later time.
10965

11066
```php
111-
$icons = new Feather\Icons();
112-
113-
// Set some default attributes (this will be merged with the current defaults in the class)
114-
$icons->setAttributes(array('color' => 'red', 'stroke-width' => 3));
67+
$icons->getIcon('anchor', [], 'Icon of an anchor');
11568

116-
// Now they will be included with every icon
117-
$icons->get('delete');
118-
// <svg ... color="red" stroke-width="1" ... >...</svg>
69+
$icon->setAltText('Icon of an anchor');
11970
```
12071

121-
#### Arguments
72+
### Aliases
12273

123-
|Argument |Type |Description |
124-
|-----------|-------|---------------------------------------------------------------------------|
125-
|$attributes|array |Attributes to add |
126-
|$merge? |boolean|Whether to merge with the current attributes (true) or replace them (false)|
127-
128-
<br>
129-
130-
### `Feather\Icons->getAttributes()`
131-
132-
Get the current attributes for the class. To set it, use the `setAttributes()` method;
74+
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
75+
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`.
13376

13477
```php
135-
$icons = new Feather\Icons();
136-
137-
$attrs = $icons->getAttributes();
138-
```
139-
140-
<br>
141-
142-
### `Feather\DEFAULT_ATTRIBUTES`
143-
144-
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.
145-
146-
```php
147-
$icons = new Feather\Icons();
148-
149-
// Add/modify some default attributes
150-
$icons->setAttributes( ... );
151-
152-
// ... do some stuff ...
153-
154-
// Now say you want to reset the attributes you modified to the default...
155-
// Set merge to false to overwrite instead of merge the arrays
156-
$icons->setAttributes(Feather\DEFAULT_ATTRIBUTES, false);
78+
$icons->addAlias('close-button', 'x');
15779
```
15880

15981
## Contributing
16082

161-
Feel free to open up issues and PRs for suggesstions.
162-
163-
Developing requires both nodejs and composer. The icons are included as a node module and built for use in php.
164-
165-
Better contributing docs are coming soon!
83+
Feel free to open up issues and PRs for suggestions.
16684

16785
## License
16886

UPGRADE-2.0.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# UPGRADE FROM 1.x to 2.0
2+
3+
## PHP version support
4+
5+
- Support for PHP < 7.4 was dropped
6+
7+
## Classes
8+
9+
- `Feather\Icons` was renamed to `Feather\IconManager`
10+
11+
## Icons
12+
13+
- `Feather\Icons::get()` was renamed to `Feather\IconManager::getIcon()`
14+
- `Feather\Icon` objects are returned by `Feather\IconManager::getIcon()` instead of a `string`

0 commit comments

Comments
 (0)