From e90880331fbb01270aae48c87fac9da7296a372f Mon Sep 17 00:00:00 2001 From: dingyongliang Date: Mon, 22 May 2023 15:50:07 +0800 Subject: [PATCH] * zin: refactor labels. --- lib/zin/wg/prilabel/v1.php | 4 ++-- lib/zin/wg/risklabel/css/v1.css | 1 - lib/zin/wg/risklabel/v1.php | 6 +++--- lib/zin/wg/severitylabel/css/v1.css | 1 - lib/zin/wg/severitylabel/v1.php | 23 +++++++++-------------- 5 files changed, 14 insertions(+), 21 deletions(-) delete mode 100644 lib/zin/wg/risklabel/css/v1.css delete mode 100644 lib/zin/wg/severitylabel/css/v1.css diff --git a/lib/zin/wg/prilabel/v1.php b/lib/zin/wg/prilabel/v1.php index 914ca37268..210b9edd16 100644 --- a/lib/zin/wg/prilabel/v1.php +++ b/lib/zin/wg/prilabel/v1.php @@ -5,7 +5,7 @@ namespace zin; class priLabel extends wg { protected static $defineProps = array( - 'pri:int|string' + 'pri: int|string' ); protected function onAddChild(mixed $child): mixed @@ -19,7 +19,7 @@ class priLabel extends wg protected function build(): wg { - $pri = (int)$this->prop('pri'); + $pri = $this->prop('pri'); return span ( diff --git a/lib/zin/wg/risklabel/css/v1.css b/lib/zin/wg/risklabel/css/v1.css deleted file mode 100644 index e3b8545b7f..0000000000 --- a/lib/zin/wg/risklabel/css/v1.css +++ /dev/null @@ -1 +0,0 @@ -.risk-label {font-size: 14px; font-weight: 400;} diff --git a/lib/zin/wg/risklabel/v1.php b/lib/zin/wg/risklabel/v1.php index dec9a03c08..4eaf21dbba 100644 --- a/lib/zin/wg/risklabel/v1.php +++ b/lib/zin/wg/risklabel/v1.php @@ -5,8 +5,8 @@ namespace zin; class riskLabel extends wg { protected static $defineProps = array( - 'text?:string', // 标签文本 - 'level?:string' // 风险等级:高('high' 或 'h')、中('middle' 或 'm')、低('low' 或 'l') + 'text?: string', // 标签文本 + 'level?: string' // 风险等级:高('high' 或 'h')、中('middle' 或 'm')、低('low' 或 'l') ); public static function getPageCSS(): string|false @@ -37,7 +37,7 @@ class riskLabel extends wg return span ( set($this->props->skip(array_keys(static::getDefinedProps()))), - setClass('risk-label', $this->getThemeClass()), + setClass($this->getThemeClass()), $text ); } diff --git a/lib/zin/wg/severitylabel/css/v1.css b/lib/zin/wg/severitylabel/css/v1.css deleted file mode 100644 index 0b578e7dca..0000000000 --- a/lib/zin/wg/severitylabel/css/v1.css +++ /dev/null @@ -1 +0,0 @@ -.severity-level {font-size: 14px; font-weight: 400;} diff --git a/lib/zin/wg/severitylabel/v1.php b/lib/zin/wg/severitylabel/v1.php index f19aaed4e5..a372ed322c 100644 --- a/lib/zin/wg/severitylabel/v1.php +++ b/lib/zin/wg/severitylabel/v1.php @@ -5,8 +5,9 @@ namespace zin; class severityLabel extends wg { protected static $defineProps = array( - 'text?:string', // 标签文本 - 'level?:string|int' // 严重程度等级 1|2|3|4 + 'text?: string', // 标签文本 + 'level?: string|int', // 严重程度等级 + 'isIcon?: bool=false' // 是否显示为图标 ); protected function onAddChild(mixed $child): mixed @@ -18,23 +19,17 @@ class severityLabel extends wg } } - private function setThemeStyle(): \zin\directive - { - $level = (int)$this->prop('level'); - if($level === 1) return setClass('text-danger'); - if($level === 2) return setClass('text-warning'); - if($level === 3) return setClass('text-secondary'); - return setStyle('color', 'var(--color-slate-800)'); - } - protected function build() { - $text = $this->prop('text'); + $text = $this->prop('text'); + $level = $this->prop('level'); + $isIcon = $this->prop('isIcon'); + return span ( set($this->props->skip(array_keys(static::getDefinedProps()))), - setClass('severity-label'), - $this->setThemeStyle(), + setClass($isIcon ? 'severity' : 'severity severity-label'), + set('data-severity', $level), $text ); }