This commit is contained in:
2020-03-27 10:13:51 +07:00
commit da1024a5b3
16614 changed files with 3274282 additions and 0 deletions

View File

@@ -0,0 +1,233 @@
<?php
/**
* Icon.php
* @author Revin Roman
* @link https://rmrevin.ru
*/
namespace rmrevin\yii\fontawesome\component;
use rmrevin\yii\fontawesome\FA;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Class Icon
* @package rmrevin\yii\fontawesome\component
*/
class Icon
{
/**
* @deprecated
* @var string
*/
public static $defaultTag = 'i';
/**
* @deprecated
* @var string
*/
private $tag;
/**
* @var array
*/
private $options = [];
/**
* @param string $name
* @param array $options
*/
public function __construct($name, $options = [])
{
Html::addCssClass($options, FA::$cssPrefix);
if (!empty($name)) {
Html::addCssClass($options, FA::$cssPrefix . '-' . $name);
}
$this->options = $options;
}
/**
* @return string
*/
public function __toString()
{
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'i');
return Html::tag($tag, null, $options);
}
/**
* @return self
*/
public function inverse()
{
return $this->addCssClass(FA::$cssPrefix . '-inverse');
}
/**
* @return self
*/
public function spin()
{
return $this->addCssClass(FA::$cssPrefix . '-spin');
}
/**
* @return self
*/
public function fixedWidth()
{
return $this->addCssClass(FA::$cssPrefix . '-fw');
}
/**
* @return self
*/
public function li()
{
return $this->addCssClass(FA::$cssPrefix . '-li');
}
/**
* @return self
*/
public function border()
{
return $this->addCssClass(FA::$cssPrefix . '-border');
}
/**
* @return self
*/
public function pullLeft()
{
return $this->addCssClass(FA::$cssPrefix . '-pull-left');
}
/**
* @return self
*/
public function pullRight()
{
return $this->addCssClass(FA::$cssPrefix . '-pull-right');
}
/**
* @param string $value
* @return self
* @throws \yii\base\InvalidConfigException
*/
public function size($value)
{
return $this->addCssClass(
FA::$cssPrefix . '-' . $value,
in_array((string)$value, [FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X], true),
sprintf(
'%s - invalid value. Use one of the constants: %s.',
'FA::size()',
'FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X'
)
);
}
/**
* @param string $value
* @return self
* @throws \yii\base\InvalidConfigException
*/
public function rotate($value)
{
return $this->addCssClass(
FA::$cssPrefix . '-rotate-' . $value,
in_array((string)$value, [FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270], true),
sprintf(
'%s - invalid value. Use one of the constants: %s.',
'FA::rotate()',
'FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270'
)
);
}
/**
* @param string $value
* @return self
* @throws \yii\base\InvalidConfigException
*/
public function flip($value)
{
return $this->addCssClass(
FA::$cssPrefix . '-flip-' . $value,
in_array((string)$value, [FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL], true),
sprintf(
'%s - invalid value. Use one of the constants: %s.',
'FA::flip()',
'FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL'
)
);
}
/**
* @deprecated
* Change html tag.
* @param string $tag
* @return static
* @throws \yii\base\InvalidParamException
*/
public function tag($tag)
{
$this->tag = $tag;
$this->options['tag'] = $tag;
return $this;
}
/**
* @param string $class
* @param bool $condition
* @param string|bool $throw
* @return \rmrevin\yii\fontawesome\component\Icon
* @throws \yii\base\InvalidConfigException
* @codeCoverageIgnore
*/
public function addCssClass($class, $condition = true, $throw = false)
{
if ($condition === false) {
if (!empty($throw)) {
$message = !is_string($throw)
? 'Condition is false'
: $throw;
throw new \yii\base\InvalidConfigException($message);
}
} else {
Html::addCssClass($this->options, $class);
}
return $this;
}
/**
* @deprecated
* @param string|null $tag
* @param string|null $content
* @param array $options
* @return string
*/
public function render($tag = null, $content = null, $options = [])
{
$tag = empty($tag)
? (empty($this->tag) ? static::$defaultTag : $this->tag)
: $tag;
$options = array_merge($this->options, $options);
return Html::tag($tag, $content, $options);
}
}

View File

