Giter VIP home page Giter VIP logo

yii2-icons's Introduction

yii2-icons

Latest Stable Version License Total Downloads Monthly Downloads Daily Downloads

This extension offers an easy method to setup various icon frameworks to work with Yii Framework 2.0. Most popular and free icon frameworks available are currently supported. This list may be extended in future based on demand and feedback.

  1. Bootstrap Glyphicons
  2. Font Awesome
  3. Unicode Icons: A collection of unicode symbols made available as CSS icons by Krajee
  4. Elusive Icons
  5. Typicons
  6. Web Hosting Hub Glyphs
  7. JQuery UI Icons
  8. Socicon Icons: Needs you to add attribution to the icon source.
  9. Octicons: The Github icons collection.
  10. Flag-Icons
  11. Open Iconic Icons

Demo

You can see a demonstration here on usage of this extension with documentation and examples.

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Either run

$ php composer.phar require kartik-v/yii2-icons "@dev"

or add

"kartik-v/yii2-icons": "@dev"

to the require section of your composer.json file.

Usage

Global Setup

In case you wish to setup one Icon framework globally, set the parameter icon-framework in the params array of your Yii Configuration File.

'params' => [
  'icon-framework' => 'fa',  // Font Awesome Icon framework
]

To initialize the globally setup framework in your view, call this code in your view or view layout file.

use kartik\icons\Icon;
Icon::map($this);  

Per View Setup

You can also call each icon-framework individually in your view or view layout like below. Map any icon framework within each view as in the example below.

use kartik\icons\Icon;
Icon::map($this, Icon::EL); // Maps the Elusive icon font framework

Displaying Icons

After mapping your icon framework with one of the options above, you can display icons using Icon::show method. Icons can be displayed using one of the options below:

use kartik\icons\Icon;

// Option 1: Uses the `icon-framework` setup in Yii config params. 
echo Icon::show('user'); 

// Option 2: Specific Icon Call in a view. Additional options can also be passed to style the icon.
echo Icon::show('user', ['class'=>'fa-2x'], Icon::FA); 

NOTE: The kartik\icons\Icon::show method outputs a HTML formatted text. So in order to display icons in Yii-2 components like Navbar or Nav, you must set encodeLabels to false.

$items = [
    ['label' => Icon::show('home') . 'Home', 'url' => ['/site/index']],
];

// Your other code

/* Note you must encodeLabels to false to display icons in labels */
echo \yii\bootstrap\Nav::widget([
    'items' => $items,
    'encodeLabels' => false
]);

// Your other code

Displaying Stacked Icons

You can also display stacked icons for frameworks like Font Awesome, where this is supported. For example:

use kartik\icons\Icon;
// fa-twitter on fa-square-o
Icon::showStack('square-o', 'twitter', ['class'=>'fa-lg']);

// fa-flag on fa-circle
Icon::showStack('circle', 'flag', ['class'=>'fa-lg'], ['class'=>'fa-inverse']);

Add Custom Icons

You can add custom icon sets to the list of available frameworks.

use kartik\icons\Icon;
// add framework
Icon::addFramework('custom', [
    'class' => '\common\icons\CustomIconAsset',
    'prefix' => 'custom-icon',
]);

// map to view file
Icon::map($this, 'custom');

// show the icon
echo Icon::show('menu',[], 'custom');
namespace common\icons;
class CustomIconAsset extends \yii\web\AssetBundle
{
    public $sourcePath = '@common/icons/assets/custom';
    public $depends = array(
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset'
    );
    public $css=[
        'css/animation.css',
        'css/custom-codes.css',
        'css/custom-embedded.css',
        'css/custom-ie7.css',
        'css/custom-ie7-codes.css',
        'css/custom.css',
    ];
}

The above asset bundle uses files genereted by http://fontello.com/.

License

yii2-icons is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

yii2-icons's People

Contributors

kartik-v avatar derekisbusy avatar davidsonalencar avatar bupy7 avatar

Watchers

James Cloos avatar Yannick Nascimento avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.