From eeb4f6ae700fe9bc6c72d3c701300ccfe7d1ccd4 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Wed, 13 Nov 2024 13:10:33 +0000 Subject: [PATCH 1/6] Widgets/StatsOverview: Add support for heading and description --- .../views/stats-overview-widget.blade.php | 18 ++++++++++++++ packages/widgets/src/StatsOverviewWidget.php | 24 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/widgets/resources/views/stats-overview-widget.blade.php b/packages/widgets/resources/views/stats-overview-widget.blade.php index 1169f12a467..e5669bf26ef 100644 --- a/packages/widgets/resources/views/stats-overview-widget.blade.php +++ b/packages/widgets/resources/views/stats-overview-widget.blade.php @@ -1,8 +1,26 @@ @php $columns = $this->getColumns(); + $hasHeading = $this->hasHeading(); + $hasDescription = $this->hasDescription(); @endphp + @if($hasHeading || $hasDescription) +
+ @if($hasHeading) +

+ {{ $this->getHeading() }} +

+ @endif + + @if($hasDescription) +

+ {{ $this->getDescription() }} +

+ @endif +
+ @endif +
getPollingInterval()) wire:poll.{{ $pollingInterval }} diff --git a/packages/widgets/src/StatsOverviewWidget.php b/packages/widgets/src/StatsOverviewWidget.php index dc946e78380..26a2a259d25 100644 --- a/packages/widgets/src/StatsOverviewWidget.php +++ b/packages/widgets/src/StatsOverviewWidget.php @@ -15,6 +15,10 @@ class StatsOverviewWidget extends Widget protected int | string | array $columnSpan = 'full'; + protected ?string $heading = null; + + protected ?string $description = null; + /** * @var view-string */ @@ -53,6 +57,26 @@ protected function getCards(): array return []; } + protected function hasHeading(): bool + { + return $this->heading !== null; + } + + protected function hasDescription(): bool + { + return $this->description !== null; + } + + protected function getDescription(): ?string + { + return $this->description; + } + + protected function getHeading(): ?string + { + return $this->heading; + } + /** * @return array */ From 5d91f105f2cce617ab5f108bc0161978be6be5ed Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Wed, 13 Nov 2024 13:20:44 +0000 Subject: [PATCH 2/6] Widgets/StatsOverview: Tidy up existence logic --- .../widgets/resources/views/stats-overview-widget.blade.php | 4 ++-- packages/widgets/src/StatsOverviewWidget.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/widgets/resources/views/stats-overview-widget.blade.php b/packages/widgets/resources/views/stats-overview-widget.blade.php index e5669bf26ef..51d4fbc5f1d 100644 --- a/packages/widgets/resources/views/stats-overview-widget.blade.php +++ b/packages/widgets/resources/views/stats-overview-widget.blade.php @@ -4,9 +4,9 @@ $hasDescription = $this->hasDescription(); @endphp - + @if($hasHeading || $hasDescription) -
+
@if($hasHeading)

{{ $this->getHeading() }} diff --git a/packages/widgets/src/StatsOverviewWidget.php b/packages/widgets/src/StatsOverviewWidget.php index 26a2a259d25..8452c070ef7 100644 --- a/packages/widgets/src/StatsOverviewWidget.php +++ b/packages/widgets/src/StatsOverviewWidget.php @@ -59,12 +59,12 @@ protected function getCards(): array protected function hasHeading(): bool { - return $this->heading !== null; + return filled($this->heading); } protected function hasDescription(): bool { - return $this->description !== null; + return filled($this->description); } protected function getDescription(): ?string From 686d4972800d6bcbbe0950ab68eed4d1d427eb53 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Wed, 13 Nov 2024 13:22:58 +0000 Subject: [PATCH 3/6] Misc: Fmt --- .../views/stats-overview-widget.blade.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/widgets/resources/views/stats-overview-widget.blade.php b/packages/widgets/resources/views/stats-overview-widget.blade.php index 51d4fbc5f1d..15ae5a23077 100644 --- a/packages/widgets/resources/views/stats-overview-widget.blade.php +++ b/packages/widgets/resources/views/stats-overview-widget.blade.php @@ -5,16 +5,20 @@ @endphp - @if($hasHeading || $hasDescription) + @if ($hasHeading || $hasDescription)
- @if($hasHeading) -

+ @if ($hasHeading) +

{{ $this->getHeading() }}