@@ -0,0 +1,161 @@
<?php
/**
* Stack.php
* @author Revin Roman
* @link https://rmrevin.ru
*/
namespace rmrevin\yii\fontawesome\component;
use rmrevin\yii\fontawesome\FA;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Class Stack
* @package rmrevin\yii\fontawesome\component
*/
class Stack
{
/**
* @deprecated
* @var string
*/
public static $defaultTag = 'span';
/**
* @deprecated
* @var string
*/
private $tag;
/**
* @var array
*/
private $options = [];
/**
* @var Icon
*/
private $icon_front;
/**
* @var Icon
*/
private $icon_back;
/**
* @param array $options
*/
public function __construct($options = [])
{
Html::addCssClass($options, FA::$cssPrefix . '-stack');
$this->options = $options;
}
/**
* @return string
*/
public function __toString()
{
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'span');
$template = ArrayHelper::remove($options, 'template', '{back}{front}');
$icon_back = $this->icon_back instanceof Icon
? $this->icon_back->addCssClass(FA::$cssPrefix . '-stack-2x')
: null;
$icon_front = $this->icon_front instanceof Icon
? $this->icon_front->addCssClass(FA::$cssPrefix . '-stack-1x')
: null;
$content = str_replace(['{back}', '{front}'], [$icon_back, $icon_front], $template);
return Html::tag($tag, $content, $options);
}
/**
* @param string|Icon $icon
* @param array $options
* @return self
*/
public function icon($icon, $options = [])
{
if (is_string($icon)) {
$icon = new Icon($icon, $options);
}
$this->icon_front = $icon;
return $this;
}
/**
* @param string|Icon $icon
* @param array $options
* @return self
*/
public function on($icon, $options = [])
{
if (is_string($icon)) {
$icon = new Icon($icon, $options);
}
$this->icon_back = $icon;
return $this;
}
/**
* @deprecated
* Change html tag.
* @param string $tag
* @return static
* @throws \yii\base\InvalidParamException
*/
public function tag($tag)
{
$this->tag = $tag;
$this->options['tag'] = $tag;
return $this;
}
/**
* @deprecated
* @param string|null $tag
* @param array $options
* @return string
* @throws \yii\base\InvalidConfigException
*/
public function render($tag = null, $options = [])
{
$tag = empty($tag)
? (empty($this->tag) ? static::$defaultTag : $this->tag)
: $tag;
$options = array_merge($this->options, $options);
$template = ArrayHelper::remove($options, 'template', '{back}{front}');
$icon_back = $this->icon_back instanceof Icon
? $this->icon_back->addCssClass(FA::$cssPrefix . '-stack-2x')
: null;
$icon_front = $this->icon_front instanceof Icon
? $this->icon_front->addCssClass(FA::$cssPrefix . '-stack-1x')
: null;
return Html::tag(
$tag,
str_replace(['{back}', '{front}'], [$icon_back, $icon_front], $template),
$options
);
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* UnorderedList.php
* @author Revin Roman
* @link https://rmrevin.com
*/
namespace rmrevin\yii\fontawesome\component;
use rmrevin\yii\fontawesome\FA;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Class UnorderedList
* @package rmrevin\yii\fontawesome\component
*/
class UnorderedList
{
/**
* @deprecated
* @var string
*/
public static $defaultTag = 'ul';
/**
* @deprecated
* @var string
*/
private $tag;
/**
* @var array
*/
protected $options = [];
/**
* @var array
*/
protected $items = [];
/**
* @param array $options
*/
public function __construct($options = [])
{
Html::addCssClass($options, FA::$cssPrefix . '-ul');
$options['item'] = function ($item, $index) {
return call_user_func($item, $index);
};
$this->options = $options;
}
/**
* @return string
*/
public function __toString()
{
return Html::ul($this->items, $this->options);
}
/**
* @param string $label
* @param array $options
* @return static
*/
public function item($label, $options = [])
{
$this->items[] = function ($index) use ($label, $options) {
$tag = ArrayHelper::remove($options, 'tag', 'li');
$icon = ArrayHelper::remove($options, 'icon');
$icon = empty($icon)
? null
: (is_string($icon) ? (string)(new Icon($icon))->li() : $icon);
$content = trim($icon . $label);
return Html::tag($tag, $content, $options);
};
return $this;
}
/**
* @deprecated
* Change html tag.
* @param string $tag
* @return static
* @throws \yii\base\InvalidParamException
*/
public function tag($tag)
{
$this->tag = $tag;
$this->options['tag'] = $tag;
return $this;
}
/**
* @deprecated
* @param string|null $tag
* @param array $options
* @return string
* @throws \yii\base\InvalidConfigException
*/
public function render($tag = null, $options = [])
{
$tag = empty($tag)
? (empty($this->tag) ? static::$defaultTag : $this->tag)
: $tag;
$options = array_merge($this->options, $options);
$items = $this->items;
return Html::tag($tag, implode($items), $options);
}
}