Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for content icons (Google Material etc) #739

Open
wants to merge 3 commits into
base: v5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Traits/TButtonIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Ublaboo\DataGrid\Traits;

use Ublaboo\DataGrid\Utils\IconData;

trait TButtonIcon
{

Expand All @@ -20,10 +22,11 @@ trait TButtonIcon
/**
* Set icon
* @param string $icon
* @param string $content
*/
public function setIcon($icon)
public function setIcon($icon, $content = '')
{
$this->icon = $icon;
$this->icon = new IconData($icon, $content);

return $this;
}
Expand Down
13 changes: 9 additions & 4 deletions src/Traits/TButtonTryAddIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@

use Nette\Utils\Html;
use Ublaboo\DataGrid\DataGrid;
use Ublaboo\DataGrid\Utils\IconData;

trait TButtonTryAddIcon
{

/**
* Should the element has an icon?
* @param Html $el
* @param string|null $icon
* @param string $name
* @param Html $el
* @param string|IconData|null $icon
* @param string $name
* @return void
*/
public function tryAddIcon(Html $el, $icon, $name)
{
if ($icon) {
$el->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $icon));
if (is_object($icon)) {
$el->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $icon->iconClass)->setText($icon->content));
} else {
$el->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $icon));
}

if (strlen($name)) {
$el->addHtml(' ');
Expand Down
27 changes: 27 additions & 0 deletions src/Utils/IconData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Ublaboo\DataGrid\Utils;

class IconData
{
/**
* @var string
*/
public $content;

/**
* @var string
*/
public $iconClass;


/**
* @param string $content
* @param string $iconClass
*/
public function __construct($content, $iconClass)
{
$this->content = $content;
$this->iconClass = $iconClass;
}
}