+ zin: add riskLabel wg.

This commit is contained in:
dingyongliang
2023-05-18 14:02:59 +08:00
parent 8b6c630013
commit bab9859a02
3 changed files with 56 additions and 0 deletions
+11
View File
@@ -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());
}
+1
View File
@@ -0,0 +1 @@
.risk-label {font-size: 14px; font-weight: 400;}
+44
View File
@@ -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
);
}
}