增加 InfoBox 组件
parent
ee06382d9f
commit
f046e3a4d3
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Widgets;
|
||||
|
||||
use Dcat\Admin\Widgets\Widget;
|
||||
|
||||
class InfoBox extends Widget
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $view = 'admin::widgets.info-box';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'primary';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $icon;
|
||||
|
||||
public function __construct(string $title, string $content, ?string $icon = null)
|
||||
{
|
||||
$this->title($title);
|
||||
$this->content($content);
|
||||
$this->icon($icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Info Box 图标
|
||||
*
|
||||
* @param string $icon
|
||||
* @return $this
|
||||
*/
|
||||
public function icon(string $icon = null)
|
||||
{
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Info Box 内容
|
||||
*
|
||||
* @param string $content
|
||||
* @return $this
|
||||
*/
|
||||
public function content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Info Box 标题
|
||||
*
|
||||
* @param string $title
|
||||
* @return $this
|
||||
*/
|
||||
public function title($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add style.
|
||||
*
|
||||
* @param string $style
|
||||
* @return $this
|
||||
*/
|
||||
public function style($style = 'info')
|
||||
{
|
||||
$this->style = $style;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Variables in view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function defaultVariables()
|
||||
{
|
||||
$this->class('info-box');
|
||||
|
||||
return [
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'icon' => $this->icon,
|
||||
'style' => $this->style,
|
||||
'attributes' => $this->formatHtmlAttributes(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<style>
|
||||
.info-box {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.info-box .info-box-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
line-height: 2;
|
||||
padding: 0 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.info-box .info-box-number {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div {!! $attributes !!}>
|
||||
@if($icon)
|
||||
<span class="info-box-icon bg-{{ $style }}">
|
||||
<i class="{{ $icon }}"></i>
|
||||
</span>
|
||||
@endif
|
||||
|
||||
<div class="info-box-content">
|
||||
<span class="info-box-text">{{ $title }}</span>
|
||||
<span class="info-box-number">{!! $content !!}</span>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Reference in New Issue