From 35e4044a4038eecec329d59e5f9282bd5a9063db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Prudil?= Date: Thu, 7 Feb 2019 12:52:54 +0100 Subject: [PATCH 1/3] Support for content icons --- src/Traits/TButtonIcon.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Traits/TButtonIcon.php b/src/Traits/TButtonIcon.php index bdcc9b881..48ac38d94 100644 --- a/src/Traits/TButtonIcon.php +++ b/src/Traits/TButtonIcon.php @@ -20,10 +20,14 @@ trait TButtonIcon /** * Set icon * @param string $icon + * @param string $content */ - public function setIcon($icon) + public function setIcon($icon, $content = '') { - $this->icon = $icon; + $this->icon = (object)[ + 'class' => $class, + 'content' => $content, + ]; return $this; } From db6b23b66a4ccb7c276b71a97623cbdc9862930f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Prudil?= Date: Thu, 7 Feb 2019 12:53:57 +0100 Subject: [PATCH 2/3] Support for content icons --- src/Traits/TButtonTryAddIcon.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Traits/TButtonTryAddIcon.php b/src/Traits/TButtonTryAddIcon.php index 4db1bfedc..9ef4a9eb0 100644 --- a/src/Traits/TButtonTryAddIcon.php +++ b/src/Traits/TButtonTryAddIcon.php @@ -24,7 +24,11 @@ trait TButtonTryAddIcon 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->class)->setText($icon->content)); + } else { + $el->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $icon)); + } if (strlen($name)) { $el->addHtml(' '); From 8ab693161a89c5fd0a58ac85db0b2e965f22ef95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Prudil?= Date: Wed, 24 Nov 2021 13:49:55 +0100 Subject: [PATCH 3/3] Add new Class IconData --- src/Traits/TButtonIcon.php | 7 +++---- src/Traits/TButtonTryAddIcon.php | 9 +++++---- src/Utils/IconData.php | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/Utils/IconData.php diff --git a/src/Traits/TButtonIcon.php b/src/Traits/TButtonIcon.php index 48ac38d94..24712b399 100644 --- a/src/Traits/TButtonIcon.php +++ b/src/Traits/TButtonIcon.php @@ -8,6 +8,8 @@ namespace Ublaboo\DataGrid\Traits; +use Ublaboo\DataGrid\Utils\IconData; + trait TButtonIcon { @@ -24,10 +26,7 @@ trait TButtonIcon */ public function setIcon($icon, $content = '') { - $this->icon = (object)[ - 'class' => $class, - 'content' => $content, - ]; + $this->icon = new IconData($icon, $content); return $this; } diff --git a/src/Traits/TButtonTryAddIcon.php b/src/Traits/TButtonTryAddIcon.php index 9ef4a9eb0..8aad062ff 100644 --- a/src/Traits/TButtonTryAddIcon.php +++ b/src/Traits/TButtonTryAddIcon.php @@ -10,22 +10,23 @@ 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) { if (is_object($icon)) { - $el->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $icon->class)->setText($icon->content)); + $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)); } diff --git a/src/Utils/IconData.php b/src/Utils/IconData.php new file mode 100644 index 000000000..dba12455a --- /dev/null +++ b/src/Utils/IconData.php @@ -0,0 +1,27 @@ +content = $content; + $this->iconClass = $iconClass; + } +}