* zin: refactor pageheader/pageheading/dropdown components.
This commit is contained in:
+8
-14
@@ -1,13 +1,7 @@
|
||||
<?php
|
||||
namespace zin\wg;
|
||||
namespace zin;
|
||||
|
||||
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 dropdown extends \zin\core\wg
|
||||
class dropdown extends wg
|
||||
{
|
||||
static $tag = 'menu';
|
||||
|
||||
@@ -19,14 +13,14 @@ class dropdown extends \zin\core\wg
|
||||
{
|
||||
if(is_string($item))
|
||||
{
|
||||
$li = h5::li();
|
||||
$li = h::li();
|
||||
if($item === '|' or $item === 'divider') $li->addClass('menu-divider');
|
||||
else $li->addClass('menu-item')->append($item);
|
||||
|
||||
return $li;
|
||||
}
|
||||
|
||||
$li = h5::li()->addClass('menu-item');
|
||||
$li = h::li()->addClass('menu-item');
|
||||
|
||||
/* Divider. */
|
||||
if(isset($item['text']) and ($item['text'] === '|' or $item['text'] === 'divider'))
|
||||
@@ -35,17 +29,17 @@ class dropdown extends \zin\core\wg
|
||||
return $li;
|
||||
}
|
||||
|
||||
$a = h5::a();
|
||||
$a = h::a();
|
||||
|
||||
/* Avatar item. */
|
||||
if(isset($item['avatar']))
|
||||
{
|
||||
$div = h5::div()->addClass('avatar')->addClass('avatar circle primary');
|
||||
$div->append(h5::img(\zin\set('src', $item['avatar'])));
|
||||
$div = h::div()->addClass('avatar')->addClass('avatar circle primary');
|
||||
$div->append(h::img(\zin\set('src', $item['avatar'])));
|
||||
$a->append($div);
|
||||
}
|
||||
if(isset($item['url'])) $a->prop('href', $item['url']);
|
||||
if(isset($item['icon'])) $a->append(h5::i()->addClass("icon icon-{$item['icon']}"));
|
||||
if(isset($item['icon'])) $a->append(h::i()->addClass("icon icon-{$item['icon']}"));
|
||||
if(isset($item['text'])) $a->append($item['text']);
|
||||
if(isset($item['attr']))
|
||||
{
|
||||
|
||||
+19
-23
@@ -1,16 +1,8 @@
|
||||
<?php
|
||||
namespace zin\wg;
|
||||
namespace zin;
|
||||
|
||||
use \zin\core\h5;
|
||||
|
||||
require_once dirname(dirname(__DIR__)) . DS . 'core' . DS . 'wg.class.php';
|
||||
|
||||
class pageheader extends \zin\core\wg
|
||||
class pageheader extends wg
|
||||
{
|
||||
static $tag = 'header';
|
||||
|
||||
static $defaultProps = array('id' => 'header');
|
||||
|
||||
static $customprops = 'heading,navbar,toolbar';
|
||||
|
||||
public $heading;
|
||||
@@ -27,9 +19,9 @@ class pageheader extends \zin\core\wg
|
||||
* @access protected
|
||||
* @return object|string
|
||||
*/
|
||||
protected function acceptChild($child, $strAsHtml = false)
|
||||
protected function onAddChild($child, $strAsHtml = false)
|
||||
{
|
||||
if(class_exists('\zin\wg\pageheading') and $child instanceof \zin\wg\pageheading)
|
||||
if(class_exists('\zin\pageheading') and $child instanceof \zin\pageheading)
|
||||
{
|
||||
$this->heading = $child;
|
||||
return NULL;
|
||||
@@ -48,7 +40,7 @@ class pageheader extends \zin\core\wg
|
||||
}
|
||||
|
||||
/* Invoke parent method; */
|
||||
$child = parent::acceptChild($child, $strAsHtml);
|
||||
$child = parent::onAddChild($child, $strAsHtml);
|
||||
|
||||
if(!$strAsHtml && is_string($child) && !$this->props->has('name'))
|
||||
{
|
||||
@@ -67,23 +59,27 @@ class pageheader extends \zin\core\wg
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function build($isPrint = false, $parent = NULL)
|
||||
protected function build()
|
||||
{
|
||||
$builder = parent::build($isPrint, $parent);
|
||||
|
||||
$container = h5::div()->addClass('container main-header');
|
||||
$container = h::div
|
||||
(
|
||||
setClass('container main-header')
|
||||
);
|
||||
|
||||
/* Heading. */
|
||||
$container->append($this->heading);
|
||||
$container->add($this->heading);
|
||||
|
||||
/* Navigation Bar. */
|
||||
$container->append($this->navbar);
|
||||
$container->add($this->navbar);
|
||||
|
||||
/* Tool Bar. */
|
||||
$container->append($this->toolbar);
|
||||
$container->add($this->toolbar);
|
||||
|
||||
$builder->append($container);
|
||||
|
||||
return $builder;
|
||||
return h::create
|
||||
(
|
||||
'header',
|
||||
setId('header'),
|
||||
$container
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-33
@@ -1,63 +1,51 @@
|
||||
<?php
|
||||
namespace zin\wg;
|
||||
namespace zin;
|
||||
|
||||
use \zin\core\h5;
|
||||
|
||||
require_once dirname(dirname(__DIR__)) . DS . 'core' . DS . 'wg.class.php';
|
||||
|
||||
class pageheading extends \zin\core\wg
|
||||
class pageheading extends wg
|
||||
{
|
||||
static $tag = 'div';
|
||||
|
||||
static $defaultProps = array('id' => 'heading');
|
||||
|
||||
static $customProps = 'text,icon,url';
|
||||
protected static $defineProps = 'text?:string, icon?:string, url?:string';
|
||||
|
||||
/**
|
||||
* Accept child node.
|
||||
* On add child.
|
||||
*
|
||||
* @param object|string $child
|
||||
* @param bool $strAsHtml
|
||||
* @access protected
|
||||
* @return object|string
|
||||
*/
|
||||
protected function acceptChild($child, $strAsHtml = false)
|
||||
protected function onAddChild($child)
|
||||
{
|
||||
/* Invoke parent method; */
|
||||
$child = parent::acceptChild($child, $strAsHtml);
|
||||
|
||||
if(!$strAsHtml && is_string($child) && !$this->props->has('text'))
|
||||
if(is_string($child) && !$this->props->has('text'))
|
||||
{
|
||||
$this->prop('text', $child);
|
||||
return NULL;
|
||||
$this->props->set('text', $child);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build builder.
|
||||
* Build.
|
||||
*
|
||||
* @param bool $isPrint
|
||||
* @param object $parent
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function build($isPrint = false, $parent = NULL)
|
||||
protected function build()
|
||||
{
|
||||
$icon = $this->prop('icon');
|
||||
$text = $this->prop('text');
|
||||
$url = $this->prop('url');
|
||||
|
||||
$builder = parent::build($isPrint, $parent);
|
||||
$container = h::div
|
||||
(
|
||||
setId('heading'),
|
||||
setClass('primary'),
|
||||
icon(set('name', $icon))
|
||||
);
|
||||
|
||||
if(!empty($icon)) $builder->append(new icon($icon));
|
||||
/* Generate button with url. */
|
||||
if(!empty($url)) $container->add(btn($text, set('url', $url), setClass('primary')));
|
||||
else $container->add(h::span($text, setClass('text')));
|
||||
|
||||
if(empty($text)) return $builder;
|
||||
$this->add($container);
|
||||
|
||||
if(!empty($url)) $builder->append(\zin\btn($text, \zin\set('url', $url))->addClass('primary'));
|
||||
else $builder->append(h5::span($text)->addClass('text'));
|
||||
|
||||
return $builder;
|
||||
return $this->children();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user