Files
xk-api-yii/admin/components/UI/Widget/Icon.php
2024-09-19 11:32:39 +08:00

65 lines
1.3 KiB
PHP

<?php
namespace admin\components\UI\Widget;
use admin\components\UI\Widget\Append\Element;
/**
*图标组件
* @package backend\components\UI\Widget
*/
class Icon extends Widget
{
use Element;
private string $content;
private bool $layout = false;
private int $size;
/**
* @param string $content
* @param callable|null $callback
*/
public function __construct(string $content, ?callable $callback = null)
{
$this->content = $content;
$this->callback = $callback;
}
/**
* 设置大小
* @param int $size
* @return $this
*/
public function size(int $size): self
{
$this->size = $size;
return $this;
}
/**
* @return array
*/
public function render(): array
{
$icon = $this->content;
if (strpos($icon, '<svg') !== false) {
return [
'nodeName' => 'n-icon',
'size' => $this->size,
'child' => [
'nodeName' => 'rich-text',
'class' => implode(' ', $this->class),
'nodes' => $icon
]
];
}
return [
'nodeName' => 'icon-' . $icon,
'class' => implode(' ', $this->class),
];
}
}