Skip to content

Commit

Permalink
Fix #993: Enhancements to support Bootstrap v5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 3, 2021
1 parent 371be29 commit 4f21281
Show file tree
Hide file tree
Showing 50 changed files with 207 additions and 177 deletions.
6 changes: 5 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ Change Log: `yii2-grid`

## Version 3.3.6

**Date:** _under development_
**Date:** 02-Sep-2021

- (enh #993): Enhancements to support Bootstrap v5.x.
- (enh #971): Correct `kv-grid-group.js` version.
- (enh #969): Update Fontawesome CDN version.
- (enh #968): Update Ukraine Translations.
- (bug #959): Correct `filterOptions` column seq setting in ColumnTrait.
- (bug #958): Correct ExpandRowColumn expand all & collapse all.
- (enh #956): Update Portugese Brazilian Translations.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2020, Kartik Visweswaran
Copyright (c) 2014 - 2021, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
],
"require": {
"kartik-v/yii2-dialog": "~1.0",
"kartik-v/yii2-bootstrap4-dropdown": "~1.0"
"kartik-v/yii2-bootstrap4-dropdown": "~1.0",
"kartik-v/yii2-bootstrap5-dropdown": "~1.0"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 19 additions & 19 deletions src/ActionColumn.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-grid
* @version 3.3.6
*/

namespace kartik\grid;

use Closure;
use Exception;
use Yii;
use yii\grid\ActionColumn as YiiActionColumn;
use yii\helpers\ArrayHelper;
Expand Down Expand Up @@ -115,7 +116,7 @@ class ActionColumn extends YiiActionColumn
public $headerOptions = [];

/**
* @var array|\Closure the HTML attributes for the data cell tag. This can either be an array of attributes or an
* @var array|Closure the HTML attributes for the data cell tag. This can either be an array of attributes or an
* anonymous function ([[Closure]]) that returns such an array. The signature of the function should be the
* following: `function ($model, $key, $index, $column)`. A function may be used to assign different attributes
* to different rows based on the data in that row.
Expand All @@ -131,7 +132,7 @@ class ActionColumn extends YiiActionColumn

/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
* @throws InvalidConfigException
*/
public function init()
{
Expand All @@ -140,9 +141,8 @@ public function init()
'mergeHeader' => true,
'hAlign' => GridView::ALIGN_CENTER,
'vAlign' => GridView::ALIGN_MIDDLE,
'width' => '50px',
'width' => '100px',
]);
/** @noinspection PhpUndefinedFieldInspection */
$this->_isDropdown = ($this->grid->bootstrap && $this->dropdown);
if (!isset($this->header)) {
$this->header = Yii::t('kvgrid', 'Actions');
Expand Down Expand Up @@ -217,19 +217,19 @@ protected function renderLabel(&$options, $title, $iconOptions = [])
* @param string $name button name as written in the [[template]]
* @param string $title the title of the button
* @param string $icon the meaningful glyphicon suffix name for the button
* @throws InvalidConfigException
* @throws InvalidConfigException|Exception
*/
protected function setDefaultButton($name, $title, $icon)
{
$isBs4 = $this->grid->isBs4();
$notBs3 = !$this->grid->isBs(3);
if (isset($this->buttons[$name])) {
return;
}
$this->buttons[$name] = function ($url) use ($name, $title, $icon, $isBs4) {
$this->buttons[$name] = function ($url) use ($name, $title, $icon, $notBs3) {
$opts = "{$name}Options";
$options = ['title' => $title, 'aria-label' => $title, 'data-pjax' => '0'];
if ($name === 'delete') {
$item = isset($this->grid->itemLabelSingle) ? $this->grid->itemLabelSingle : Yii::t('kvgrid', 'item');
$item = $this->grid->itemLabelSingle ?? Yii::t('kvgrid', 'item');
$options['data-method'] = 'post';
$options['data-confirm'] = Yii::t('kvgrid', 'Are you sure to delete this {item}?', ['item' => $item]);
}
Expand All @@ -238,7 +238,7 @@ protected function setDefaultButton($name, $title, $icon)
$link = Html::a($label, $url, $options);
if ($this->_isDropdown) {
$options['tabindex'] = '-1';
return $isBs4 ? $link : "<li>{$link}</li>\n";
return $notBs3 ? $link : "<li>{$link}</li>\n";
} else {
return $link;
}
Expand All @@ -251,10 +251,10 @@ protected function setDefaultButton($name, $title, $icon)
*/
protected function initDefaultButtons()
{
$isBs4 = $this->grid->isBs4();
$this->setDefaultButton('view', Yii::t('kvgrid', 'View'), $isBs4 ? 'eye' : 'eye-open');
$this->setDefaultButton('update', Yii::t('kvgrid', 'Update'), $isBs4 ? 'pencil-alt' : 'pencil');
$this->setDefaultButton('delete', Yii::t('kvgrid', 'Delete'), $isBs4 ? 'trash-alt' : 'trash');
$notBs3 = !$this->grid->isBs(3);
$this->setDefaultButton('view', Yii::t('kvgrid', 'View'), $notBs3 ? 'eye' : 'eye-open');
$this->setDefaultButton('update', Yii::t('kvgrid', 'Update'), $notBs3 ? 'pencil-alt' : 'pencil');
$this->setDefaultButton('delete', Yii::t('kvgrid', 'Delete'), $notBs3 ? 'trash-alt' : 'trash');
}

/**
Expand All @@ -263,8 +263,8 @@ protected function initDefaultButtons()
*/
protected function renderDataCellContent($model, $key, $index)
{
$isBs4 = $this->grid->isBs4();
if ($isBs4 && $this->_isDropdown) {
$notBs3 = !$this->grid->isBs(3);
if ($notBs3 && $this->_isDropdown) {
Html::addCssClass($this->buttonOptions, 'dropdown-item');
}
$content = parent::renderDataCellContent($model, $key, $index);
Expand All @@ -278,13 +278,13 @@ protected function renderDataCellContent($model, $key, $index)
$trimmed = trim($content);
if ($this->_isDropdown && !empty($trimmed)) {
$label = ArrayHelper::remove($options, 'label', Yii::t('kvgrid', 'Actions'));
$caret = $isBs4 ? '' : ArrayHelper::remove($options, 'caret', ' <span class="caret"></span>');
$caret = $notBs3 ? '' : ArrayHelper::remove($options, 'caret', ' <span class="caret"></span>');
$options = array_replace_recursive($options, ['type' => 'button', 'data-toggle' => 'dropdown']);
Html::addCssClass($options, 'dropdown-toggle');
$button = Html::button($label . $caret, $options);
Html::addCssClass($this->dropdownMenu, 'dropdown-menu');
$dropdown = $button . PHP_EOL . Html::tag($isBs4 ? 'div' : 'ul', $content, $this->dropdownMenu);
Html::addCssClass($this->dropdownOptions, $isBs4 ? 'btn-group' : 'dropdown');
$dropdown = $button . PHP_EOL . Html::tag($notBs3 ? 'div' : 'ul', $content, $this->dropdownMenu);
Html::addCssClass($this->dropdownOptions, $notBs3 ? 'btn-group' : 'dropdown');
return Html::tag('div', $dropdown, $this->dropdownOptions);
}
return $content;
Expand Down
2 changes: 1 addition & 1 deletion src/ActionColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down
16 changes: 9 additions & 7 deletions src/BooleanColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

namespace kartik\grid;

use Exception;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Html;

/**
Expand Down Expand Up @@ -67,7 +69,7 @@ class BooleanColumn extends DataColumn

/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
* @throws InvalidConfigException
*/
public function init()
{
Expand All @@ -83,7 +85,7 @@ public function init()
}
$this->filter = [true => $this->trueLabel, false => $this->falseLabel];
if (empty($this->trueIcon)) {
$this->trueIcon = $this->getIconMarkup('true');
$this->trueIcon = $this->getIconMarkup();
}

if (empty($this->falseIcon)) {
Expand All @@ -96,20 +98,20 @@ public function init()
* Get icon HTML markup
* @param string $type the type of markup `true` or `false`
* @return string
* @throws \yii\base\InvalidConfigException
* @throws InvalidConfigException|Exception
*/
protected function getIconMarkup($type = 'true')
{
$label = $type === 'false' ? $this->falseLabel: $this->trueLabel;
if (!$this->grid->bootstrap) {
return $label;
}
$isBs4 = $this->grid->isBs4();
$notBs3 = !$this->grid->isBs(3);
if ($type === 'true') {
return ($isBs4 ? GridView::ICON_ACTIVE_BS4 : GridView::ICON_ACTIVE) .
return ($notBs3 ? GridView::ICON_ACTIVE_BS4 : GridView::ICON_ACTIVE) .
Html::tag('span', $this->trueLabel, ['class' => 'kv-grid-boolean']);
}
return ($isBs4 ? GridView::ICON_INACTIVE_BS4 : GridView::ICON_INACTIVE) .
return ($notBs3 ? GridView::ICON_INACTIVE_BS4 : GridView::ICON_INACTIVE) .
Html::tag('span', $this->falseLabel, ['class' => 'kv-grid-boolean']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/CheckboxColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down
2 changes: 1 addition & 1 deletion src/CheckboxColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down
14 changes: 5 additions & 9 deletions src/ColumnTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down Expand Up @@ -209,8 +209,6 @@ public function renderHeaderCell()
Html::addCssClass($this->headerOptions, 'kv-merged-header');
}
$this->headerOptions['data-col-seq'] = array_search($this, $this->grid->columns);
/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpUndefinedMethodInspection */
return parent::renderHeaderCell();
}

Expand All @@ -225,8 +223,6 @@ public function renderFilterCell()
return null;
}
$this->filterOptions['data-col-seq'] = array_search($this, $this->grid->columns);
/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpUndefinedMethodInspection */
return parent::renderFilterCell();
}

Expand Down Expand Up @@ -262,8 +258,8 @@ public function parseExcelFormats(&$options, $model, $key, $index)
if (isset($this->xlFormat)) {
$fmt = $this->xlFormat;
} elseif ($autoFormat && isset($this->format)) {
$tSep = isset($formatter->thousandSeparator) ? $formatter->thousandSeparator : ',';
$dSep = isset($formatter->decimalSeparator) ? $formatter->decimalSeparator : '.';
$tSep = $formatter->thousandSeparator ?? ',';
$dSep = $formatter->decimalSeparator ?? '.';
switch ($format) {
case 'text':
case 'html':
Expand Down Expand Up @@ -337,7 +333,7 @@ protected function renderPageSummaryCellContent()
}
$content = $this->getPageSummaryCellContent();
if ($this->pageSummary === true) {
$format = isset($this->pageSummaryFormat) ? $this->pageSummaryFormat : $this->format;
$format = $this->pageSummaryFormat ?? $this->format;
return $this->grid->formatter->format($content, $format);
}
return ($content === null) ? $this->grid->emptyCell : $content;
Expand Down Expand Up @@ -490,7 +486,7 @@ protected function isValidAlignment($type = 'hAlign')
$this->hAlign === GridView::ALIGN_RIGHT ||
$this->hAlign === GridView::ALIGN_CENTER
);
} elseif ($type = 'vAlign') {
} elseif ($type === 'vAlign') {
return (
$this->vAlign === GridView::ALIGN_TOP ||
$this->vAlign === GridView::ALIGN_MIDDLE ||
Expand Down
11 changes: 7 additions & 4 deletions src/DataColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

namespace kartik\grid;

use Closure;
use Exception;
use kartik\base\Widget;
use yii\base\InvalidConfigException;
use yii\grid\DataColumn as YiiDataColumn;
use kartik\base\Config;
use yii\helpers\Html;
Expand Down Expand Up @@ -211,7 +214,7 @@ class DataColumn extends YiiDataColumn

/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
* @throws InvalidConfigException
*/
public function init()
{
Expand Down Expand Up @@ -246,7 +249,7 @@ public function renderDataCell($model, $key, $index)
* Renders filter inputs based on the `filterType`
*
* @return string
* @throws \Exception
* @throws Exception
*/
protected function renderFilterCellContent()
{
Expand Down Expand Up @@ -282,7 +285,7 @@ protected function renderFilterCellContent()
return Html::activeCheckbox($this->grid->filterModel, $this->attribute, $this->filterInputOptions);
}
$options = array_replace_recursive($this->filterWidgetOptions, $options);
/** @var \kartik\base\Widget $widgetClass */
/** @var Widget $widgetClass */
return $widgetClass::widget($options);
}
}
2 changes: 1 addition & 1 deletion src/Demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down
4 changes: 2 additions & 2 deletions src/EditableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down Expand Up @@ -154,7 +154,7 @@ public function renderDataCellContent($model, $key, $index)
$id = $this->grid->options['id'];
$this->_view->registerJs("kvRefreshEC('{$id}','{$this->_css}');");
}
$editableClass = ArrayHelper::remove($this->_editableOptions, 'class', Editable::className());
$editableClass = ArrayHelper::remove($this->_editableOptions, 'class', Editable::class);
if (!isset($this->_editableOptions['inlineSettings']['options'])) {
$this->_editableOptions['inlineSettings']['options']['class'] = 'skip-export';
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/EditableColumnAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down
2 changes: 1 addition & 1 deletion src/EditableColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down
2 changes: 1 addition & 1 deletion src/EnumColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 3.3.6
*/

Expand Down
Loading

0 comments on commit 4f21281

Please sign in to comment.