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
|
|
|
use Ajax\semantic\html\modules\HtmlDropdown; |
11
|
|
|
|
12
|
|
|
class HtmlInput extends HtmlSemDoubleElement { |
13
|
|
|
use IconTrait; |
14
|
|
|
|
15
|
|
|
public function __construct($identifier, $type="text", $value="", $placeholder="") { |
16
|
|
|
parent::__construct("div-" . $identifier, "div", "ui input"); |
17
|
|
|
$this->content=[ "field" => new \Ajax\common\html\html5\HtmlInput($identifier, $type, $value, $placeholder) ]; |
18
|
|
|
$this->_states=[ State::DISABLED,State::FOCUS,State::ERROR ]; |
19
|
|
|
$this->_variations=[ Variation::TRANSPARENT ]; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function setFocus() { |
23
|
|
|
$this->addToProperty("class", State::FOCUS); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function addLoading() { |
27
|
|
|
if ($this->_hasIcon === false) { |
28
|
|
|
throw new \Exception("Input must have an icon for showing a loader, use addIcon before"); |
29
|
|
|
} |
30
|
|
|
return $this->addToProperty("class", State::LOADING); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function labeled($label, $direction=Direction::LEFT, $icon=NULL) { |
34
|
|
|
$labelO=$this->addLabel($label,$direction===Direction::LEFT,$icon); |
35
|
|
|
$this->addToProperty("class", $direction . " labeled"); |
36
|
|
|
return $labelO; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function labeledToCorner($icon, $direction=Direction::LEFT) { |
40
|
|
|
return $this->labeled("", $direction . " corner", $icon)->toCorner($direction); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) { |
44
|
|
|
$actionO=$action; |
45
|
|
|
if (\is_object($action) === false) { |
46
|
|
|
$actionO=new HtmlButton("action-" . $this->identifier, $action); |
47
|
|
|
if (isset($icon)) |
48
|
|
|
$actionO->addIcon($icon, true, $labeled); |
49
|
|
|
} |
50
|
|
|
$this->addToProperty("class", $direction . " action"); |
51
|
|
|
$this->addContent($actionO, \strstr($direction, Direction::LEFT) !== false); |
52
|
|
|
return $actionO; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){ |
56
|
|
|
$labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items); |
57
|
|
|
$labelO->asSelect("select-".$this->identifier,false,true); |
58
|
|
|
return $this->labeled($labelO,$direction); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getField() { |
62
|
|
|
return $this->content["field"]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setPlaceholder($value) { |
66
|
|
|
$this->getField()->setPlaceholder($value); |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setTransparent() { |
71
|
|
|
return $this->addToProperty("class", "transparent"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public static function outline($identifier, $icon, $value="", $placeholder="") { |
75
|
|
|
$result=new HtmlInput($identifier, "text", $value, $placeholder); |
76
|
|
|
$result->addToProperty("class", "transparent"); |
77
|
|
|
$result->addIcon($icon)->setOutline(); |
78
|
|
|
return $result; |
79
|
|
|
} |
80
|
|
|
} |