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