39 lines
1006 B
PHP
39 lines
1006 B
PHP
<?php
|
|
|
|
namespace App\Filament\Infolists\Components;
|
|
|
|
use Filament\Infolists\Components\Entry;
|
|
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
|
|
|
class ExpandableHtmlEntry extends Entry implements HasEmbeddedView
|
|
{
|
|
protected int $limit = 200;
|
|
|
|
public function limit(int $limit): static
|
|
{
|
|
$this->limit = $limit;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function toEmbeddedHtml(): string
|
|
{
|
|
$state = $this->getState() ?? '';
|
|
$plain = strip_tags($state);
|
|
|
|
if (! $plain) {
|
|
return $this->wrapEmbeddedHtml('<span class="text-sm text-gray-400">-</span>');
|
|
}
|
|
|
|
if (mb_strlen($plain) <= $this->limit) {
|
|
return $this->wrapEmbeddedHtml('<div class="prose max-w-none">' . $state . '</div>');
|
|
}
|
|
|
|
$html = view('livewire.expandable-text-embed', [
|
|
'html' => $state,
|
|
'key' => 'et-' . substr(md5($state), 0, 8),
|
|
])->render();
|
|
|
|
return $this->wrapEmbeddedHtml($html);
|
|
}
|
|
} |