hyperf-view/builder/View/Components/Grid/Avatar.php

111 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Builder\View\Components\Grid;
use Builder\View\Components\GridComponent;
/**
* Class Avatar
* @package HPlus\UI\Components
*/
class Avatar extends GridComponent
{
protected $componentName = "Avatar";
protected $host = "";
/**
* @var string
*/
protected $shape = "circle";
protected $imageUrl = "";
/**
* @var string|int
*/
protected $size = '40px';
protected $autoFixFontSize =true;
protected $triggerType ='button';
protected $triggerIconStyle ='';
protected $defaultSrc;
public function __construct($value = null)
{
$this->componentValue($value);
$this->defaultSrc = config('config.default_avatar');
}
static public function make($value = null)
{
return new Avatar($value);
}
/**
* 设置头像的图标类型,参考 Icon 组件
* @param string $icon
* @return $this
*/
public function triggerIconStyle(string $icon)
{
$this->triggerIconStyle = $icon;
return $this;
}
/**
* 设置头像的大小 number
* @param int|string $size
* @return $this
*/
public function size($size)
{
$this->size = $size;
return $this;
}
/***
* 是否自动根据头像尺寸调整字体大小
* @param bool|boolean $fix
* @return $this
*/
public function autoFixFontSize(bool $fix)
{
$this->autoFixFontSize = $fix;
return $this;
}
/**
* 设置头像的形状 circle / square
* @param string $shape
* @return $this
*/
public function shape(string $shape)
{
$this->shape = $shape;
return $this;
}
/**
* 图片头像的资源地址
* @param string $src
* @return $this
*/
public function imageUrl(string $src)
{
$this->imageUrl = $src;
return $this;
}
/**
* 设置默认头像
* @param string $defaultSrc
* @return $this
*/
public function defaultSrc($defaultSrc)
{
$this->defaultSrc = $defaultSrc;
return $this;
}
}