Skip to content

Commit

Permalink
Added possibility to specify "secondary" button class using PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Janda authored and paveljanda committed Sep 12, 2022
1 parent ef9e02a commit 1351abe
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Column/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Action extends Column
/**
* @var string|callable
*/
protected $class = 'btn btn-xs btn-default btn-secondary';
protected $class = '';

/**
* @var bool
Expand All @@ -93,6 +93,7 @@ public function __construct(

$this->href = $href;
$this->params = $params;
$this->class = sprintf('btn btn-xs %s', $grid::$btnSecondaryClass)
}


Expand Down
2 changes: 1 addition & 1 deletion src/Column/ItemDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(DataGrid $grid, string $primaryWhereColumn)
$this->primaryWhereColumn = $primaryWhereColumn;

$this->title = 'ublaboo_datagrid.show';
$this->class = 'btn btn-xs btn-default btn-secondary ajax';
$this->class = sprintf('btn btn-xs %s ajax', $grid::$btnSecondaryClass);
$this->icon = 'eye';
}

Expand Down
13 changes: 10 additions & 3 deletions src/Components/DataGridPaginator/DataGridPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class DataGridPaginator extends Control
*/
private $iconPrefix;

/**
* @var string
*/
private $btnSecondaryClass;

/**
* @var Paginator
*/
Expand All @@ -47,11 +52,12 @@ class DataGridPaginator extends Control

public function __construct(
ITranslator $translator,
string $iconPrefix = 'fa fa-'
)
{
string $iconPrefix = 'fa fa-',
string $btnSecondaryClass = 'btn-default btn-secondary'
) {
$this->translator = $translator;
$this->iconPrefix = $iconPrefix;
$this->btnSecondaryClass = $btnSecondaryClass;
}


Expand Down Expand Up @@ -129,6 +135,7 @@ public function render(): void
}

$this->getTemplate()->iconPrefix = $this->iconPrefix;
$this->getTemplate()->btnSecondaryClass = $this->btnSecondaryClass;
$this->getTemplate()->originalTemplate = $this->getOriginalTemplateFile();
$this->getTemplate()->setFile($this->getTemplateFile());
$this->getTemplate()->render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@

<div n:if="$paginator->pageCount > 1">
{if $paginator->isFirst()}
<a class="first btn btn-sm btn-default btn-secondary disabled">
<a class="first btn btn-sm {$btnSecondaryClass} disabled">
{else}
<a class="btn btn-sm btn-default btn-secondary ajax" href="{$link('page!', ['page' => $paginator->page - 1])}" rel="prev">
<a class="btn btn-sm {$btnSecondaryClass} ajax" href="{$link('page!', ['page' => $paginator->page - 1])}" rel="prev">
{/if}
<i n:block = "icon-arrow-left" class="{$iconPrefix}arrow-left"></i> {='ublaboo_datagrid.previous'|translate}</a>

{foreach $steps as $step}
{if $step == $paginator->page}
<a class="first btn btn-sm btn-primary active">{$step}</a>
{else}
<a class="btn btn-sm btn-default btn-secondary ajax" href="{$link('page!', ['page' => $step])}">{$step}</a>
<a class="btn btn-sm {$btnSecondaryClass} ajax" href="{$link('page!', ['page' => $step])}">{$step}</a>
{/if}

{if $iterator->nextValue > $step + 1}<span>…</span>{/if}
{/foreach}

{if $paginator->isLast()}
<a class="first btn btn-sm btn-default btn-secondary disabled">{='ublaboo_datagrid.next'|translate}
<a class="first btn btn-sm {$btnSecondaryClass} disabled">{='ublaboo_datagrid.next'|translate}
{else}
<a class="btn btn-sm btn-default btn-secondary ajax" href="{$link('page!', ['page' => $paginator->page + 1])}" rel="next">{='ublaboo_datagrid.next'|translate}
<a class="btn btn-sm {$btnSecondaryClass} ajax" href="{$link('page!', ['page' => $paginator->page + 1])}" rel="next">{='ublaboo_datagrid.next'|translate}
{/if}
<i n:block = "icon-arrow-right" class="{$iconPrefix}arrow-right"></i></a>
</div>
10 changes: 8 additions & 2 deletions src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ class DataGrid extends Control
*/
public static $iconPrefix = 'fa fa-';