@endif - @if($hasDescription) -

+ @if ($hasDescription) +

{{ $this->getDescription() }}

@endif From e22713bbb9524eb4995bc0fb420f3f894a4d10fd Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Wed, 13 Nov 2024 13:59:47 +0000 Subject: [PATCH 4/6] Widgets/StatsOverview/Docs: Add docs for header and description --- packages/widgets/docs/02-stats-overview.md | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/widgets/docs/02-stats-overview.md b/packages/widgets/docs/02-stats-overview.md index 80dd56420ee..084da7ab9de 100644 --- a/packages/widgets/docs/02-stats-overview.md +++ b/packages/widgets/docs/02-stats-overview.md @@ -165,3 +165,27 @@ To disable this behavior, you may override the `$isLazy` property on the widget ```php protected static bool $isLazy = false; ``` + +## Adding a header and description + +You may also add a header and description text above the widget by overriding the `$header` and `$description` properties. + +```php +protected ?string $header = 'Analytics'; + +protected ?string $description = 'An overview of some analytics.'; +``` + +If you need to dynamically generated the header or description text, you can instead override the `getHeader()` and `getDescription()` methods. + +```php +protected function getHeader(): ?string +{ + return 'Analytics'; +} + +protected function getDescription(): ?string +{ + return 'An overview of some analytics.'; +} +``` From 4c0e5d91a252c08cc5d69d2509606bc95c755880 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Wed, 13 Nov 2024 14:01:26 +0000 Subject: [PATCH 5/6] Widgets/StatsOverview: Remove useless has* methods --- .../resources/views/stats-overview-widget.blade.php | 10 ++++++---- packages/widgets/src/StatsOverviewWidget.php | 10 ---------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/widgets/resources/views/stats-overview-widget.blade.php b/packages/widgets/resources/views/stats-overview-widget.blade.php index 15ae5a23077..599fa101f92 100644 --- a/packages/widgets/resources/views/stats-overview-widget.blade.php +++ b/packages/widgets/resources/views/stats-overview-widget.blade.php @@ -1,7 +1,9 @@ @php $columns = $this->getColumns(); - $hasHeading = $this->hasHeading(); - $hasDescription = $this->hasDescription(); + $heading = $this->getHeading(); + $description = $this->getDescription(); + $hasHeading = filled($heading); + $hasDescription = filled($description); @endphp @@ -11,7 +13,7 @@

- {{ $this->getHeading() }} + {{ $heading }}

@endif @@ -19,7 +21,7 @@ class="fi-wi-stats-overview-header-heading col-span-full text-base font-semibold

- {{ $this->getDescription() }} + {{ $description }}

@endif
diff --git a/packages/widgets/src/StatsOverviewWidget.php b/packages/widgets/src/StatsOverviewWidget.php index 8452c070ef7..8fea2dff019 100644 --- a/packages/widgets/src/StatsOverviewWidget.php +++ b/packages/widgets/src/StatsOverviewWidget.php @@ -57,16 +57,6 @@ protected function getCards(): array return []; } - protected function hasHeading(): bool - { - return filled($this->heading); - } - - protected function hasDescription(): bool - { - return filled($this->description); - } - protected function getDescription(): ?string { return $this->description; From 0cd4a48000c27f2b1492b925028d259bd3195119 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Wed, 13 Nov 2024 14:18:00 +0000 Subject: [PATCH 6/6] Update 02-stats-overview.md --- packages/widgets/docs/02-stats-overview.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/widgets/docs/02-stats-overview.md b/packages/widgets/docs/02-stats-overview.md index 084da7ab9de..0fda615dc6b 100644 --- a/packages/widgets/docs/02-stats-overview.md +++ b/packages/widgets/docs/02-stats-overview.md @@ -168,7 +168,7 @@ protected static bool $isLazy = false; ## Adding a header and description -You may also add a header and description text above the widget by overriding the `$header` and `$description` properties. +You may also add a header and description text above the widget by overriding the `$header` and `$description` properties: ```php protected ?string $header = 'Analytics'; @@ -176,7 +176,7 @@ protected ?string $header = 'Analytics'; protected ?string $description = 'An overview of some analytics.'; ``` -If you need to dynamically generated the header or description text, you can instead override the `getHeader()` and `getDescription()` methods. +If you need to dynamically generated the header or description text, you can instead override the `getHeader()` and `getDescription()` methods: ```php protected function getHeader(): ?string