rmrevin/yii2-fontawesome Asset Bundle for Yii2 with Font Awesome

fontawesomeassetbundle

Yii 2 Font Awesome Asset Bundle

This extension provides a assets bundle with Font Awesome for Yii framework 2.0 applications and helper to use icons.

For license information check the LICENSE-file.

LicenseLatest Stable VersionLatest Unstable VersionTotal Downloads

Code Status

Scrutinizer Code QualityCode CoverageTravis CI Build StatusDependency Status

Support

Update to 2.17

Be careful in version 2.17 deprecated methods were removed. More in the changelog.

Installation

The preferred way to install this extension is through composer.

Either run

composer require "rmrevin/yii2-fontawesome:~2.17"

or add

"rmrevin/yii2-fontawesome": "~2.17",

to the require section of your composer.json file.

Usage

In view

rmrevin\yii\fontawesome\AssetBundle::register($this);

or as dependency in your main application asset bundle

class AppAsset extends AssetBundle
{
    // ...

    public $depends = [
        // ...
        'rmrevin\yii\fontawesome\AssetBundle'
    ];
}

Class reference

Namespace: rmrevin\yii\fontawesome;

Class FA or FontAwesome

  • static FA::icon($name, $options=[]) - Creates an component\Icon that can be used to FontAwesome html icon
    • $name - name of icon in font awesome set.
    • $options - additional attributes for i.fa html tag.
  • static FA::stack($name, $options=[]) - Creates an component\Stack that can be used to FontAwesome html icon
    • $options - additional attributes for span.fa-stack html tag.

Class component\Icon ($Icon)

  • (string)$Icon - render icon
  • $Icon->render() - DEPRECATED! render icon
  • $Icon->tag($value) - DEPRECATED! set another html tag for icon (default i)
    • $value - name of tag
  • $Icon->addCssClass($value) - add to html tag css class in $value
    • $value - name of css class
  • $Icon->inverse() - add to html tag css class fa-inverse
  • $Icon->spin() - add to html tag css class fa-spin
  • $Icon->fixedWidth() - add to html tag css class fa-fw
  • $Icon->ul() - add to html tag css class fa-ul
  • $Icon->li() - add to html tag css class fa-li
  • $Icon->border() - add to html tag css class fa-border
  • $Icon->pullLeft() - add to html tag css class pull-left
  • $Icon->pullRight() - add to html tag css class pull-right
  • $Icon->size($value) - add to html tag css class with size
    • $value - size value (variants: FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X)
  • $Icon->rotate($value) - add to html tag css class with rotate
    • $value - rotate value (variants: FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270)
  • $Icon->flip($value) - add to html tag css class with rotate
    • $value - flip value (variants: FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL)

Class component\Stack ($Stack)

  • (string)$Stack - render icon stack
  • $Stack->render() - DEPRECATED! render icon stack
  • $Stack->tag($value) - DEPRECATED! set another html tag for icon stack (default span)
  • $Stack->icon($icon, $options=[]) - set icon for stack
    • $icon - name of icon or component\Icon object
    • $options - additional attributes for icon html tag.
  • $Stack->icon($icon, $options=[]) - set background icon for stack
    • $icon - name of icon or component\Icon object
    • $options - additional attributes for icon html tag.

Helper examples

use rmrevin\yii\fontawesome\FA;

// normal use
echo FA::icon('home'); // <i class="fa fa-home"></i>

// shortcut
echo FA::i('home'); // <i class="fa fa-home"></i>

// icon with additional attributes
echo FA::icon(
    'arrow-left', 
    ['class' => 'big', 'data-role' => 'arrow']
); // <i class="big fa fa-arrow-left" data-role="arrow"></i>

// icon in button
echo Html::submitButton(
    Yii::t('app', '{icon} Save', ['icon' => FA::icon('check')])
); // <button type="submit"><i class="fa fa-check"></i> Save</button>

