mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
WIP
This commit is contained in:
@@ -45,11 +45,12 @@ class ComponentContainer extends ViewComponent
|
||||
protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array
|
||||
{
|
||||
return match ($parameterName) {
|
||||
'record' => [$this->getRecord()],
|
||||
'livewire' => [$this->getLivewire()],
|
||||
'record' => [$this->getRecord()],
|
||||
default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Tests\Infolists\Fixtures;
|
||||
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Infolists\Concerns\InteractsWithInfolists;
|
||||
use Filament\Infolists\Contracts\HasInfolists;
|
||||
use Livewire\Component;
|
||||
|
||||
class Livewire extends Component implements HasForms, HasInfolists
|
||||
{
|
||||
use InteractsWithForms;
|
||||
use InteractsWithInfolists;
|
||||
|
||||
public $data;
|
||||
|
||||
public static function make(): static
|
||||
{
|
||||
return new static;
|
||||
}
|
||||
|
||||
public function data($data): static
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use Filament\Infolists;
|
||||
use Filament\Tests\Infolists\Fixtures\Livewire;
|
||||
use Filament\Tests\TestCase;
|
||||
|
||||
use function Filament\Tests\livewire;
|
||||
|
||||
uses(TestCase::class);
|
||||
|
||||
it('can inject the correct `$livewire` for infolists outside a panel', function () {
|
||||
livewire(TestComponentWithInfolist::class)
|
||||
->assertOk()
|
||||
->assertSee('First Entry Label')
|
||||
->assertSee('First Entry State')
|
||||
->assertSee('Second Entry Label')
|
||||
->assertSee('Second Entry State');
|
||||
});
|
||||
|
||||
class TestComponentWithInfolist extends Livewire
|
||||
{
|
||||
public function mount(): void
|
||||
{
|
||||
$this->data([
|
||||
'first_entry' => 'First Entry State',
|
||||
'second_entry' => 'Second Entry State',
|
||||
]);
|
||||
}
|
||||
|
||||
public function infolist(Infolists\Infolist $infolist): Infolists\Infolist
|
||||
{
|
||||
return $infolist
|
||||
->state($this->data)
|
||||
->schema(function (TestComponentWithInfolist $livewire) {
|
||||
expect($livewire)->toBe($this);
|
||||
|
||||
return [
|
||||
Infolists\Components\TextEntry::make('first_entry')
|
||||
->label('First Entry Label'),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function infolistWithCustomName(Infolists\Infolist $infolist): Infolists\Infolist
|
||||
{
|
||||
return $infolist
|
||||
->state($this->data)
|
||||
->schema(function (TestComponentWithInfolist $livewire) {
|
||||
expect($livewire)->toBe($this);
|
||||
|
||||
return [
|
||||
Infolists\Components\TextEntry::make('second_entry')
|
||||
->label('Second Entry Label'),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return <<<'BLADE'
|
||||
{{ $this->infolist }}
|
||||
{{ $this->infolistWithCustomName }}
|
||||
BLADE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user