-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from CottaCush/features/rework-widgets
(BaseWidget): Add `beginDiv` and `endDiv`
- Loading branch information
Showing
15 changed files
with
338 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace CottaCush\Yii2\Assets; | ||
|
||
/** | ||
* Class EmptyStateAsset | ||
* @package CottaCush\Yii2\Assets | ||
* @author Olawale Lawal <wale@cottacush.com> | ||
*/ | ||
class EmptyStateAsset extends LocalAssetBundle | ||
{ | ||
public $css = [ | ||
'css/empty-state.css', | ||
]; | ||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace CottaCush\Yii2\Widgets; | ||
|
||
use CottaCush\Yii2\Helpers\Html; | ||
use yii\helpers\ArrayHelper; | ||
|
||
/** | ||
* Class BaseContentHeaderButton | ||
* @author Olajide Oye <jide@cottacush.com> | ||
* @package app\widgets | ||
*/ | ||
class BaseContentHeaderButton extends BaseWidget | ||
{ | ||
public $button; | ||
public $buttonClass; | ||
|
||
protected function setButton() | ||
{ | ||
if (is_string($this->button)) { | ||
return; | ||
} | ||
if (is_array($this->button)) { | ||
$this->buildButton($this->button); | ||
return; | ||
} | ||
|
||
$buttonDetails = ArrayHelper::getValue($this->view->params, 'content-header-button', ''); | ||
if (is_string($buttonDetails)) { | ||
$this->button = $buttonDetails; | ||
return; | ||
} | ||
$this->buildButton($buttonDetails); | ||
} | ||
|
||
private function buildButton($buttonArray) | ||
{ | ||
if (!is_array($buttonArray)) { | ||
return; | ||
} | ||
|
||
$text = ArrayHelper::getValue($buttonArray, 'label', 'Add New'); | ||
$tag = ArrayHelper::getValue($buttonArray, 'tag', 'a'); | ||
$iconName = ArrayHelper::getValue($buttonArray, 'icon'); | ||
$icon = ''; | ||
if ($iconName) { | ||
$icon = Html::faIcon($iconName); | ||
} | ||
$options = ArrayHelper::getValue($buttonArray, 'options', []); | ||
|
||
Html::addCssClass($options, $this->buttonClass); | ||
|
||
$this->button = Html::tag($tag, "$icon $text", $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
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,69 @@ | ||
<?php | ||
|
||
namespace CottaCush\Yii2\Widgets; | ||
|
||
use CottaCush\Yii2\Helpers\Html; | ||
use yii\helpers\ArrayHelper; | ||
use yii\helpers\Url; | ||
use yii\widgets\Breadcrumbs; | ||
|
||
/** | ||
* Class ContentHeaderWidget | ||
* @author Olajide Oye <jide@cottacush.com> | ||
* @package CottaCush\Yii2\Widgets | ||
*/ | ||
class ContentHeaderWidget extends BaseContentHeaderButton | ||
{ | ||
public $title; | ||
public $breadcrumbs; | ||
public $buttonClass = 'btn btn-sm content-header-btn'; | ||
public $contentRight; | ||
public $icon; | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
$view = $this->view; | ||
|
||
if (is_null($this->title)) { | ||
$this->title = ArrayHelper::getValue($view, 'params.pageTitle', $view->title); | ||
} | ||
if (is_null($this->breadcrumbs)) { | ||
$this->breadcrumbs = ArrayHelper::getValue($view, 'params.breadcrumbs', $this->title); | ||
} | ||
if (is_null($this->contentRight)) { | ||
$this->contentRight = ArrayHelper::getValue($view, 'params.contentHeaderRight', ''); | ||
} | ||
|
||
$this->setButton(); | ||
} | ||
|
||
public function run() | ||
{ | ||
echo Html::beginTag('section', ['class' => 'content-header']); | ||
echo $this->beginDiv(' clearfix'); | ||
echo $this->beginDiv(' content-header__left'); | ||
echo Html::beginTag('h1', ['class' => 'content-header-title']); | ||
|
||
echo ($this->icon) ? Html::faIcon($this->icon) . ' ' . $this->title : $this->title; | ||
|
||
echo Html::endTag('h1'); | ||
|
||
echo $this->endDiv(); | ||
echo Html::tag('div', $this->contentRight, ['class' => 'content-header__right']); | ||
if (ArrayHelper::getValue($this->view->params, 'show-content-header-button', true)) { | ||
echo $this->button; | ||
} | ||
echo $this->endDiv(); | ||
echo Breadcrumbs::widget([ | ||
'tag' => 'ol', | ||
'homeLink' => [ | ||
'label' => 'Home', | ||
'url' => Url::toRoute('/') | ||
], | ||
'links' => $this->breadcrumbs | ||
]); | ||
echo Html::endTag('section'); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace CottaCush\Yii2\Widgets; | ||
|
||
use CottaCush\Yii2\Assets\EmptyStateAsset; | ||
use CottaCush\Yii2\Assets\FontAwesomeAsset; | ||
use CottaCush\Yii2\Helpers\Html; | ||
|
||
/** | ||
* Class EmptyStateWidget | ||
* @package CottaCush\Yii2\Widgets | ||
* @author Olajide Oye <jide@cottacush.com> | ||
* @author Olawale Lawal <wale@cottacush.com> | ||
*/ | ||
class EmptyStateWidget extends BaseWidget | ||
{ | ||
public $icon; | ||
public $title; | ||
public $description; | ||
public $buttonClass = 'btn btn-primary'; | ||
|
||
public $showButton = true; | ||
public $button; | ||
|
||
public function run() | ||
{ | ||
echo Html::beginTag('section', ['class' => 'empty-state']); | ||
|
||
echo Html::faIcon($this->icon, ['class' => 'empty-state__icon']); | ||
echo Html::tag('h2', $this->title, ['class' => 'empty-state__title']); | ||
echo Html::tag('p', $this->description, ['class' => 'empty-state__description']); | ||
|
||
if ($this->showButton) { | ||
echo Html::tag('div', $this->button, ['class' => 'empty-state__btn']); | ||
} | ||
|
||
echo Html::endTag('section'); | ||
|
||
EmptyStateAsset::register($this->getView()); | ||
FontAwesomeAsset::register($this->view); | ||
} | ||
} |
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
Oops, something went wrong.