Files
filament/packages/forms/src/Components/Section.php
T

96 lines
2.2 KiB
PHP

<?php
namespace Filament\Forms\Components;
use Closure;
use Filament\Support\Concerns\HasDescription;
use Filament\Support\Concerns\HasExtraAlpineAttributes;
use Filament\Support\Concerns\HasHeading;
use Filament\Support\Concerns\HasIcon;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Str;
class Section extends Component implements Contracts\CanConcealComponents, Contracts\CanEntangleWithSingularRelationships
{
use Concerns\CanBeCollapsed;
use Concerns\CanBeCompacted;
use Concerns\EntanglesStateWithSingularRelationship;
use HasDescription;
use HasExtraAlpineAttributes;
use HasHeading;
use HasIcon;
/**
* @var view-string
*/
protected string $view = 'filament-forms::components.section';
protected bool | Closure | null $isAside = null;
protected bool | Closure $isFormBefore = false;
final public function __construct(string | Htmlable | Closure $heading)
{
$this->heading($heading);
}
public static function make(string | Htmlable | Closure $heading): static
{
$static = app(static::class, ['heading' => $heading]);
$static->configure();
return $static;
}
protected function setUp(): void
{
parent::setUp();
$this->columnSpan('full');
}
public function aside(bool | Closure | null $condition = true): static
{
$this->isAside = $condition;
return $this;
}
public function getId(): ?string
{
$id = parent::getId();
if (! $id) {
$id = Str::slug($this->getHeading());
if ($statePath = $this->getStatePath()) {
$id = "{$statePath}.{$id}";
}
}
return $id;
}
public function canConcealComponents(): bool
{
return $this->isCollapsible();
}
public function isAside(): bool
{
return (bool) ($this->evaluate($this->isAside) ?? false);
}
public function formBefore(bool | Closure $condition = true): static
{
$this->isFormBefore = $condition;
return $this;
}
public function isFormBefore(): bool
{
return (bool) $this->evaluate($this->isFormBefore);
}
}