// icon with additional methods
echo FA::icon('cog')->inverse();    // <i class="fa fa-cog fa-inverse"></i>
echo FA::icon('cog')->spin();       // <i class="fa fa-cog fa-spin"></i>
echo FA::icon('cog')->fixedWidth(); // <i class="fa fa-cog fa-fw"></i>
echo FA::icon('cog')->li();         // <i class="fa fa-cog fa-li"></i>
echo FA::icon('cog')->border();     // <i class="fa fa-cog fa-border"></i>
echo FA::icon('cog')->pullLeft();   // <i class="fa fa-cog pull-left"></i>
echo FA::icon('cog')->pullRight();  // <i class="fa fa-cog pull-right"></i>

// icon size
echo FA::icon('cog')->size(FA::SIZE_3X);
// values: FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X
// <i class="fa fa-cog fa-size-3x"></i>

// icon rotate
echo FA::icon('cog')->rotate(FA::ROTATE_90); 
// values: FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_180
// <i class="fa fa-cog fa-rotate-90"></i>

// icon flip
echo FA::icon('cog')->flip(FA::FLIP_VERTICAL); 
// values: FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL
// <i class="fa fa-cog fa-flip-vertical"></i>

// icon with multiple methods
echo FA::icon('cog')
        ->spin()
        ->fixedWidth()
        ->pullLeft()
        ->size(FA::SIZE_LARGE);
// <i class="fa fa-cog fa-spin fa-fw pull-left fa-size-lg"></i>

// icons stack
echo FA::stack()
        ->icon('twitter')
        ->on('square-o');
// <span class="fa-stack">
//   <i class="fa fa-square-o fa-stack-2x"></i>
//   <i class="fa fa-twitter fa-stack-1x"></i>
// </span>

// icons stack with additional attributes
echo FA::stack(['data-role' => 'stacked-icon'])
     ->on(FA::Icon('square')->inverse())
     ->icon(FA::Icon('cog')->spin());
// <span class="fa-stack" data-role="stacked-icon">
//   <i class="fa fa-square-o fa-inverse fa-stack-2x"></i>
//   <i class="fa fa-cog fa-spin fa-stack-1x"></i>
// </span>

// unordered list icons 
echo FA::ul(['data-role' => 'unordered-list'])
     ->item('Bullet item', ['icon' => 'circle'])
     ->item('Checked item', ['icon' => 'check']);
// <ul class="fa-ul" data-role="unordered-list">
//   <li><i class="fa fa-circle fa-li"></i>Bullet item</li>
//   <li><i class="fa fa-check fa-li"></i>Checked Item</li>
// </span>

// autocomplete icons name in IDE
echo FA::icon(FA::_COG);
echo FA::icon(FA::_DESKTOP);
echo FA::stack()
     ->on(FA::_CIRCLE_O)
     ->icon(FA::_TWITTER);

Set another prefix

FA::$cssPrefix = 'awf';

echo FA::icon('home');
// <i class="awf awf-home"></i>
echo FA::icon('cog')->inverse();
// <i class="awf awf-cog awf-inverse"></i>

Changelog

2017-01-11 - 2.17.1

  • Downgrade minimum php to 5.4

