From 396cc3fcce9e6b5c0ffd9e25a567415d04784d39 Mon Sep 17 00:00:00 2001 From: Diego Smania Date: Mon, 1 Jul 2024 20:23:21 -0300 Subject: [PATCH] [Components/ProfileItems]: Improve profile items --- .../widget/profile-col-item.blade.php | 8 +++++-- .../widget/profile-row-item.blade.php | 8 +++++-- src/View/Components/Widget/ProfileColItem.php | 20 +++++++++++++--- src/View/Components/Widget/ProfileRowItem.php | 20 +++++++++++++--- tests/Components/WidgetComponentsTest.php | 24 +++++++++++++++++++ 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/resources/views/components/widget/profile-col-item.blade.php b/resources/views/components/widget/profile-col-item.blade.php index c2bc41d2..7fc9fa90 100644 --- a/resources/views/components/widget/profile-col-item.blade.php +++ b/resources/views/components/widget/profile-col-item.blade.php @@ -10,7 +10,7 @@ {{-- Header --}} @isset($title)
- @if(! empty($url)) + @if(! empty($url) && $urlTarget === 'title') {{ $title }} @else {{ $title }} @@ -22,7 +22,11 @@ @isset($text)

- {{ $text }} + @if(! empty($url) && $urlTarget === 'text') + {{ $text }} + @else + {{ $text }} + @endif

