+ zin: add nav
This commit is contained in:
+12
-11
@@ -13,15 +13,16 @@ namespace zin;
|
||||
|
||||
require_once __DIR__ . DS . 'core' . DS . 'h.func.php';
|
||||
|
||||
function icon() {return createWg('icon', func_get_args());}
|
||||
function btn() {return createWg('btn', func_get_args());}
|
||||
function pagebase() {return createWg('pagebase', func_get_args());}
|
||||
function page() {return createWg('page', func_get_args());}
|
||||
function btngroup() {return createWg('btngroup', func_get_args());}
|
||||
function checkbox() {return createWg('checkbox', func_get_args());}
|
||||
function pagemain() {return createWg('pagemain', func_get_args());}
|
||||
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 icon() {return createWg('icon', func_get_args());}
|
||||
function btn() {return createWg('btn', func_get_args());}
|
||||
function pagebase() {return createWg('pagebase', func_get_args());}
|
||||
function page() {return createWg('page', func_get_args());}
|
||||
function btngroup() {return createWg('btngroup', func_get_args());}
|
||||
function checkbox() {return createWg('checkbox', func_get_args());}
|
||||
function pagemain() {return createWg('pagemain', func_get_args());}
|
||||
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());}
|
||||
function nav() {return createWg('nav', func_get_args());}
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace zin;
|
||||
|
||||
require_once dirname(__DIR__) . DS . 'actionitem' . DS . 'v1.php';
|
||||
|
||||
class nav extends wg
|
||||
{
|
||||
static $defineProps = 'items?:array';
|
||||
|
||||
public function onBuildItem($item)
|
||||
{
|
||||
if(!($item instanceof item)) $item = item($item);
|
||||
return actionItem
|
||||
(
|
||||
set('name', 'nav'),
|
||||
inherit($item)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return builder
|
||||
*/
|
||||
protected function build()
|
||||
{
|
||||
$items = $this->prop('items');
|
||||
return h::nav
|
||||
(
|
||||
setClass('nav'),
|
||||
set($this->props->skip(array_keys(static::getDefinedProps()))),
|
||||
is_array($items) ? array_map(array($this, 'onBuildItem'), $this->prop('items')) : NULL,
|
||||
$this->children(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
namespace zin\wg;
|
||||
|
||||
require_once dirname(dirname(__DIR__)) . DS . 'core' . DS . 'wg.class.php';
|
||||
require_once dirname(dirname(__DIR__)) . DS . 'core' . DS . 'h5.class.php';
|
||||
require_once dirname(__DIR__) . DS . 'icon' . DS . 'v1.php';
|
||||
|
||||
use \zin\core\h5;
|
||||
|
||||
class zuinav extends \zin\core\wg
|
||||
{
|
||||
static $tag = 'div';
|
||||
|
||||
static $defaultProps = array('class' => 'nav');
|
||||
|
||||
static $customProps = 'className,items,hasIcons,onRenderItem,afterRender';
|
||||
|
||||
public $cssList = array(':root{--nav-active-color: white;}');
|
||||
|
||||
protected function buildItem($item)
|
||||
{
|
||||
if (isset($item['type']) && $item['type'] === 'divider') return h5::li()->addClass('nav-divider');
|
||||
|
||||
$a = h5::a();
|
||||
if (isset($item['active']) && $item['active'] === true) $a->addClass('active');
|
||||
|
||||
$url = isset($item['url']) ? $item['url'] : NULL;
|
||||
if (!empty($url)) $a->prop('href', "$url");
|
||||
|
||||
$icon = isset($item['icon']) ? $item['icon'] : NULL;
|
||||
if (!empty($icon))
|
||||
{
|
||||
$i = h5::i()->addClass("icon icon-$icon");
|
||||
$a->append($i);
|
||||
}
|
||||
|
||||
$span = h5::span($item['text'])->addClass('text');
|
||||
$a->append($span);
|
||||
|
||||
$li = h5::li()->addClass('nav-item');
|
||||
$li->append($a);
|
||||
|
||||
return $li;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return builder
|
||||
*/
|
||||
protected function build($isPrint = false, $parent = NULL)
|
||||
{
|
||||
$builder = parent::build($isPrint, $parent);
|
||||
|
||||
$jsRender = $this->prop('js-render');
|
||||
if ($jsRender)
|
||||
{
|
||||
$id = $this->prop('id');
|
||||
$this->props->remove('id');
|
||||
$builder->jsVar('options', $this->props->data);
|
||||
$builder->js(<<<END
|
||||
domReady(() => {
|
||||
const nav = new zui.Nav('#$id', options);
|
||||
});
|
||||
END);
|
||||
}
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user