built in Widgets not configurable

widget's props are protected and there is no way to configure it
protected static bool $isLazy = true;

protected static ?int $sort = null;
protected static bool $isLazy = true;

protected static ?int $sort = null;
of course we can just extend it, but if there is an api like configureUsing it will be helpful and benefits plugins developer to provide customization
Solution:
to override widgets, you extend the class, make modifications, and register the new one
Jump to solution
10 Replies
awcodes
awcodes2y ago
I agree with what you are saying, but since widgets are livewire components they can’t be instantiated and therefore can’t be configured like a class can.
wyChoong
wyChoongOP2y ago
I’m not getting livewire component can’t configure
awcodes
awcodes2y ago
You can't call say ProductWidget::make(), it's not possible with a livewire component.
wyChoong
wyChoongOP2y ago
GitHub
filament/packages/support/src/Concerns/Configurable.php at 3.x · fi...
Admin panel, form builder and table builder for Laravel. Built with the TALL stack. Designed for humans. - filamentphp/filament
wyChoong
wyChoongOP2y ago
It’s for blade component which is normal class, but this approach can’t apply to livewire?
awcodes
awcodes2y ago
I still don't think that would work. I'm interested if you can think of a way to do it though.
wyChoong
wyChoongOP2y ago
i copied the code from the Configurable trait and made some modifications
// Widget.php
public function render(): View
{
$this->configure();

return view(static::$view, $this->getViewData());
}

// service provider
AccountWidget::configureUsing(function ($widget) {
$widget->columnSpan = 4;
// $widget::$isLazy = false;
});
// Widget.php
public function render(): View
{
$this->configure();

return view(static::$view, $this->getViewData());
}

// service provider
AccountWidget::configureUsing(function ($widget) {
$widget->columnSpan = 4;
// $widget::$isLazy = false;
});
some things to note - can't access protected properties - lazy props is too late to override with this approach, unless livewire provide a class property or method instead of just blade properties hey @Dan Harrin sorry for tagging you. but just want to highlight this idea if its something you would consider or already did, since if to make it work it would be breaking changes (protected -> public props) after v3 release
Dan Harrin
Dan Harrin2y ago
no, i dont think i would consider this, sorry its too hacky with Livewire interals IMO
Solution
Dan Harrin
Dan Harrin2y ago
to override widgets, you extend the class, make modifications, and register the new one
wyChoong
wyChoongOP2y ago
ok sure

Did you find this page helpful?