+ zin: add new widget actionItem

This commit is contained in:
Hao Sun
2023-02-15 17:43:07 +08:00
parent 982fd07a64
commit 1977ced1dc
2 changed files with 37 additions and 0 deletions
+1
View File
@@ -24,3 +24,4 @@ function row() {return createWg('row', func_get_args());}
function column() {return createWg('column', func_get_args());}
function center() {return createWg('center', func_get_args());}
function cell() {return createWg('cell', func_get_args());}
function actionItem() {return createWg('actionitem', func_get_args());}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace zin;
class actionItem extends wg
{
static $defineProps = 'name:string="action", type:string="item", outerTag:string="li", tagName:string="a", icon?:string, text?:string, url?:string, target?:string, active?:bool, disabled?:bool, trailingIcon?:string, outerProps?:array';
protected function buildItem()
{
list($tagName, $icon, $text, $trailingIcon) = $this->prop('tagName', 'icon', 'text', 'trailingIcon');
return h::create
(
$tagName,
set($text),
set($this->props->skip(array_keys(actionItem::getDefinedProps()))),
$icon ? icon($icon) : NULL,
$this->children(),
$trailingIcon ? icon($trailingIcon) : NULL,
);
}
protected function build()
{
list($name, $type, $outerTag, $tagName, $url, $target, $active, $disabled, $outerProps) = $this->prop('name', 'type', 'outerTag', 'tagName', 'url', 'target', 'active', 'disabled', 'outerProps');
return h::create
(
$outerTag,
set($tagName === 'a' ? array('href' => $url, 'target' => $target) : array('data-url' => $url, 'data-target' => $target)),
setClass("$name-$type"),
setClass(array('active' => $active, 'disabled' => $disabled)),
set($outerProps),
$this->buildItem()
);
}
}