diff --git a/README.md b/README.md index cd80549..01440e9 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,26 @@ public static function getOverlookWidgetTitle(): string } ``` +### Customize Widget Icon + +By default, the icon will be loaded from the resource but you can override it by passing using the `icons` modifier on the plugin and passing it an array of icon names and resource names. + +```php +use Awcodes\Overlook\OverlookPlugin; + +public function panel(Panel $panel): Panel +{ + return $panel + ->plugins([ + OverlookPlugin::make() + ->icons([ + 'heroicon-o-heart' => \App\Filament\Resources\Shop\ProductResource::class, + 'heroicon-o-newspaper' => \App\Filament\Resources\Shop\OrderResource::class, + ]), + ]); +} +``` + diff --git a/src/OverlookPlugin.php b/src/OverlookPlugin.php index 39b5120..3aaf516 100644 --- a/src/OverlookPlugin.php +++ b/src/OverlookPlugin.php @@ -26,6 +26,8 @@ class OverlookPlugin implements Plugin protected int | Closure | null $sort = null; + protected array | Closure | null $icons = null; + public function getId(): string { return 'awcodes/overlook'; @@ -136,4 +138,16 @@ public function tooltips(bool | Closure | null $condition = true): static return $this; } + + public function icons(array | Closure | null $icons): static + { + $this->icons = $icons; + + return $this; + } + + public function getIcons(): array + { + return $this->evaluate($this->icons) ?? []; + } } diff --git a/src/Widgets/OverlookWidget.php b/src/Widgets/OverlookWidget.php index 2471122..c279f75 100644 --- a/src/Widgets/OverlookWidget.php +++ b/src/Widgets/OverlookWidget.php @@ -22,6 +22,8 @@ class OverlookWidget extends Widget public array $grid = []; + public array $icons = []; + /** * @throws Exception */ @@ -61,6 +63,7 @@ public function getData(): array $plugin = OverlookPlugin::get(); $includes = filled($this->includes) ? $this->includes : $plugin->getIncludes(); $excludes = filled($this->excludes) ? $this->excludes : $plugin->getExcludes(); + $icons = filled($this->icons) ? $this->icons : $plugin->getIcons(); $rawResources = filled($includes) ? $includes @@ -68,9 +71,12 @@ public function getData(): array return collect($rawResources)->filter(function ($resource) use ($excludes) { return ! in_array($resource, $excludes); - })->transform(function ($resource) { + })->transform(function ($resource) use ($icons) { + + $customIcon = array_search($resource, $icons); + $res = app($resource); - + $widgetQuery = $res->getEloquentQuery(); if ($res instanceof CustomizeOverlookWidget) { @@ -86,7 +92,7 @@ public function getData(): array 'name' => $title, 'raw_count' => $this->formatRawcount($rawCount), 'count' => $this->convertCount($rawCount), - 'icon' => $res->getNavigationIcon(), + 'icon' => $customIcon ?: $res->getNavigationIcon(), 'url' => $res->getUrl('index'), ]; }