* zin: refactor tabs.

This commit is contained in:
dingyongliang
2023-05-24 13:29:02 +08:00
parent a4cf4b5368
commit 692004aba2
2 changed files with 17 additions and 16 deletions
+4
View File
@@ -910,6 +910,10 @@ function modalDialog()
* array items
* ?string direction='h'
* ?string activeId
*
* ====== blocks ======
* tabPanes = array()
* ====================
*/
function tabs()
{
+13 -16
View File
@@ -2,6 +2,8 @@
declare(strict_types=1);
namespace zin;
require_once dirname(__DIR__) . DS . 'tabpane' . DS . 'v1.php';
class tabs extends wg
{
protected static $defineProps = array(
@@ -11,6 +13,10 @@ class tabs extends wg
'activeID?:string'
);
protected static $defineBlocks = array(
'tabPanes' => array()
);
public static function getPageCSS(): string|false
{
return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
@@ -43,11 +49,10 @@ class tabs extends wg
{
if(!isset($item['data'])) return null;
$isActive = $this->prop('activeID') == $id || (isset($item['active']) && $item['active']);
return div
return new tabPane
(
setClass('tab-pane'),
setID($id),
$isActive ? setClass('active') : null,
set::isActive($isActive),
$item['data']
);
}
@@ -78,22 +83,14 @@ class tabs extends wg
protected function build(): wg
{
$items = $this->prop('items');
$items = $this->prop('items');
$isVertical = $this->prop('direction') === 'v';
$tabPanes = $this->block('tabPanes');
if(empty($items))
{
return div
(
set($this->props->skip(array_keys(static::getDefinedProps()))),
$isVertical ? setClass('flex') : null,
$this->children()
);
}
$labelViews = array();
$labelViews = array();
$contentViews = array();
if(is_array($tabPanes)) $contentViews = array_merge($contentViews, $tabPanes);
foreach($items as $item)
{
$id = $this->getItemID($item);