diff --git a/packages/widgets/docs/02-stats-overview.md b/packages/widgets/docs/02-stats-overview.md index 80dd56420e..0fda615dc6 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.'; +} +``` diff --git a/packages/widgets/resources/views/stats-overview-widget.blade.php b/packages/widgets/resources/views/stats-overview-widget.blade.php index 1169f12a46..599fa101f9 100644 --- a/packages/widgets/resources/views/stats-overview-widget.blade.php +++ b/packages/widgets/resources/views/stats-overview-widget.blade.php @@ -1,8 +1,32 @@ @php $columns = $this->getColumns(); + $heading = $this->getHeading(); + $description = $this->getDescription(); + $hasHeading = filled($heading); + $hasDescription = filled($description); @endphp - + + @if ($hasHeading || $hasDescription) +
+ @if ($hasHeading) +

+ {{ $heading }} +

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

+ {{ $description }} +

+ @endif +
+ @endif +
getPollingInterval()) wire:poll.{{ $pollingInterval }} diff --git a/packages/widgets/src/StatsOverviewWidget.php b/packages/widgets/src/StatsOverviewWidget.php index dc946e7838..8fea2dff01 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,16 @@ class StatsOverviewWidget extends Widget return []; } + protected function getDescription(): ?string + { + return $this->description; + } + + protected function getHeading(): ?string + { + return $this->heading; + } + /** * @return array */