@endisset diff --git a/resources/views/components/widget/profile-row-item.blade.php b/resources/views/components/widget/profile-row-item.blade.php index 61fee1e0..d02fdd07 100644 --- a/resources/views/components/widget/profile-row-item.blade.php +++ b/resources/views/components/widget/profile-row-item.blade.php @@ -9,7 +9,7 @@ {{-- Header --}} @isset($title) - @if(! empty($url)) + @if(! empty($url) && $urlTarget === 'title') {{ $title }} @else {{ $title }} @@ -19,7 +19,11 @@ {{-- Text --}} @isset($text) - {{ $text }} + @if(! empty($url) && $urlTarget === 'text') + {{ $text }} + @else + {{ $text }} + @endif @endisset diff --git a/src/View/Components/Widget/ProfileColItem.php b/src/View/Components/Widget/ProfileColItem.php index cd678e70..3f8f67e3 100644 --- a/src/View/Components/Widget/ProfileColItem.php +++ b/src/View/Components/Widget/ProfileColItem.php @@ -39,7 +39,8 @@ class ProfileColItem extends Component * The badge theme for the text attribute. When used, the text attribute * will be wrapped inside a badge of the configured theme. Available themes * are: light, dark, primary, secondary, info, success, warning, danger or - * any other AdminLTE color like lighblue or teal. + * any other AdminLTE color like lighblue or teal. You can also prepend + * the 'pill-' token for a pill badge, for example: 'pill-info'. * * @var string */ @@ -53,6 +54,13 @@ class ProfileColItem extends Component */ public $url; + /** + * The target element for the URL (title or text). + * + * @var string + */ + public $urlTarget; + /** * Create a new component instance. * @@ -60,7 +68,7 @@ class ProfileColItem extends Component */ public function __construct( $title = null, $text = null, $icon = null, $size = 4, - $badge = null, $url = null + $badge = null, $url = null, $urlTarget = 'title' ) { $this->title = UtilsHelper::applyHtmlEntityDecoder($title); $this->text = UtilsHelper::applyHtmlEntityDecoder($text); @@ -68,6 +76,7 @@ public function __construct( $this->size = $size; $this->badge = $badge; $this->url = $url; + $this->urlTarget = $urlTarget; } /** @@ -80,7 +89,12 @@ public function makeTextWrapperClass() $classes = []; if (isset($this->badge)) { - $classes[] = "badge bg-{$this->badge}"; + $badgeMode = str_starts_with($this->badge, 'pill-') + ? 'badge-pill' + : 'badge'; + + $badgeTheme = str_replace('pill-', '', $this->badge); + $classes[] = "{$badgeMode} bg-{$badgeTheme}"; } return implode(' ', $classes); diff --git a/src/View/Components/Widget/ProfileRowItem.php b/src/View/Components/Widget/ProfileRowItem.php index f85ba9dc..a92257db 100644 --- a/src/View/Components/Widget/ProfileRowItem.php +++ b/src/View/Components/Widget/ProfileRowItem.php @@ -39,7 +39,8 @@ class ProfileRowItem extends Component * The badge theme for the text attribute. When used, the text attribute * will be wrapped inside a badge of the configured theme. Available themes * are: light, dark, primary, secondary, info, success, warning, danger or - * any other AdminLTE color like lighblue or teal. + * any other AdminLTE color like lighblue or teal. You can also prepend + * the 'pill-' token for a pill badge, for example: 'pill-info'. * * @var string */ @@ -53,6 +54,13 @@ class ProfileRowItem extends Component */ public $url; + /** + * The target element for the URL (title or text). + * + * @var string + */ + public $urlTarget; + /** * Create a new component instance. * @@ -60,7 +68,7 @@ class ProfileRowItem extends Component */ public function __construct( $title = null, $text = null, $icon = null, $size = 12, - $badge = null, $url = null + $badge = null, $url = null, $urlTarget = 'title' ) { $this->title = UtilsHelper::applyHtmlEntityDecoder($title); $this->text = UtilsHelper::applyHtmlEntityDecoder($text); @@ -68,6 +76,7 @@ public function __construct( $this->size = $size; $this->badge = $badge; $this->url = $url; + $this->urlTarget = $urlTarget; } /** @@ -80,7 +89,12 @@ public function makeTextWrapperClass() $classes = ['float-right']; if (isset($this->badge)) { - $classes[] = "badge bg-{$this->badge}"; + $badgeMode = str_starts_with($this->badge, 'pill-') + ? 'badge-pill' + : 'badge'; + + $badgeTheme = str_replace('pill-', '', $this->badge); + $classes[] = "{$badgeMode} bg-{$badgeTheme}"; } return implode(' ', $classes); diff --git a/tests/Components/WidgetComponentsTest.php b/tests/Components/WidgetComponentsTest.php index c608ff2f..3b450b0a 100644 --- a/tests/Components/WidgetComponentsTest.php +++ b/tests/Components/WidgetComponentsTest.php @@ -232,6 +232,8 @@ public function testInfoBoxComponentProgressAttribute() public function testProfileColItemComponent() { + // Test with common badge. + $component = new Components\Widget\ProfileColItem( 'title', 'text', null, null, 'b-theme' ); @@ -239,6 +241,16 @@ public function testProfileColItemComponent() $twClass = $component->makeTextWrapperClass(); $this->assertStringContainsString('badge', $twClass); $this->assertStringContainsString('bg-b-theme', $twClass); + + // Test with common pill badge. + + $component = new Components\Widget\ProfileColItem( + 'title', 'text', null, null, 'pill-b-theme' + ); + + $twClass = $component->makeTextWrapperClass(); + $this->assertStringContainsString('badge-pill', $twClass); + $this->assertStringContainsString('bg-b-theme', $twClass); } /* @@ -249,6 +261,8 @@ public function testProfileColItemComponent() public function testProfileRowItemComponent() { + // Test with common badge. + $component = new Components\Widget\ProfileRowItem( 'title', 'text', null, null, 'b-theme' ); @@ -256,6 +270,16 @@ public function testProfileRowItemComponent() $twClass = $component->makeTextWrapperClass(); $this->assertStringContainsString('badge', $twClass); $this->assertStringContainsString('bg-b-theme', $twClass); + + // Test with common pill badge. + + $component = new Components\Widget\ProfileRowItem( + 'title', 'text', null, null, 'pill-b-theme' + ); + + $twClass = $component->makeTextWrapperClass(); + $this->assertStringContainsString('badge-pill', $twClass); + $this->assertStringContainsString('bg-b-theme', $twClass); } /*