+ zin: add riskLabel wg.
This commit is contained in:
@@ -1131,3 +1131,14 @@ function commentForm()
|
||||
{
|
||||
return createWg('commentForm', func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Zentao risk label wg.
|
||||
*
|
||||
* ?string text
|
||||
* ?string level 'h'|'m'|'l'
|
||||
*/
|
||||
function riskLabel()
|
||||
{
|
||||
return createWg('riskLabel', func_get_args());
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.risk-label {font-size: 14px; font-weight: 400;}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace zin;
|
||||
|
||||
class riskLabel extends wg
|
||||
{
|
||||
protected static $defineProps = array(
|
||||
'string?:text', // 标签文本
|
||||
'string?:level' // 等级:高('h')、中('m')、低('l')
|
||||
);
|
||||
|
||||
public static function getPageCSS(): string|false
|
||||
{
|
||||
return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
|
||||
}
|
||||
|
||||
protected function onAddChild(mixed $child): mixed
|
||||
{
|
||||
if(is_string($child) && !$this->props->has('text'))
|
||||
{
|
||||
$this->props->set('text', $child);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function setThemeStyle(): \zin\directive
|
||||
{
|
||||
$level = $this->prop('level');
|
||||
if($level === 'h') return setClass('text-danger');
|
||||
if($level === 'm') return setClass('text-warning');
|
||||
return setStyle('color', 'var(--color-slate-800)');
|
||||
}
|
||||
|
||||
protected function build(): wg
|
||||
{
|
||||
$text = $this->prop('text');
|
||||
return span
|
||||
(
|
||||
setClass('risk-label'),
|
||||
$this->setThemeStyle(),
|
||||
$text
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user