Skip to content

Commit

Permalink
adds partial table widget customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
eighty9nine committed Jul 28, 2024
1 parent 2c92686 commit 237fca4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
52 changes: 49 additions & 3 deletions resources/views/advanced-table-widget.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
@php
use Filament\Support\Facades\FilamentView;
$heading = $this->getHeading();
$description = $this->getDescription();
$label = $this->getLabel();
$filters = $this->getFilters();
$icon = $this->getIcon();
$iconColor = $this->getIconColor();
$iconBackgroundColor = filled($this->getIconBackgroundColor())
? match ($this->getIconBackgroundColor()) {
'primary' => 'bg-primary-200 dark:bg-primary-950',
'secondary' => 'bg-secondary-200 dark:bg-secondary-950',
'success' => 'bg-success-200 dark:bg-success-950',
'danger' => 'bg-danger-200 dark:bg-danger-950',
'warning' => 'bg-warning-200 dark:bg-warning-950',
'info' => 'bg-info-200 dark:bg-info-950',
default => 'bg-gray-200 dark:bg-gray-950',
}
: '';
$badge = $this->getBadge();
$badgeColor = $this->getBadgeColor();
$badgeIcon = $this->getBadgeIcon();
$badgeIconPosition = $this->getBadgeIconPosition();
$badgeSize = $this->getBadgeSize();
@endphp
<x-filament-widgets::widget class="fi-wi-table">
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\Widgets\View\WidgetsRenderHook::TABLE_WIDGET_START, scopes: static::class) }}

{{ $this->table }}
<x-advanced-widgets::section :description="$description" :heading="$heading" :icon="$icon" :iconColor="$iconColor"
:iconBackgroundColor="$iconBackgroundColor" :label="$label" :badge="$badge" :badgeColor="$badgeColor" :badgeIcon="$badgeIcon" :badgeIconPosition="$badgeIconPosition"
:badgeSize="$badgeSize">
@if ($filters)
<x-slot name="headerEnd">
<x-filament::input.wrapper inline-prefix wire:target="filter" class="w-max sm:-my-2">
<x-filament::input.select inline-prefix wire:model.live="filter">
@foreach ($filters as $value => $label)
<option value="{{ $value }}">
{{ $label }}
</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
</x-slot>
@endif
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\Widgets\View\WidgetsRenderHook::TABLE_WIDGET_START, scopes: static::class) }}

{{ $this->table }}

{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\Widgets\View\WidgetsRenderHook::TABLE_WIDGET_END, scopes: static::class) }}
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\Widgets\View\WidgetsRenderHook::TABLE_WIDGET_END, scopes: static::class) }}
</x-advanced-widgets::section>
</x-filament-widgets::widget>
2 changes: 2 additions & 0 deletions src/AdvancedTableWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class AdvancedTableWidget extends AdvancedWidget implements Actions\Contracts\HasActions, Forms\Contracts\HasForms, Infolists\Contracts\HasInfolists, Tables\Contracts\HasTable
{
use Concerns\CanBeCustomised,
Concerns\HasSectionContent;
use Actions\Concerns\InteractsWithActions;
use Forms\Concerns\InteractsWithForms;
use Infolists\Concerns\InteractsWithInfolists;
Expand Down
35 changes: 35 additions & 0 deletions src/Concerns/HasSectionContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace EightyNine\FilamentAdvancedWidget\Concerns;

trait HasSectionContent
{
protected static ?string $heading = null;

protected static ?string $description = null;

protected static ?string $label = null;

protected static ?array $filters = null;

public function getFilters(): ?array
{
return static::$filters;
}

public function getHeading(): ?string
{
return static::$heading;
}

public function getDescription(): ?string
{
return static::$description;
}

public function getLabel(): ?string
{
return static::$label;
}

}

0 comments on commit 237fca4

Please sign in to comment.