Merge branch 'zin_dev' of https://gitlab.zcorp.cc/easycorp/zentaopms into zin_dev
This commit is contained in:
+57
-25
@@ -1,11 +1,23 @@
|
||||
<?php
|
||||
namespace zin;
|
||||
|
||||
require_once dirname(__DIR__) . DS . 'icon' . DS . 'v1.php';
|
||||
|
||||
class btn extends wg
|
||||
{
|
||||
static $defineProps = 'icon?:string, text?:string, square?:bool, disabled?:bool, active?:bool, url?:string, target?:string, size?:string|number, trailingIcon?:string, caret?:string|bool, hint?:string, type?:string';
|
||||
static $defineProps = array
|
||||
(
|
||||
'icon?:string',
|
||||
'text?:string',
|
||||
'square?:bool',
|
||||
'disabled?:bool',
|
||||
'active?:bool',
|
||||
'url?:string',
|
||||
'target?:string',
|
||||
'size?:string|number',
|
||||
'trailingIcon?:string',
|
||||
'caret?:string|bool',
|
||||
'hint?:string',
|
||||
'type?:string'
|
||||
);
|
||||
|
||||
public function onAddChild($child)
|
||||
{
|
||||
@@ -16,20 +28,17 @@ class btn extends wg
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return builder
|
||||
*/
|
||||
protected function build()
|
||||
private function getProps()
|
||||
{
|
||||
$props = $this->props->skip(array_keys(static::getDefinedProps()));
|
||||
|
||||
$url = $this->prop('url');
|
||||
$target = $this->prop('target');
|
||||
$url = $this->prop('url');
|
||||
$target = $this->prop('target');
|
||||
|
||||
if(empty($url))
|
||||
{
|
||||
$props['type'] = $this->prop('type', 'button');
|
||||
if(!isset($props['data-url'])) $props['data-url'] = $url;
|
||||
if(!isset($props['data-url'])) $props['data-url'] = $url;
|
||||
if(!isset($props['data-target'])) $props['data-target'] = $target;
|
||||
}
|
||||
else
|
||||
@@ -40,37 +49,60 @@ class btn extends wg
|
||||
}
|
||||
$props['title'] = $this->prop('hint');
|
||||
|
||||
return $props;
|
||||
}
|
||||
|
||||
private function getChildren()
|
||||
{
|
||||
$caret = $this->prop('caret');
|
||||
$text = $this->prop('text');
|
||||
$icon = $this->prop('icon');
|
||||
$trailingIcon = $this->prop('trailingIcon');
|
||||
|
||||
$children = array();
|
||||
if(!empty($icon)) $children[] = icon($icon);
|
||||
if(!empty($text)) $children[] = h::span($text, setClass('text'));
|
||||
$children[] = parent::build();
|
||||
if(!empty($trailingIcon)) $children[] = icon($trailingIcon);
|
||||
if(!empty($caret)) $children[] = h::span(setClass(is_string($caret) ? "caret-$caret" : 'caret'));
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
private function getClassList()
|
||||
{
|
||||
$caret = $this->prop('caret');
|
||||
$text = $this->prop('text');
|
||||
$icon = $this->prop('icon');
|
||||
$trailingIcon = $this->prop('trailingIcon');
|
||||
$square = $this->prop('square');
|
||||
$isEmptyText = empty($text);
|
||||
$onlyCaret = $isEmptyText && !empty($caret) && empty($icon) && empty($trailingIcon);
|
||||
$onlyCaret = empty($text) && !empty($caret) && empty($icon) && empty($trailingIcon);
|
||||
|
||||
$classList = array
|
||||
(
|
||||
'disabled' => $this->prop('disabled'),
|
||||
'active' => $this->prop('active'),
|
||||
'btn' => true,
|
||||
'disabled' => $this->prop('disabled'),
|
||||
'active' => $this->prop('active'),
|
||||
'btn-caret' => $onlyCaret,
|
||||
'square' => $square
|
||||
'square' => $this->prop('square')
|
||||
);
|
||||
|
||||
$size = $this->prop('size');
|
||||
if(!empty($size)) $classList["size-$size"] = true;
|
||||
|
||||
$children = array();
|
||||
if(!empty($icon)) $children[] = new icon($icon);
|
||||
if(!empty($text)) $children[] = h::span($text, setClass('text'));
|
||||
return $classList;
|
||||
}
|
||||
|
||||
$children[] = parent::build();
|
||||
/**
|
||||
* @return builder
|
||||
*/
|
||||
protected function build()
|
||||
{
|
||||
$props = $this->getProps();
|
||||
$children = $this->getChildren();
|
||||
$classList = $this->getClassList();
|
||||
|
||||
if(!empty($trailingIcon)) $children[] = new icon($trailingIcon);
|
||||
if(!empty($caret)) $children[] = h::span(setClass(is_string($caret) ? "caret-$caret" : 'caret'));
|
||||
|
||||
return h::button
|
||||
return button
|
||||
(
|
||||
setClass('btn'),
|
||||
set($props),
|
||||
setClass($classList),
|
||||
$children
|
||||
|
||||
+16
-12
@@ -5,18 +5,6 @@ class icon extends wg
|
||||
{
|
||||
protected static $defineProps = 'name:string, size?:string|number';
|
||||
|
||||
protected function build()
|
||||
{
|
||||
list($name, $size) = $this->prop(array('name', 'size'));
|
||||
return h::i
|
||||
(
|
||||
setClass('icon', empty($name) ? NULL : "icon-$name"),
|
||||
is_numeric($size) ? setStyle('font-size', "{$size}px") : (is_string($size) ? setClass("size-$size") : NULL),
|
||||
set($this->props->skip(array_keys(icon::getDefinedProps()))),
|
||||
$this->children()
|
||||
);
|
||||
}
|
||||
|
||||
public function onAddChild($child)
|
||||
{
|
||||
if(is_string($child) && !$this->props->has('name'))
|
||||
@@ -25,4 +13,20 @@ class icon extends wg
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function build()
|
||||
{
|
||||
list($name, $size) = $this->prop(array('name', 'size'));
|
||||
return h::i
|
||||
(
|
||||
setClass('icon', empty($name) ? NULL : "icon-$name"),
|
||||
is_numeric($size)
|
||||
? setStyle('font-size', "{$size}px")
|
||||
: (is_string($size)
|
||||
? setClass("icon-$size")
|
||||
: NULL),
|
||||
set($this->props->skip(array_keys(icon::getDefinedProps()))),
|
||||
$this->children()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,11 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace zin;
|
||||
|
||||
class label extends wg
|
||||
{
|
||||
static $defineProps = 'text?:string';
|
||||
|
||||
public function onAddChild($child)
|
||||
{
|
||||
if(is_string($child) && !$this->props->has('text'))
|
||||
{
|
||||
$this->props->set('text', $child);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return span
|
||||
|
||||
Reference in New Issue
Block a user