['ball']]; /** @var SIZE */ protected $size = self::SIZE_LARGE; /** * Create a new ball element * * @param SIZE $size */ public function __construct(string $size = self::SIZE_LARGE) { $size = trim($size); if (empty($size)) { $size = self::SIZE_MEDIUM; } $this->size = $size; } /** * Register the attribute callbacks * * @param Attributes $attributes */ protected function registerAttributeCallbacks(Attributes $attributes): void { $attributes->registerAttributeCallback('class', function () { return new Attribute('class', $this->assembleCssClasses()); }); } /** * Assemble the CSS classes for the ball * * @return array */ protected function assembleCssClasses(): array { return ['ball-size-' . $this->size]; } /** * Add content to the ball * * Automatically wraps text content in a span element. * * @param ValidHtml ...$content * * @return $this */ public function addHtml(ValidHtml ...$content): static { if (count($content) === 1 && $content[0] instanceof Text) { $content[0] = new HtmlElement('span', null, $content[0]); } return parent::addHtml(...$content); } }