* zin: support for setting props with control prop.

This commit is contained in:
sunhao
2024-03-05 16:00:01 +08:00
parent 6e5e7ed4be
commit 0b3ad6800d
2 changed files with 29 additions and 10 deletions
+1
View File
@@ -33,6 +33,7 @@ function formBatch(): formBatch {return createWg('formBatch', func_get_args());}
function formBatchItem(): formBatchItem {return createWg('formBatchItem', func_get_args());}
function formBatchPanel(): formBatchPanel {return createWg('formBatchPanel', func_get_args());}
function batchActions(): batchActions {return createWg('batchActions', func_get_args());}
function content(): content {return createWg('content', func_get_args());}
function listItem(): listItem {return createWg('listitem', func_get_args());}
function breadcrumb(): breadcrumb {return createWg('breadcrumb', func_get_args());}
function control(): control {return createWg('control', func_get_args());}
+28 -10
View File
@@ -6,10 +6,18 @@ class content extends wg
{
protected static array $defineProps = array
(
'control?: string', // 内容类型,值可以为:html, text 以及其他部件的类型。
'control?: string|array', // 内容类型,值可以为:html, text 以及其他部件的类型,也可以指定为包含 `control` 键值的控件属性数组。
'render?: callable|Closure' // 自定义构建函数。
);
protected static array $controlMap = array
(
'list' => 'simpleList',
'status' => 'statusLabel',
'pri' => 'priLabel',
'severity' => 'severityLabel',
);
protected function buildText(): node
{
return div
@@ -41,11 +49,6 @@ class content extends wg
);
}
protected function buildList(): node
{
return new simpleList(set($this->props->skip('control')), $this->children());
}
protected function buildDivider(): node
{
return hr(setClass('divider'));
@@ -60,13 +63,28 @@ class content extends wg
$control = $this->prop('control');
if($control)
{
$methodName = "build{$control}";
$controlProps = array();
$controlName = '';
if(is_string($control))
{
$controlName = $control;
}
elseif(is_array($control))
{
$controlName = $control['control'];
unset($control['control']);
$controlProps = $control;
}
$methodName = "build{$controlName}";
if(method_exists($this, $methodName)) return $this->$methodName();
$wgName = "\\zin\\$control";
if(class_exists($wgName)) return new $wgName(set($this->props->skip('control')), $this->children());
if(isset(static::$controlMap[$controlName])) $controlName = static::$controlMap[$controlName];
return createWg($control, set($this->props->skip('control')), 'div');
$wgName = "\\zin\\$controlName";
if(class_exists($wgName)) return new $wgName(set($this->props->skip('controlName')), $controlProps ? set($controlProps) : null, $this->children());
return createWg($controlName, set($this->props->skip('control')), $controlProps ? set($controlProps) : null, 'div');
}
if($this->hasProp('children')) $this->prop('children');