'callout'];
/**
* Create a new callout
*
* The $type parameter determines the color and icon of the callout.
*
* @param CalloutType $type The type of the callout
* @param ValidHtml|string $content The content of the callout
* @param ?string $title An optional title, displayed above the content
*/
public function __construct(
protected CalloutType $type,
protected ValidHtml|string $content,
protected ?string $title = null
) {
$this->addAttributes(Attributes::create(['class' => $type->value]));
}
protected function assemble(): void
{
$this->addHtml($this->type->getIcon());
$this->addHtml(HtmlElement::create(
'div',
['class' => 'callout-text'],
[
$this->title === null || trim($this->title) === ''
? null
: HtmlElement::create('strong', ['class' => 'callout-title'], Text::create($this->title)),
is_string($this->content) ? Text::create($this->content) : $this->content,
],
));
}
/**
* Set the callout width to 100% of its parent container
*
* Callouts are by default sized to fill their parent container.
*
* @param bool $isFitContent Whether the callout size should be dependent on its content
*
* @return $this
*/
public function setFitContent(bool $isFitContent = true): static
{
if ($isFitContent) {
$this->addAttributes(Attributes::create(['class' => static::CLASS_FIT_CONTENT]));
} else {
$this->removeAttribute('class', static::CLASS_FIT_CONTENT);
}
return $this;
}
}