/**
* @var string
*/
public static $btnSecondaryClass = 'btn-default btn-secondary';

/**
* Default form method
*
Expand Down Expand Up @@ -573,7 +578,7 @@ public function render(): void
$template->filter_active = $this->isFilterActive();
$template->originalTemplate = $this->getOriginalTemplateFile();
$template->iconPrefix = static::$iconPrefix;
$template->iconPrefix = static::$iconPrefix;
$template->btnSecondaryClass = static::$btnSecondaryClass;
$template->itemsDetail = $this->itemsDetail;
$template->columnsVisibility = $this->getColumnsVisibility();
$template->columnsSummary = $this->columnsSummary;
Expand Down Expand Up @@ -2451,7 +2456,8 @@ public function createComponentPaginator(): DataGridPaginator
{
$component = new DataGridPaginator(
$this->getTranslator(),
static::$iconPrefix
static::$iconPrefix,
static::$btnSecondaryClass
);
$paginator = $component->getPaginator();

Expand Down
2 changes: 1 addition & 1 deletion src/InlineEdit/InlineEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct(DataGrid $grid, ?string $primaryWhereColumn = null)
$this->primaryWhereColumn = $primaryWhereColumn;

$this->title = 'ublaboo_datagrid.edit';
$this->class = 'btn btn-xs btn-default btn-secondary ajax';
$this->class = sprintf('btn btn-xs %s ajax', $grid::$btnSecondaryClass);
$this->icon = 'pencil pencil-alt';

$this->onControlAfterAdd[] = [$this, 'addControlsClasses'];
Expand Down
4 changes: 2 additions & 2 deletions src/templates/datagrid.latte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
{/if}

<div class="btn-group">
<button type="button" class="btn btn-xs btn-default btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" n:if="$control->canHideColumns()">
<button type="button" class="btn btn-xs {$btnSecondaryClass} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" n:if="$control->canHideColumns()">
<i n:block="icon-gear" class="{$iconPrefix}cog"></i>
</button>
<ul class="dropdown-menu dropdown-menu-right dropdown-menu--grid">
Expand Down Expand Up @@ -301,7 +301,7 @@
{/if}
{/if}
{/foreach}
<span class="handle-sort btn btn-xs btn-default btn-secondary" n:if="$control->isSortable()">
<span class="handle-sort btn btn-xs {$btnSecondaryClass}" n:if="$control->isSortable()">
<i n:block="icon-arrows-v" class="{$iconPrefix}arrows-v {$iconPrefix}arrows-alt-v"></i>
</span>
{if $inlineEdit && $row->hasInlineEdit()}
Expand Down
4 changes: 2 additions & 2 deletions src/templates/datagrid_tree.latte
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{/if}
{/foreach}

<span class="handle-sort btn btn-xs btn-default btn-secondary" n:if="$control->isSortable()">
<span class="handle-sort btn btn-xs {btnSecondaryClass}" n:if="$control->isSortable()">
<i class="{$iconPrefix}arrows"></i>
</span>
</div>
Expand Down Expand Up @@ -126,7 +126,7 @@
{/if}
{/foreach}

<span class="handle-sort btn btn-xs btn-default btn-secondary" n:if="$control->isSortable()">
<span class="handle-sort btn btn-xs {btnSecondaryClass}" n:if="$control->isSortable()">
<i n:block = "icon-arrows" class="{$iconPrefix}arrows {$iconPrefix}arrows-alt"></i>
</span>
</div>
Expand Down

0 comments on commit 1351abe

Please sign in to comment.