orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.26k stars 631 forks source link

IconComponent issue with 14.22.0 #2830

Closed c-gross closed 1 month ago

c-gross commented 2 months ago

Describe the bug I'm using the IconComponent() component to render icon in table headers. That was working fine in orchid 14.21.0. Yesterday I tested orchid 14.22.0 and it's throwing an error now. I'm not able to update Laravel to v11 because of some dependencies so I can't test orchid 14.23.0 yet. But I guess the issue will also apply in 14.23.0 when I check the files changes.

To Reproduce TD::make('foo', (new IconComponent('bs.file-earmark-medical', '', null, '1.3em', '1.3em'))->render()())

Orchid\Icons\IconComponent::__construct(): Argument #1 ($finder) must be of type Orchid\Icons\IconFinder, string given, called in /Users/...../app/Orchid/Layouts/Order/OrderViewOrderItemLayout.php on line 144

Server (please complete the following information):

c-gross commented 2 months ago

Just saw that a new param IconFinder is required to pass and reason for my error. How can I get the IconFinder within a layout table?

tabuna commented 1 month ago

Hello! I'm sorry you've encountered this issue. It's because some components were reworked to avoid generating temporary compiled Blade files, which was impacting performance. Unfortunately, I didn't explicitly document this change and didn't anticipate its consequences.

Currently, icon rendering relies entirely on blade, so it's challenging to invoke it as you wish. Here are approximate steps:

app(IconComponent::class, [
     'path'   => 'bs.file-earmark-medical',
     'width'  => '1.3em', 
     'height' => '1.3em'
])->render()(['attributes' => []]); //  View object

Instead, it's recommended to use the rendering via Blade:

use Illuminate\Support\Facades\Blade;

Blade::render('<x-orchid-icon path="bs.file-earmark-medical"/>');
c-gross commented 1 month ago

Thank you, that did help alot. To use it for the table heading I only had to add ->__toString() at the end to avoid the "must be string" error and it's working.

Still hope for the icon feature for tables #2732 ;)