-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring, updated tests.
- Loading branch information
Showing
6 changed files
with
194 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* UnorderedList.php | ||
* @author Revin Roman | ||
* @link https://rmrevin.com | ||
*/ | ||
|
||
namespace rmrevin\yii\fontawesome\component; | ||
|
||
use rmrevin\yii\fontawesome\FA; | ||
use yii\helpers\Html; | ||
|
||
/** | ||
* Class UnorderedList | ||
* @package rmrevin\yii\fontawesome\component | ||
*/ | ||
class UnorderedList | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public static $defaultTag = 'ul'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $tag; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $options = []; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $items = []; | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function __construct($options = []) | ||
{ | ||
Html::addCssClass($options, FA::$cssPrefix . '-ul'); | ||
|
||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->render(); | ||
} | ||
|
||
/** | ||
* @param string|Icon $icon | ||
* @param string|null $label | ||
* @param array $options | ||
* @return static | ||
*/ | ||
public function item($icon, $label = null, $options = []) | ||
{ | ||
if (is_string($icon)) { | ||
$icon = new Icon($icon, $options); | ||
} | ||
|
||
$content = trim((string)$icon->li() . $label); | ||
|
||
$this->items[] = Html::tag('li', $content); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Change html tag. | ||
* @param string $tag | ||
* @return static | ||
* @throws \yii\base\InvalidParamException | ||
*/ | ||
public function tag($tag) | ||
{ | ||
$this->tag = $tag; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters