1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\base\constants\State; |
7
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
8
|
|
|
use Ajax\semantic\html\base\constants\Variation; |
9
|
|
|
use Ajax\semantic\html\base\traits\IconTrait; |
10
|
|
|
|
11
|
|
|
class HtmlInput extends HtmlSemDoubleElement{ |
12
|
|
|
use IconTrait; |
13
|
|
|
public function __construct($identifier,$type="text",$value="",$placeholder=""){ |
14
|
|
|
parent::__construct("div-".$identifier,"div","ui input"); |
15
|
|
|
$this->content=new \Ajax\common\html\html5\HtmlInput($identifier,$type,$value,$placeholder); |
16
|
|
|
$this->_states=[State::DISABLED,State::FOCUS,State::ERROR]; |
17
|
|
|
$this->_variations=[Variation::TRANSPARENT]; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function setFocus(){ |
21
|
|
|
$this->addToProperty("class", State::FOCUS); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function addLoading(){ |
25
|
|
|
if($this->_hasIcon===false){ |
26
|
|
|
throw new \Exception("Input must have an icon for showing a loader, use addIcon before"); |
27
|
|
|
} |
28
|
|
|
return $this->addToProperty("class", State::LOADING); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function addLabel($label,$direction=Direction::LEFT,$icon=NULL){ |
32
|
|
|
$labelO=$label; |
33
|
|
|
if(\is_object($label)===false){ |
34
|
|
|
$labelO=new HtmlLabel("label-".$this->identifier,$label); |
35
|
|
|
if(isset($icon)) |
36
|
|
|
$labelO->addIcon($icon); |
37
|
|
|
}else{ |
38
|
|
|
$labelO->addToPropertyCtrl("class", "label", array("label")); |
39
|
|
|
} |
40
|
|
|
$this->addToProperty("class", $direction." labeled"); |
41
|
|
|
$this->addContent($labelO,\strstr($direction,Direction::LEFT)!==false); |
42
|
|
|
return $labelO; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function addLabelToCorner($label,$direction=Direction::LEFT,$icon=NULL){ |
46
|
|
|
return $this->addLabel($label,$direction." corner",$icon)->toCorner($direction); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function addAction($action,$direction=Direction::LEFT,$icon=NULL,$labeled=false){ |
50
|
|
|
$actionO=$action; |
51
|
|
|
if(\is_object($action)===false){ |
52
|
|
|
$actionO=new HtmlButton("action-".$this->identifier,$action); |
53
|
|
|
if(isset($icon)) |
54
|
|
|
$actionO->addIcon($icon,true,$labeled); |
55
|
|
|
} |
56
|
|
|
$this->addToProperty("class", $direction." action"); |
57
|
|
|
$this->addContent($actionO,\strstr($direction,Direction::LEFT)!==false); |
58
|
|
|
return $actionO; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |