fix smallstatblock

This commit is contained in:
Charles 2025-04-25 13:20:32 -04:00
parent 795102457f
commit fbf1a5cc59
3 changed files with 46 additions and 38 deletions

View File

@ -2,48 +2,60 @@
namespace App\Filament\Server\Components;
use BackedEnum;
use Closure;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Filament\Schemas\Components\Component;
use Filament\Schemas\Components\Concerns\CanOpenUrl;
use Filament\Schemas\Components\Concerns\HasDescription;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;
class SmallStatBlock extends Stat
class SmallStatBlock extends Component
{
protected string|\Closure|Htmlable|null $label;
use CanOpenUrl;
use HasDescription;
protected $value;
protected string $view = 'filament.components.server-small-data-block';
public function label(string|Htmlable|Closure|null $label): static
protected string|BackedEnum|null $icon = null;
protected string $value;
final public function __construct(string $label, string $value)
{
$this->label = $label;
$this->label($label);
$this->value($value);
}
/**
* @return SmallStatBlock
*/
public static function make(string $label, string $value): static
{
return app(static::class, ['label' => $label, 'value' => $value]);
}
public function icon(string|BackedEnum|null $icon): static
{
$this->icon = $icon;
return $this;
}
public function value($value): static
/**
* @return SmallStatBlock
*/
private function value(string $value): static
{
$this->value = $value;
return $this;
}
public function getLabel(): string|Htmlable
{
return $this->label;
}
/**
* @return scalar | Htmlable | Closure
*/
public function getValue(): mixed
{
return value($this->value);
}
public function toHtml(): string
{
return $this->render()->render();
}
public function render(): View
{
return view('filament.components.server-small-data-block');
}
}

View File

@ -4,15 +4,16 @@ namespace App\Filament\Server\Components;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;
class StatBlock extends Stat
{
protected string|\Closure|Htmlable|null $label;
protected string $view = 'filament.components.server-data-block';
protected $value;
public function label(string|Htmlable $label): static
public function label(string $label): static
{
$this->label = $label;
@ -26,7 +27,7 @@ class StatBlock extends Stat
return $this;
}
public function getLabel(): string|Htmlable
public function getLabel(): string
{
return $this->label;
}
@ -40,9 +41,4 @@ class StatBlock extends Stat
{
return $this->render()->render();
}
public function render(): View
{
return view('filament.components.server-data-block', $this->data());
}
}

View File

@ -3,10 +3,10 @@
namespace App\Filament\Server\Widgets;
use App\Enums\ContainerStatus;
use App\Filament\Server\Components\SmallStatBlock;
use App\Models\Server;
use Carbon\CarbonInterface;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Number;
class ServerOverview extends StatsOverviewWidget
@ -18,18 +18,18 @@ class ServerOverview extends StatsOverviewWidget
protected function getStats(): array
{
return [
Stat::make('Name', $this->server->name)
SmallStatBlock::make('Name', $this->server->name)
->extraAttributes([
'class' => 'overflow-x-auto',
]),
Stat::make('Status', $this->status()),
Stat::make('Address', $this->server->allocation->address)
SmallStatBlock::make('Status', $this->status()),
SmallStatBlock::make('Address', $this->server->allocation->address)
->extraAttributes([
'class' => 'overflow-x-auto',
]),
Stat::make('CPU', $this->cpuUsage()),
Stat::make('Memory', $this->memoryUsage()),
Stat::make('Disk', $this->diskUsage()),
SmallStatBlock::make('CPU', $this->cpuUsage()),
SmallStatBlock::make('Memory', $this->memoryUsage()),
SmallStatBlock::make('Disk', $this->diskUsage()),
];
}