初始化仓库
This commit is contained in:
64
admin/components/UI/Widget/Icon.php
Normal file
64
admin/components/UI/Widget/Icon.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user