Skip to content

Commit a5420dc

Browse files
committed
refactor ajaxOverlay in CardWidget
1 parent 094ceb7 commit a5420dc

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/CardWidget.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
class CardWidget extends \yii\base\Widget
1212
{
13+
const OVERLAY_TYPES = ['overlay', 'dark'];
14+
1315
/**
1416
* title of a card
1517
* @var string
@@ -106,10 +108,7 @@ public function run(): string
106108
$html .= $this->getCardBody();
107109
$html .= $this->getCardFooter();
108110

109-
if ($this->ajaxLoad) {
110-
$overlay = ($this->ajaxOverlay == 'dark') ? 'overlay dark' : 'overlay';
111-
$html .= ($this->ajaxLoad) ? Html::tag('div', '<i class="fas fa-2x fa-sync-alt fa-spin"></i>', ['class' => $overlay, 'data-ajax-load-url' => $this->ajaxLoad]) : '';
112-
}
111+
$html .= (!empty($this->ajaxLoad)) ? Html::tag('div', '<i class="fas fa-2x fa-sync-alt fa-spin"></i>', ['class' => $this->getOverlayClass(), 'data-ajax-load-url' => $this->ajaxLoad]) : '';
113112

114113
$html .= Html::endTag('div'); // the end of a card
115114

@@ -217,6 +216,16 @@ protected function getCardFooterClass(): string
217216
return $class;
218217
}
219218

219+
/**
220+
* @return string
221+
*/
222+
protected function getOverlayClass(): string
223+
{
224+
if (empty($this->ajaxOverlay) || !in_array($this->ajaxOverlay, self::OVERLAY_TYPES)) return '';
225+
226+
return ($this->ajaxOverlay == 'dark') ? 'overlay dark' : 'overlay';
227+
}
228+
220229
/**
221230
* @return void
222231
*/

0 commit comments

Comments
 (0)