Files
xk-api-yii/admin/components/UI/Form/Row.php
2024-09-19 11:32:39 +08:00

55 lines
1.1 KiB
PHP

<?php
namespace admin\components\UI\Form;
use admin\components\UI\Form;
/**
* Class Row
* @package backend\components\UI\Table
*/
class Row extends Composite implements Component
{
/**
* 设置列
* @param callable $callback
* @param int $width
* @return $this
*/
public function column(callable $callback, int $width = 0): self
{
$form = new Form();
$callback($form);
$this->column[] = [
'width' => $width,
'object' => $form,
];
return $this;
}
/**
* @return array
*/
public function render(): array
{
$inner = [];
foreach ($this->column as $vo) {
$width = $vo['width'] ? "lg:row-span-{$vo['width']}" : '';
$form = $vo['object']->renderForm();
$inner[] = [
'nodeName' => 'div',
'class' => $width,
'child' => $form
];
}
return [
'nodeName' => 'div',
'class' => 'grid lg:grid-flow-col gap-4',
'child' => $inner
];
}
}