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

Improve profile items #1291

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
8 changes: 6 additions & 2 deletions resources/views/components/widget/profile-col-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{-- Header --}}
@isset($title)
<h5 class="description-header">
@if(! empty($url))
@if(! empty($url) && $urlTarget === 'title')
<a href="{{ $url }}">{{ $title }}</a>
@else
{{ $title }}
Expand All @@ -22,7 +22,11 @@
@isset($text)
<p class="description-text">
<span class="{{ $makeTextWrapperClass() }}">
{{ $text }}
@if(! empty($url) && $urlTarget === 'text')
<a href="{{ $url }}">{{ $text }}</a>
@else
{{ $text }}
@endif
</span>
</p>
@endisset
Expand Down
8 changes: 6 additions & 2 deletions resources/views/components/widget/profile-row-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{{-- Header --}}
@isset($title)
@if(! empty($url))
@if(! empty($url) && $urlTarget === 'title')
<a href="{{ $url }}">{{ $title }}</a>
@else
{{ $title }}
Expand All @@ -19,7 +19,11 @@
{{-- Text --}}
@isset($text)
<span class="{{ $makeTextWrapperClass() }}">
{{ $text }}
@if(! empty($url) && $urlTarget === 'text')
<a href="{{ $url }}">{{ $text }}</a>
@else
{{ $text }}
@endif
</span>
@endisset

Expand Down
20 changes: 17 additions & 3 deletions src/View/Components/Widget/ProfileColItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -53,21 +54,29 @@ class ProfileColItem extends Component
*/
public $url;

/**
* The target element for the URL (title or text).
*
* @var string
*/
public $urlTarget;

/**
* Create a new component instance.
*
* @return void
*/
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);
$this->icon = $icon;
$this->size = $size;
$this->badge = $badge;
$this->url = $url;
$this->urlTarget = $urlTarget;
}

/**
Expand All @@ -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);
Expand Down
20 changes: 17 additions & 3 deletions src/View/Components/Widget/ProfileRowItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -53,21 +54,29 @@ class ProfileRowItem extends Component
*/
public $url;

/**
* The target element for the URL (title or text).
*
* @var string
*/
public $urlTarget;

/**
* Create a new component instance.
*
* @return void
*/
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);
$this->icon = $icon;
$this->size = $size;
$this->badge = $badge;
$this->url = $url;
$this->urlTarget = $urlTarget;
}

/**
Expand All @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions tests/Components/WidgetComponentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,25 @@ public function testInfoBoxComponentProgressAttribute()

public function testProfileColItemComponent()
{
// Test with common badge.

$component = new Components\Widget\ProfileColItem(
'title', 'text', null, null, 'b-theme'
);

$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);
}

/*
Expand All @@ -249,13 +261,25 @@ public function testProfileColItemComponent()

public function testProfileRowItemComponent()
{
// Test with common badge.

$component = new Components\Widget\ProfileRowItem(
'title', 'text', null, null, 'b-theme'
);

$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);
}

/*
Expand Down