efureev/yii2-fontawesome

此包已被废弃,不再维护。未建议替代包。

为 Yii2 应用程序提供 Font Awesome 资产包

安装: 12

依赖者: 0

建议者: 0

安全性: 0

星星: 0

关注者: 3

分支: 49

开放问题: 1

类型:yii2-extension

2.18.0 2016-09-12 10:29 UTC

README

此扩展为 Yii2 应用程序提供包含 Font Awesome 的资产包,并提供用于使用图标的辅助工具。

有关许可信息,请查看 LICENSE 文件。

License Latest Stable Version Latest Unstable Version Total Downloads

代码状态

Scrutinizer Code Quality Code Coverage Travis CI Build Status

支持

安装

安装此扩展的首选方法是使用 composer

运行以下命令

composer require "efureev/yii2-fontawesome:~2"

或在您的 composer.json 文件的 require 部分中添加

"efureev/yii2-fontawesome": "~2",

使用

在视图中

efureev\fontawesome\AssetBundle::register($this);

或作为主应用程序资产包的依赖项

class AppAsset extends AssetBundle
{
	// ...

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

类参考

命名空间: efureev\fontawesome;

###类 FAFontAwesome

  • static FA::icon($name, $options=[]) - 创建一个可用于 FontAwesome html 图标的 components\Icon
    • $name - Font Awesome 集中图标的名称。
    • $options - 为 i.fa html 标签添加的额外属性。
  • static FA::stack($name, $options=[]) - 创建一个可用于 FontAwesome html 图标的 components\Stack
    • $options - 为 span.fa-stack html 标签添加的额外属性。

###类 components\Icon ($Icon)

  • (string)$Icon - 渲染图标
  • $Icon->render() - 渲染图标
  • $Icon->tag($value) - 为图标设置另一个 html 标签(默认 i
    • $value - 标签名称
  • $Icon->addCssClass($value) - 在 $value 中添加 html 标签的 css 类
    • $value - css 类名称
  • $Icon->inverse() - 在 html 标签的 css 类中添加 fa-inverse
  • $Icon->spin() - 在 html 标签的 css 类中添加 fa-spin
  • $Icon->fixedWidth() - 在 html 标签的 css 类中添加 fa-fw
  • $Icon->ul() - 在 html 标签的 css 类中添加 fa-ul
  • $Icon->li() - 在 html 标签的 css 类中添加 fa-li
  • $Icon->border() - 在 html 标签的 css 类中添加 fa-border
  • $Icon->pullLeft() - 在 html 标签的 css 类中添加 pull-left
  • $Icon->pullRight() - 在 html 标签的 css 类中添加 pull-right
  • $Icon->size($value) - 添加具有大小属性的 html 标签的 css 类
    • $value - 大小值(变体:FA::SIZE_LARGEFA::SIZE_2XFA::SIZE_3XFA::SIZE_4XFA::SIZE_5X
  • $Icon->rotate($value) - 添加具有旋转值的 html 标签的 css 类
    • $value - 旋转值(变体:FA::ROTATE_90FA::ROTATE_180FA::ROTATE_270
  • $Icon->flip($value) - 添加具有翻转值的 html 标签的 css 类
    • $value - 翻转值(变体:FA::FLIP_HORIZONTALFA::FLIP_VERTICAL

###类 components\Stack ($Stack)

  • (string)$Stack - 渲染图标堆栈
  • $Stack->render() - 渲染图标堆栈
  • $Stack->tag($value) - 为图标堆栈设置另一个 html 标签(默认 span
  • $Stack->icon($icon, $options=[]) - 设置堆栈的图标
    • $icon - 图标名称或 component\Icon 对象
    • $options - 为图标 html 标签添加的额外属性。
  • $Stack->icon($icon, $options=[]) - 设置堆栈的背景图标
    • $icon - 图标名称或 component\Icon 对象
    • $options - 为图标 html 标签添加的额外属性。

辅助函数示例

use efureev\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')->ul();         // <i class="fa fa-cog fa-ul"></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('circle', 'Bullet item')
     ->item('check', 'Checked item');
// <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);

设置另一个前缀

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>