props->has('text')) { $this->props->set('text', $child); return false; } } protected function getProps() { $url = $this->prop('disabled') ? null : $this->prop('url'); $target = $this->prop('target'); $props = array_merge($this->getRestProps(), array('title' => $this->prop('hint'))); if(empty($url)) { $props['tagName'] = 'button'; $props['type'] = $this->prop('btnType'); if(!isset($props['data-target'])) $props['data-target'] = $target; return $props; } $props['tagName'] = 'a'; if(!isset($props['href'])) $props['href'] = $url; if(!isset($props['target'])) $props['target'] = $target; return $props; } private function getChildren() { list($caret, $text, $icon, $iconClass, $trailingIcon, $trailingIconClass) = $this->prop(array('caret', 'text', 'icon', 'iconClass', 'trailingIcon', 'trailingIconClass')); $children = array(); if(!empty($icon)) $children[] = icon($icon, setClass($iconClass)); if(!empty($text)) $children[] = h::span($text, setClass('text')); $children[] = parent::build(); if(!empty($trailingIcon)) $children[] = icon($trailingIcon, setClass($trailingIconClass)); if(!empty($caret)) $children[] = h::span(setClass(is_string($caret) ? "caret-$caret" : 'caret')); return $children; } protected function getClassList() { list($url, $type, $caret, $text, $icon, $trailingIcon) = $this->prop(array('url', 'type', 'caret', 'text', 'icon', 'trailingIcon')); $onlyCaret = empty($text) && !empty($caret) && empty($icon) && empty($trailingIcon); $classList = array( 'btn' => true, 'disabled' => $this->prop('disabled'), 'active' => $this->prop('active'), 'btn-caret' => $onlyCaret, 'square' => $this->prop('square') ); if(empty($type) && !empty($url)) $type = 'btn-default'; else if($type === 'link') $type = 'btn-link'; else if($type === 'default') $type = 'btn-default'; if(!empty($type)) $classList[$type] = true; if(empty($text) && !empty($icon) && !isset($classList['square'])) $classList['square'] = true; $size = $this->prop('size'); if(!empty($size)) $classList["size-$size"] = true; return $classList; } protected function build() { $props = $this->getProps(); $children = $this->getChildren(); $classList = $this->getClassList(); return new h ( set($props), setClass($classList), $children ); } }