Skip to content

Commit c286d30

Browse files
committed
Button dropdown facilities
1 parent 7ebf5fc commit c286d30

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

Ajax/semantic/html/collections/form/traits/FieldsTrait.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Ajax\common\html\HtmlDoubleElement;
1414
use Ajax\semantic\html\collections\form\HtmlFormTextarea;
1515
use Ajax\semantic\html\base\HtmlSemDoubleElement;
16+
use Ajax\semantic\html\elements\HtmlButtonGroups;
1617

1718
/**
1819
* @author jc
@@ -65,17 +66,42 @@ public function addFieldRules($index,$rules){
6566
}
6667

6768
/**
69+
* Adds a new dropdown element
6870
* @param string $identifier
6971
* @param array $items
7072
* @param string $label
7173
* @param string $value
7274
* @param boolean $multiple
73-
* @return HtmlDoubleElement
75+
* @return HtmlFormDropdown
7476
*/
7577
public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){
7678
return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple));
7779
}
7880

81+
/**
82+
* Adds a new button groups
83+
* @param string $identifier
84+
* @param array $elements
85+
* @param boolean $asIcons
86+
* @return HtmlButtonGroups
87+
*/
88+
public function addButtonGroups($identifier,$elements=[],$asIcons=false){
89+
return $this->addItem(new HtmlButtonGroups($identifier,$elements,$asIcons));
90+
}
91+
92+
/**
93+
* Adds a button with a dropdown button
94+
* @param string $identifier
95+
* @param string $value
96+
* @param array $items
97+
* @param boolean $asCombo
98+
* @param string $icon
99+
* @return HtmlButtonGroups
100+
*/
101+
public function addDropdownButton($identifier,$value,$items=[],$asCombo=false,$icon=null){
102+
return $this->addItem(HtmlButton::dropdown($identifier, $value,$items,$asCombo,$icon));
103+
}
104+
79105
/**
80106
* @param string $identifier
81107
* @param string $label

Ajax/semantic/html/elements/HtmlButton.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,21 @@ public function asLink($href=NULL,$target=NULL) {
242242
parent::asLink($href,$target);
243243
return $this;
244244
}
245+
246+
/**
247+
* Returns a button with a dropdown button
248+
* @param string $identifier
249+
* @param string $value
250+
* @param array $items
251+
* @param boolean $asCombo
252+
* @param string $icon
253+
* @return HtmlButtonGroups
254+
*/
255+
public static function dropdown($identifier,$value,$items=[],$asCombo=false,$icon=null){
256+
$result=new HtmlButtonGroups($identifier,[$value]);
257+
$result->addDropdown($items,$asCombo);
258+
if(isset($icon))
259+
$result->setIcon($icon);
260+
return $result;
261+
}
245262
}

Ajax/semantic/html/elements/HtmlButtonGroups.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ protected function createItem($value){
2626
return new HtmlButton("", $value);
2727
}
2828

29+
/**
30+
* @param array $items
31+
* @param boolean $asCombo
32+
* @return HtmlDropdown
33+
*/
2934
public function addDropdown($items,$asCombo=false){
3035
$dd= new HtmlDropdown("dd-".$this->identifier,null,$items);
3136
$dd->asButton();

Ajax/semantic/html/modules/HtmlDropdown.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct($identifier, $value="", $items=array(),$associative=
4141
}
4242
$content=["text"=>$text];
4343
}
44-
$content["arrow"]=new HtmlIcon("", "dropdown");
44+
$content["arrow"]=new HtmlIcon($identifier."-icon", "dropdown");
4545
$this->content=$content;
4646
$this->tagName="div";
4747
$this->_associative=$associative;
@@ -358,6 +358,11 @@ public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $lab
358358
return $this->_addAction($this, $action,$direction,$icon,$labeled);
359359
}
360360

361+
public function setIcon($icon="dropdown"){
362+
$this->content["arrow"]=new HtmlIcon($this->identifier."-icon", $icon);
363+
return $this;
364+
}
365+
361366
public function jsAddItem($caption){
362367
$js="var first=$('#{$this->identifier} .item').first();if(first!=undefined){var new =first.clone();first.parent().append(new);first.html('{$caption}};')";
363368
return $js;

0 commit comments

Comments
 (0)