2016-10-25 - 2.17.0

  • Font Awesome updated to version 4.7.
  • Update minimum php to 5.5
  • These deprecated classes are now removed:
    • rmrevin\yii\fontawesome\CDNAssetBundle
  • These deprecated methods are now removed:
    • rmrevin\yii\fontawesome\component\Icon::ul
    • rmrevin\yii\fontawesome\component\Icon::fixed_width
    • rmrevin\yii\fontawesome\component\Icon::pull_left
    • rmrevin\yii\fontawesome\component\Icon::pull_right
  • In method rmrevin\yii\fontawesome\component\UnorderedList::item changed interface (removed $icon param).
  • These directories are now deprecated:
    • ./assets
  • These fields and methods are now deprecated:
    • rmrevin\yii\fontawesome\component\Icon::$defaultTag
    • rmrevin\yii\fontawesome\component\Icon::$tag
    • rmrevin\yii\fontawesome\component\Icon::tag()
    • rmrevin\yii\fontawesome\component\Icon::render()
    • rmrevin\yii\fontawesome\component\Stack::$defaultTag
    • rmrevin\yii\fontawesome\component\Stack::$tag
    • rmrevin\yii\fontawesome\component\Stack::tag()
    • rmrevin\yii\fontawesome\component\Stack::render()
    • rmrevin\yii\fontawesome\component\UnorderedList::$defaultTag
    • rmrevin\yii\fontawesome\component\UnorderedList::$tag
    • rmrevin\yii\fontawesome\component\UnorderedList::tag()
    • rmrevin\yii\fontawesome\component\UnorderedList::render()
  • Refactoring class rmrevin\yii\fontawesome\component\UnorderedList.

2016-08-31 - 2.16.1

  • Fix options in li item.
  • Update readme.

2016-08-31 - 2.16.0

  • Enh #22: Added FA:ul() method.
  • Refactoring.

2016-08-19 - 2.15.2

  • Update icon name constants to version 4.6.3.

2016-05-29 - 2.15.1

  • Added option to skip the icon.
  • Added option to change the order of icons in the stack.

2016-05-22 - 2.15.0

  • Remove bower package.

2016-04-16 - 2.14.0

  • Font Awesome updated to version 4.6.

2015-11-26 - 2.13.0

  • Font Awesome updated to version 4.5.

2015-11-20 - 2.12.2

  • Add shortcuts methods i() for FA::icon() and FA::s() for FA::stack()
  • Update readme

2015-11-09 - 2.12.1

  • Variable FA::$cssPrefix transferred to the class FontAwesome.
  • Refactoring.
  • Update tests.

2015-08-15 - 2.12.0

  • Font Awesome updated to version 4.4.

2015-06-29 - 2.11.0

  • Added the ability to change the tag for icons.

2015-06-23 - 2.10.3

  • Change cnd url to cloudflare.

2015-06-19 - 2.10.2

  • CDNAssetBundle is now deprecated. Use rmrevin\yii\fontawesome\cdn\AssetBundle.
  • Refactoring.

2015-05-09 - 2.10.1

  • Fix bug in tests.

2015-05-09 - 2.10.0

  • Add CDN asset bundle CDNAssetBundle.
  • Composer package fortawesome/font-awesome replaced on bower package bower-asset/fontawesome.
  • Adding warning messages in deprecated methods.
  • Add changelog.
  • Refactoring.
  • Update readme.

2015-04-28 - 2.9.2

  • Method icon()->fixed_width() is deprecated. Use instead icon()->fixedWidth().
  • Method icon()->pull_left() is deprecated. Use instead icon()->pullLeft().
  • Method icon()->pull_right() is deprecated. Use instead icon()->pullRight().
  • Updated tests.

2015-04-08 - 2.9.1

  • Fix asset bundle publish bug on windows.

2015-03-31 - 2.9.0

  • In asset bundle added init method for filtering publising assets.

2015-03-17 - 2.8.2

  • Refactoring.

2015-03-16 - 2.8.1

  • Update readme.

2015-03-16 - 2.8.0

  • In class FA add static property cssPrefix for customizing css class.
  • Refactoring.
  • Update readme.

2015-02-08 - 2.7.1

  • Update travisCI config.

2015-01-26 - 2.7.0

  • Font Awesome updated to version 4.3.
  • Update icons constants list.
  • Update readme.

Until 2015-03-04

  • Implementation of extension.

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



2.17.1 is the latest of 49 releases



MIT license
Stats
99 github stars & 29 github forks
637 downloads in the last day
15810 downloads in the last 30 days
230786 total downloads