Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement enums #1

Merged
merged 8 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/*.md export-ignore
/composer.json export-ignore
/composer.lock export-ignore
/rector.php export-ignore
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
coverage.xml
coverage/
vendor/
composer.lock
138 changes: 55 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# FontAwesome PHP Helper

![PHP](https://img.shields.io/badge/PHP-^8.0-blue.svg?style=flat)
![PHP](https://img.shields.io/badge/PHP-^8.1-blue.svg?style=flat)
![Coverage](https://badgen.net/coveralls/c/github/dragomano/fa-php-helper/main)

[По-русски](README.ru.md)

## Description

This package is designed to generate HTML code for FontAwesome 6 icons. In addition, the following features are available:
This package is designed to generate CSS classes and HTML code for FontAwesome 6 icons. In addition, the following features are available:

- add icon colors
- resize icons
- support for both modern (`fa-solid fa-`) and deprecated (`fas fa-`) classes.
- use fixed width icons (`fa-fw`) to display in lists
- optionally add the `aria-hidden="true"` attribute to hide icons from screen readers, etc.
- get random icons
- get CSS class of a random icon
- collection of CSS classes of all icons

## Installation

Expand All @@ -24,115 +25,86 @@ composer require bugo/fa-php-helper

## Using

```php
<?php declare(strict_types=1);
If only CSS classes are needed:

use Bugo\FontAwesomeHelper\Styles\SolidIcon;
use Bugo\FontAwesomeHelper\Styles\RegularIcon;
use Bugo\FontAwesomeHelper\Styles\BrandIcon;
```php
<?php

$solidIcon = new SolidIcon();
$regularIcon = new RegularIcon();
$brandIcon = new BrandIcon();
use Bugo\FontAwesome\Enums\Icon;

// 'fa-solid fa-user'
echo $solidIcon->get('user');

// '<i class="fa-solid fa-user"></i>'
echo $solidIcon->html('user');

// '<i class="fa-regular fa-calendar" title="Calendar"></i>
echo $regularIcon->html('calendar', 'Calendar');
echo Icon::V6->solid('user');

// '<i class="fa-regular fa-copy fa-2xl"></i>'
echo $regularIcon->size('2xl')->html('copy');
// 'fa-regular fa-user'
echo Icon::V6->regular('user');

// '<i class="fa-brands fa-apple" style="color: red"></i>'
echo $brandIcon->color('red')->html('apple');
// 'fa-brands fa-windows'
echo Icon::V6->brand('windows');
```

Adding a fixed width for display in lists:
Advanced example:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Styles\SolidIcon;

$solidIcon = new SolidIcon();
$solidIcon->useFixedWidth();

// '<i class="fa-solid fa-user fa-fw"></i>'
echo $solidIcon->html('user');
<?php

use Bugo\FontAwesome\Enums\Icon;

$icon = Icon::V5->brand('windows');

// 'fab fa-windows fa-fw text-red-500'
var_dump(
$icon
->fixedWidth()
->color('text-red-500')
->text()
);

$icon = Icon::V6->solid('user');

// '<i class="fa-solid fa-user fa-2xl" style="color:red" title="Пользователь" aria-hidden="true"></i>'
var_dump(
$icon
->color('red')
->size('2xl')
->title('Пользователь')
->ariaHidden()
->html()
);
```

Adding an attribute `aria-hidden="true"`:
Additional classes can be passed through the `addClass` method:

```php
<?php declare(strict_types=1);
<?php

use Bugo\FontAwesomeHelper\Styles\SolidIcon;

$solidIcon = new SolidIcon();
$solidIcon->useAriaHidden();

// '<i class="fa-solid fa-user" aria-hidden="true"></i>'
echo $solidIcon->html('user');
```

It is convenient to pass additional classes via `extra` method:

```php
<?php declare(strict_types=1);
use Bugo\FontAwesome\Enums\Icon;

use Bugo\FontAwesomeHelper\Styles\SolidIcon;

$solidIcon = new SolidIcon();
$icon = Icon::V6->solid('heart');

// '<i class="fa-solid fa-heart fa-beat"></i>'
echo $solidIcon->extra('fa-beat')->html('heart');
var_dump(
$icon
->addClass('fa-beat')
->html()
);
```

You can also get a random icon:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Styles\BrandIcon;

$brandIcon = new BrandIcon();

echo $brandIcon->random();
```

And so you can get the whole collection at once:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Collections\Collection;
<?php

$collection = new Collection();
use Bugo\FontAwesome\Enums\Icon;

echo $collection->getAll();
var_dump(Icon::V6->random());
```

An alternative way to work with icons via factories:
And so you can get the whole collection with all CSS classes at once:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Factories\IconFactoryCreator;

$iconFactoryCreator = new IconFactoryCreator();
$iconSolidFactory = $iconFactoryCreator::createFactory('solid');
$solidIcon = $iconSolidFactory->createIcon();

// '<i class="fa-solid fa-heart"></i>'
echo $solidIcon->html('heart');
<?php

$iconOldSolidFactory = $iconFactoryCreator::createFactory('old_solid');
$oldSolidIcon = $iconOldSolidFactory->createIcon();
use Bugo\FontAwesome\Enums\Icon;

// '<i class="fas fa-heart"></i>'
echo $oldSolidIcon->html('heart');
var_dump(Icon::V6->collection());
```
138 changes: 55 additions & 83 deletions README.ru.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# FontAwesome PHP Helper

![PHP](https://img.shields.io/badge/PHP-^8.0-blue.svg?style=flat)
![PHP](https://img.shields.io/badge/PHP-^8.1-blue.svg?style=flat)
![Coverage](https://badgen.net/coveralls/c/github/dragomano/fa-php-helper/main)

[English](README.md)

## Описание

Пакет предназначен для генерации HTML-кода иконок FontAwesome 6. Кроме того, доступны следующие функции:
Пакет предназначен для генерации CSS-классов и HTML-кода иконок FontAwesome 6. Кроме того, доступны следующие функции:

- добавление цвета иконок
- изменение размера иконок
- поддержка как современных (`fa-solid fa-`), так и устаревших классов (`fas fa-`)
- использование фиксированной ширины иконок (`fa-fw`) для отображения в списках
- опциональное добавление атрибута `aria-hidden="true"` для скрытия иконок от программ чтения с экрана и т. п.
- получение случайной иконки
- получение CSS-класса случайной иконки
- коллекция CSS-классов всех иконок

## Установка

Expand All @@ -24,115 +25,86 @@ composer require bugo/fa-php-helper

## Использование

```php
<?php declare(strict_types=1);
Если нужны только классы:

use Bugo\FontAwesomeHelper\Styles\SolidIcon;
use Bugo\FontAwesomeHelper\Styles\RegularIcon;
use Bugo\FontAwesomeHelper\Styles\BrandIcon;
```php
<?php

$solidIcon = new SolidIcon();
$regularIcon = new RegularIcon();
$brandIcon = new BrandIcon();
use Bugo\FontAwesome\Enums\Icon;

// 'fa-solid fa-user'
echo $solidIcon->get('user');

// '<i class="fa-solid fa-user"></i>'
echo $solidIcon->html('user');

// '<i class="fa-regular fa-calendar" title="Календарь"></i>
echo $regularIcon->html('calendar', 'Календарь');
echo Icon::V6->solid('user');

// '<i class="fa-regular fa-copy fa-2xl"></i>'
echo $regularIcon->size('2xl')->html('copy');
// 'fa-regular fa-user'
echo Icon::V6->regular('user');

// '<i class="fa-brands fa-apple" style="color: red"></i>'
echo $brandIcon->color('red')->html('apple');
// 'fa-brands fa-windows'
echo Icon::V6->brand('windows');
```

Добавление фиксированной ширины для отображения в списках:
Расширенный пример:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Styles\SolidIcon;

$solidIcon = new SolidIcon();
$solidIcon->useFixedWidth();

// '<i class="fa-solid fa-user fa-fw"></i>'
echo $solidIcon->html('user');
<?php

use Bugo\FontAwesome\Enums\Icon;

$icon = Icon::V5->brand('windows');

// 'fab fa-windows fa-fw text-red-500'
var_dump(
$icon
->fixedWidth()
->color('text-red-500')
->text()
);

$icon = Icon::V6->solid('user');

// '<i class="fa-solid fa-user fa-2xl" style="color:red" title="Пользователь" aria-hidden="true"></i>'
var_dump(
$icon
->color('red')
->size('2xl')
->title('Пользователь')
->ariaHidden()
->html()
);
```

Добавление атрибута `aria-hidden="true"`:
Дополнительные классы можно передать через метод `addClass`:

```php
<?php declare(strict_types=1);
<?php

use Bugo\FontAwesomeHelper\Styles\SolidIcon;

$solidIcon = new SolidIcon();
$solidIcon->useAriaHidden();

// '<i class="fa-solid fa-user" aria-hidden="true"></i>'
echo $solidIcon->html('user');
```

А дополнительные классы удобно передавать через метод `extra`:

```php
<?php declare(strict_types=1);
use Bugo\FontAwesome\Enums\Icon;

use Bugo\FontAwesomeHelper\Styles\SolidIcon;

$solidIcon = new SolidIcon();
$icon = Icon::V6->solid('heart');

// '<i class="fa-solid fa-heart fa-beat"></i>'
echo $solidIcon->extra('fa-beat')->html('heart');
var_dump(
$icon
->addClass('fa-beat')
->html()
);
```

Кроме того, доступно получение случайной иконки:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Styles\BrandIcon;

$brandIcon = new BrandIcon();

echo $brandIcon->random();
```

А так можно получить всю коллекцию сразу:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Collections\Collection;
<?php

$collection = new Collection();
use Bugo\FontAwesome\Enums\Icon;

echo $collection->getAll();
var_dump(Icon::V6->random());
```

Альтернативный способ работы с иконками через фабрики:
А так можно получить всю коллекцию со всеми классами сразу:

```php
<?php declare(strict_types=1);

use Bugo\FontAwesomeHelper\Factories\IconFactoryCreator;

$iconFactoryCreator = new IconFactoryCreator();
$iconSolidFactory = $iconFactoryCreator::createFactory('solid');
$solidIcon = $iconSolidFactory->createIcon();

// '<i class="fa-solid fa-heart"></i>'
echo $solidIcon->html('heart');
<?php

$iconOldSolidFactory = $iconFactoryCreator::createFactory('old_solid');
$oldSolidIcon = $iconOldSolidFactory->createIcon();
use Bugo\FontAwesome\Enums\Icon;

// '<i class="fas fa-heart"></i>'
echo $oldSolidIcon->html('heart');
var_dump(Icon::V6->collection());
```
Loading
Loading